]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/BTypes.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / types / BTypes.java
1 package org.simantics.scl.compiler.internal.codegen.types;\r
2 \r
3 import org.simantics.scl.compiler.types.TCon;\r
4 import org.simantics.scl.compiler.types.TFun;\r
5 import org.simantics.scl.compiler.types.Type;\r
6 import org.simantics.scl.compiler.types.Types;\r
7 import org.simantics.scl.compiler.types.exceptions.MatchException;\r
8 \r
9 /**\r
10  * Type utilites for SCL compiler backend\r
11  */\r
12 public class BTypes {\r
13     \r
14     public static final TCon PROC = Types.con(Types.BUILTIN, "Proc");\r
15  \r
16     public static Type[] matchFunction(Type type, int arity) throws MatchException {\r
17         type = Types.canonical(type);\r
18         /*while(type instanceof TForAll)\r
19             type = ((TForAll)type).type;*/\r
20         Type[] result = new Type[arity+1];\r
21         for(int i=0;i<arity;++i) {\r
22             if(type instanceof TFun) {\r
23                 TFun fun = (TFun)type;\r
24                 result[i] = fun.domain;\r
25                 type = Types.canonical(fun.range);\r
26             }\r
27             /*else if(type instanceof TApply) {\r
28                 TApply apply1 = (TApply)type;\r
29                 Type function1 = Types.canonical(apply1.function);\r
30                 if(function1 instanceof TApply) {\r
31                     TApply apply2 = (TApply)function1;\r
32                     Type function2 = Types.canonical(apply2.function);\r
33                     if(function2 == Types.ARROW) {\r
34                         result[i] = apply2.parameter;\r
35                         type = Types.canonical(apply1.parameter);\r
36                     }\r
37                     else\r
38                         throw new MatchException();\r
39                 }\r
40                 else\r
41                     throw new MatchException();\r
42             }*/\r
43             else\r
44                 throw new MatchException();\r
45         }\r
46         result[arity] = type;\r
47         return result;\r
48     }\r
49 \r
50 }\r