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;
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;
}
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();
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
}
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
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
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),
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),
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
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
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),
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),
}
}
- 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
}
public Expression getConstant(Name name, Type[] typeParameters) {
- return context.getConstant(name, typeParameters);
+ return context.getCompilationContext().getConstant(name, typeParameters);
}
public QueryCompilationContext createCheckContext() {
return evidence;
}
- @Override
- public SCLValue getValue(Name name) {
- return context.getValue(name);
+ public CompilationContext getCompilationContext() {
+ return context.getCompilationContext();
}
}