]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/SimplificationContext.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / contexts / SimplificationContext.java
index e983e1277e0a93f27ab0964e3083ecf588583531..bd01859c91042486877c626bd657fb7fdf790d9c 100755 (executable)
@@ -1,10 +1,9 @@
 package org.simantics.scl.compiler.elaboration.contexts;
 
-import gnu.trove.list.array.TLongArrayList;
-import gnu.trove.map.hash.THashMap;
-
 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.Constant;
 import org.simantics.scl.compiler.elaboration.expressions.Case;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
@@ -30,20 +29,14 @@ import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.compiler.types.exceptions.MatchException;
 import org.simantics.scl.compiler.types.util.MultiFunction;
 
+import gnu.trove.list.array.TLongArrayList;
+import gnu.trove.map.hash.THashMap;
+
 public class SimplificationContext implements EnvironmentalContext {
+    CompilationContext compilationContext;
     Environment environment;
     ErrorLog errorLog;
     
-    public static final Name MAP_LIST = Name.create("Prelude", "mapList");
-    public static final Name GUARD_LIST = Name.create("Prelude", "guardList");
-    public static final Name CONCAT_MAP = Name.create("Prelude", "concatMap");
-    public static final Name EMPTY_LIST = Name.create("Prelude", "emptyList");
-    public static final Name SINGLETON_LIST = Name.create("Prelude", "singletonList");    
-    public static final Name APPEND_LIST = Name.create("Prelude", "appendList");
-    public static final Name ADD_LIST = Name.create("Prelude", "addList");
-    public static final Name FROM_INTEGER = Name.create("Prelude", "fromInteger");
-    public static final Name FROM_DOUBLE = Name.create("Prelude", "fromDouble");
-    
     THashMap<Name, SCLValue> constants = new THashMap<Name, SCLValue>();
     THashMap<Variable, Expression> inlinedVariables = new THashMap<Variable, Expression>();
     
@@ -52,11 +45,11 @@ public class SimplificationContext implements EnvironmentalContext {
     JavaTypeTranslator javaTypeTranslator;
     JavaReferenceValidator<?, ?, ?, ?> validator;
     
-    public SimplificationContext(Environment environment, ErrorLog errorLog, 
-            JavaTypeTranslator javaTypeTranslator, JavaReferenceValidator<?, ?, ?, ?> validator) {
-        this.environment = environment;
-        this.errorLog = errorLog;
-        this.javaTypeTranslator = javaTypeTranslator;
+    public SimplificationContext(CompilationContext compilationContext, JavaReferenceValidator<?, ?, ?, ?> validator) {
+        this.compilationContext = compilationContext;
+        this.environment = compilationContext.environment;
+        this.errorLog = compilationContext.errorLog;
+        this.javaTypeTranslator = compilationContext.javaTypeTranslator;
         this.validator = validator;         
     }
     
@@ -167,20 +160,20 @@ public class SimplificationContext implements EnvironmentalContext {
     public Expression mapList(Expression f, Expression l) {
         try {
             MultiFunction mfun = Types.matchFunction(f.getType(), 1);
-            return apply(getConstant(MAP_LIST, new Type[] {mfun.parameterTypes[0], mfun.returnType}), f, l);
+            return apply(getConstant(Names.Prelude_mapList, new Type[] {mfun.parameterTypes[0], mfun.returnType}), f, l);
         } catch (MatchException e) {
             throw new InternalCompilerError(e);
         }
     }
     
     public Expression guardList(Expression cond) {
-        return apply(getConstant(GUARD_LIST), cond);
+        return apply(getConstant(Names.Prelude_guardList), cond);
     }
 
     public Expression concatMap(Expression f, Expression l) {
         try {
             MultiFunction mfun = Types.matchFunction(f.getType(), 1);
-            return apply(getConstant(CONCAT_MAP, new Type[] {
+            return apply(getConstant(Names.Prelude_concatMap, new Type[] {
                     mfun.parameterTypes[0], mfun.effect,
                     Types.matchApply(Types.LIST, mfun.returnType)}
             ), f, l);
@@ -190,11 +183,11 @@ public class SimplificationContext implements EnvironmentalContext {
     }
     
     public Expression emptyList(Type type) {
-        return getConstant(EMPTY_LIST, type);
+        return getConstant(Names.Prelude_emptyList, type);
     }
     
     public Expression singletonList(Expression e) {
-        return apply(getConstant(SINGLETON_LIST, e.getType()), e);
+        return apply(getConstant(Names.Prelude_singletonList, e.getType()), e);
     }
 
     public Expression match(Expression scrutinee, Expression pattern, Expression value) {
@@ -244,7 +237,7 @@ public class SimplificationContext implements EnvironmentalContext {
         return new EApply(
                 Locations.NO_LOCATION,
                 Types.PROC,
-                getConstant(Name.create("Prelude", "iterList"), variable.getType(), Types.PROC, Types.tupleConstructor(0)),
+                getConstant(Names.Prelude_iterList, variable.getType(), Types.PROC, Types.tupleConstructor(0)),
                 new Expression[] {
                     new ESimpleLambda(Types.PROC, variable, continuation), 
                     list
@@ -257,7 +250,7 @@ public class SimplificationContext implements EnvironmentalContext {
         return new EApply(
                 Locations.NO_LOCATION,
                 Types.PROC,
-                getConstant(Name.create("Vector", "iterVector"), variable.getType(), Types.PROC, Types.tupleConstructor(0)),
+                getConstant(Names.Vector_iterVector, variable.getType(), Types.PROC, Types.tupleConstructor(0)),
                 new Expression[] {
                     new ESimpleLambda(Types.PROC, variable, continuation), 
                     vector
@@ -271,4 +264,8 @@ public class SimplificationContext implements EnvironmentalContext {
             result[i] = new EVariable(parameters[i]);
         return result;
     }
+
+    public CompilationContext getCompilationContext() {
+        return compilationContext;
+    }
 }
\ No newline at end of file