1 package org.simantics.scl.compiler.internal.codegen.types;
\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
10 * Type utilites for SCL compiler backend
\r
12 public class BTypes {
\r
14 public static final TCon PROC = Types.con(Types.BUILTIN, "Proc");
\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
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
38 throw new MatchException();
\r
41 throw new MatchException();
\r
44 throw new MatchException();
\r
46 result[arity] = type;
\r