1 package org.simantics.scl.compiler.internal.codegen.types;
3 import org.simantics.scl.compiler.types.TCon;
4 import org.simantics.scl.compiler.types.TFun;
5 import org.simantics.scl.compiler.types.Type;
6 import org.simantics.scl.compiler.types.Types;
7 import org.simantics.scl.compiler.types.exceptions.MatchException;
10 * Type utilites for SCL compiler backend
14 public static final TCon PROC = Types.con(Types.BUILTIN, "Proc");
16 public static Type[] matchFunction(Type type, int arity) throws MatchException {
17 type = Types.canonical(type);
18 /*while(type instanceof TForAll)
19 type = ((TForAll)type).type;*/
20 Type[] result = new Type[arity+1];
21 for(int i=0;i<arity;++i) {
22 if(type instanceof TFun) {
23 TFun fun = (TFun)type;
24 result[i] = fun.domain;
25 type = Types.canonical(fun.range);
27 /*else if(type instanceof TApply) {
28 TApply apply1 = (TApply)type;
29 Type function1 = Types.canonical(apply1.function);
30 if(function1 instanceof TApply) {
31 TApply apply2 = (TApply)function1;
32 Type function2 = Types.canonical(apply2.function);
33 if(function2 == Types.ARROW) {
34 result[i] = apply2.parameter;
35 type = Types.canonical(apply1.parameter);
38 throw new MatchException();
41 throw new MatchException();
44 throw new MatchException();