]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/BTypes.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/BTypes.java
new file mode 100644 (file)
index 0000000..fed6686
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.scl.compiler.internal.codegen.types;\r
+\r
+import org.simantics.scl.compiler.types.TCon;\r
+import org.simantics.scl.compiler.types.TFun;\r
+import org.simantics.scl.compiler.types.Type;\r
+import org.simantics.scl.compiler.types.Types;\r
+import org.simantics.scl.compiler.types.exceptions.MatchException;\r
+\r
+/**\r
+ * Type utilites for SCL compiler backend\r
+ */\r
+public class BTypes {\r
+    \r
+    public static final TCon PROC = Types.con(Types.BUILTIN, "Proc");\r
\r
+    public static Type[] matchFunction(Type type, int arity) throws MatchException {\r
+        type = Types.canonical(type);\r
+        /*while(type instanceof TForAll)\r
+            type = ((TForAll)type).type;*/\r
+        Type[] result = new Type[arity+1];\r
+        for(int i=0;i<arity;++i) {\r
+            if(type instanceof TFun) {\r
+                TFun fun = (TFun)type;\r
+                result[i] = fun.domain;\r
+                type = Types.canonical(fun.range);\r
+            }\r
+            /*else if(type instanceof TApply) {\r
+                TApply apply1 = (TApply)type;\r
+                Type function1 = Types.canonical(apply1.function);\r
+                if(function1 instanceof TApply) {\r
+                    TApply apply2 = (TApply)function1;\r
+                    Type function2 = Types.canonical(apply2.function);\r
+                    if(function2 == Types.ARROW) {\r
+                        result[i] = apply2.parameter;\r
+                        type = Types.canonical(apply1.parameter);\r
+                    }\r
+                    else\r
+                        throw new MatchException();\r
+                }\r
+                else\r
+                    throw new MatchException();\r
+            }*/\r
+            else\r
+                throw new MatchException();\r
+        }\r
+        result[arity] = type;\r
+        return result;\r
+    }\r
+\r
+}\r