]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/BTypes.java
Fixed all line endings of the repository
[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;
2
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;
8
9 /**
10  * Type utilites for SCL compiler backend
11  */
12 public class BTypes {
13     
14     public static final TCon PROC = Types.con(Types.BUILTIN, "Proc");
15  
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);
26             }
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);
36                     }
37                     else
38                         throw new MatchException();
39                 }
40                 else
41                     throw new MatchException();
42             }*/
43             else
44                 throw new MatchException();
45         }
46         result[arity] = type;
47         return result;
48     }
49
50 }