X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fcontexts%2FSimplificationContext.java;h=bd01859c91042486877c626bd657fb7fdf790d9c;hp=90e93f3d00a014b6de9d1dc13e5f0bffe05f4ecd;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=9a175feb652b2b7bba7afa540831b9076be3c10e diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/SimplificationContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/SimplificationContext.java index 90e93f3d0..bd01859c9 100755 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/SimplificationContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/SimplificationContext.java @@ -2,6 +2,8 @@ package org.simantics.scl.compiler.elaboration.contexts; 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; @@ -31,19 +33,10 @@ 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 constants = new THashMap(); THashMap inlinedVariables = new THashMap(); @@ -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