]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/query/compilation/QueryCompilationContext.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / query / compilation / QueryCompilationContext.java
index f0f5b12271678932bf10908aee2ea1ca94870927..d454c63eb256dfbb92470e0ec7c2e03d5b27712c 100644 (file)
@@ -8,8 +8,9 @@ import static org.simantics.scl.compiler.elaboration.expressions.Expressions.var
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.common.names.Names;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.BooleanConstant;
-import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext;
 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
 import org.simantics.scl.compiler.elaboration.expressions.Case;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
@@ -23,16 +24,13 @@ import org.simantics.scl.compiler.elaboration.expressions.EVariable;
 import org.simantics.scl.compiler.elaboration.expressions.Expression;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.elaboration.java.Builtins;
-import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.types.TPred;
 import org.simantics.scl.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 
-public class QueryCompilationContext implements EnvironmentalContext {
-    private static final Name EQUALS = Name.create("Prelude", "==");
-    
+public class QueryCompilationContext {    
     TypingContext context;
     QueryCompilationMode mode;
     Type resultType;
@@ -72,7 +70,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
         }
         case GET_ALL: {
             try {
-                return new EApply(context.getConstant(Name.create("Prelude", "appendList")
+                return new EApply(context.getCompilationContext().getConstant(Names.Prelude_appendList
                         Types.matchApply(Types.LIST, a.getType())), a, b);
             } catch (MatchException e) {
                 throw new InternalCompilerError();
@@ -96,9 +94,8 @@ public class QueryCompilationContext implements EnvironmentalContext {
         condition(new EApply(
                 location,
                 Types.PROC,
-                context.getConstant(EQUALS, type),
+                context.getCompilationContext().getConstant(Names.Builtin_equals, type),
                 new Expression[] {
-                    getEvidence(location, Types.pred(Types.EQ, type)),
                     a,
                     b
                 }
@@ -132,7 +129,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Prelude", "iterList"), variable.getType(), Types.PROC, Types.tupleConstructor(0)),
+                        context.getCompilationContext().getConstant(Names.Prelude_iterList, variable.getType(), Types.PROC, Types.tupleConstructor(0)),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
                             list
@@ -143,7 +140,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Prelude", "any"), variable.getType(), Types.PROC),
+                        context.getCompilationContext().getConstant(Names.Prelude_any, variable.getType(), Types.PROC),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
                             list
@@ -154,7 +151,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Prelude", "concatMap"), variable.getType(), Types.PROC, 
+                        context.getCompilationContext().getConstant(Names.Prelude_concatMap, variable.getType(), Types.PROC, 
                                 Types.matchApply(Types.LIST, continuation.getType())),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
@@ -166,7 +163,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Prelude", "mapFirst"), variable.getType(), Types.PROC,
+                        context.getCompilationContext().getConstant(Names.Prelude_mapFirst, variable.getType(), Types.PROC,
                                 Types.matchApply(Types.MAYBE, continuation.getType())),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
@@ -188,7 +185,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Vector", "iterVector"), variable.getType(), Types.PROC, continuation.getType()),
+                        context.getCompilationContext().getConstant(Names.Vector_iterVector, variable.getType(), Types.PROC, continuation.getType()),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
                             vector
@@ -199,7 +196,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Vector", "anyVector"), variable.getType(), Types.PROC),
+                        context.getCompilationContext().getConstant(Names.Vector_anyVector, variable.getType(), Types.PROC),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
                             vector
@@ -210,7 +207,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Vector", "concatMapVector"), variable.getType(), Types.PROC,
+                        context.getCompilationContext().getConstant(Names.Vector_concatMapVector, variable.getType(), Types.PROC,
                                 Types.matchApply(Types.LIST, continuation.getType())),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
@@ -222,7 +219,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
                 continuation = new EApply(
                         Locations.NO_LOCATION,
                         Types.PROC,
-                        context.getConstant(Name.create("Vector", "mapFirstVector"), variable.getType(), Types.PROC, 
+                        context.getCompilationContext().getConstant(Names.Vector_mapFirstVector, variable.getType(), Types.PROC, 
                                 Types.matchApply(Types.MAYBE, continuation.getType())),
                         new Expression[] {
                             new ESimpleLambda(Types.PROC, variable, continuation), 
@@ -237,20 +234,17 @@ public class QueryCompilationContext implements EnvironmentalContext {
         }
     }
     
-    private static final Name MSet_iter = Name.create("MSet", "iter");
-    private static final Name MSet_mapFirst = Name.create("MSet", "mapFirst");
-    
     public void iterateMSet(Variable variable, Expression set) {
         try {
             switch(mode) {
             case ITERATE:
-                continuation = apply(context, Types.PROC, MSet_iter, variable.getType(), Types.PROC, continuation.getType(),
+                continuation = apply(context.getCompilationContext(), Types.PROC, Names.MSet_iter, variable.getType(), Types.PROC, continuation.getType(),
                         lambda(Types.PROC, variable, continuation), 
                         set
                         );
                 break;
             case GET_FIRST:
-                continuation = apply(context, Types.PROC, MSet_mapFirst, variable.getType(), Types.PROC, 
+                continuation = apply(context.getCompilationContext(), Types.PROC, Names.MSet_mapFirst, variable.getType(), Types.PROC, 
                         Types.matchApply(Types.MAYBE, continuation.getType()),
                         lambda(Types.PROC, variable, continuation), 
                         set
@@ -270,7 +264,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
     }
     
     public Expression getConstant(Name name, Type[] typeParameters) {
-        return context.getConstant(name, typeParameters);
+        return context.getCompilationContext().getConstant(name, typeParameters);
     }
     
     public QueryCompilationContext createCheckContext() {
@@ -316,8 +310,7 @@ public class QueryCompilationContext implements EnvironmentalContext {
         return evidence;
     }
 
-    @Override
-    public SCLValue getValue(Name name) {
-        return context.getValue(name);
+    public CompilationContext getCompilationContext() {
+        return context.getCompilationContext();
     }
 }