From: Hannu Niemistö Date: Mon, 5 Jun 2017 10:50:33 +0000 (+0300) Subject: (refs #7278, refs #7279) Small fixes to InternalCompilerExceptions X-Git-Tag: v1.31.0~332 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F601%2F2;p=simantics%2Fplatform.git (refs #7278, refs #7279) Small fixes to InternalCompilerExceptions Change-Id: I771fb27ecc98a7cd4f05aaf5e23a4763a6a0ca52 --- diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java index a6009426f..307a32ccc 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java @@ -3,6 +3,7 @@ package org.simantics.modeling.scl; import org.simantics.db.Resource; 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.elaboration.chr.plan.PlanContext; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; @@ -120,22 +121,22 @@ public class GraphPropertyRelation implements SCLRelation { @Override public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables, Expression[] expressions, Expression[] typeConstraintEvidenceParameters) { - Environment env = context.context.environment; + CompilationContext compilationContext = context.context; switch(boundMask) { case BF: context.iterateMaybe(location, w, variables[1], w.apply(location, - env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType), - typeConstraintEvidenceParameters[0].toVal(env, w), - expressions[0].toVal(env, w), + compilationContext.environment.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType), + typeConstraintEvidenceParameters[0].toVal(compilationContext, w), + expressions[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE))); break; case BB: - context.checkEqualsJust(location, w, expressions[1].toVal(env, w), + context.checkEqualsJust(location, w, expressions[1].toVal(compilationContext, w), w.apply(location, - env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType), - typeConstraintEvidenceParameters[0].toVal(env, w), - expressions[0].toVal(env, w), + compilationContext.environment.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType), + typeConstraintEvidenceParameters[0].toVal(compilationContext, w), + expressions[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE))); break; default: throw new IllegalArgumentException(); @@ -144,12 +145,12 @@ public class GraphPropertyRelation implements SCLRelation { @Override public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters, Expression[] typeConstraintEvidenceParameters) { - Environment env = context.context.environment; + CompilationContext compilationContext = context.context; w.apply(location, - env.getValue(CLAIM_RELATED_VALUE).getValue().createSpecialization(valueType), - typeConstraintEvidenceParameters[0].toVal(env, w), - parameters[0].toVal(env, w), + compilationContext.environment.getValue(CLAIM_RELATED_VALUE).getValue().createSpecialization(valueType), + typeConstraintEvidenceParameters[0].toVal(compilationContext, w), + parameters[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE), - parameters[1].toVal(env, w)); + parameters[1].toVal(compilationContext, w)); } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java index da08a2a38..331cef2cb 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java @@ -2,6 +2,7 @@ package org.simantics.modeling.scl; import org.simantics.db.Resource; import org.simantics.scl.compiler.common.names.Name; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.chr.plan.PlanContext; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; @@ -11,7 +12,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext; import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.types.TVar; @@ -139,13 +139,13 @@ public class GraphRelation implements SCLRelation { @Override public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables, Expression[] expressions, Expression[] typeConstraintEvidenceParameters) { - Environment env = context.context.environment; + CompilationContext compilationContext = context.context; switch(boundMask) { case BF: context.iterateList(location, w, variables[1], w.apply(location, - env.getValue(GET_OBJECTS).getValue(), - expressions[0].toVal(env, w), + compilationContext.environment.getValue(GET_OBJECTS).getValue(), + expressions[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE))); break; case FB: @@ -153,21 +153,21 @@ public class GraphRelation implements SCLRelation { throw new IllegalArgumentException(); context.iterateList(location, w, variables[0], w.apply(location, - env.getValue(GET_OBJECTS).getValue(), - expressions[1].toVal(env, w), + compilationContext.environment.getValue(GET_OBJECTS).getValue(), + expressions[1].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE))); break; case BB: context.check(location, w, inverseRelation == null || relationSelectivity <= inverseRelationSelectivity - ? w.apply(location, env.getValue(HAS_STATEMENT).getValue(), - expressions[0].toVal(env, w), + ? w.apply(location, compilationContext.environment.getValue(HAS_STATEMENT).getValue(), + expressions[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE), - expressions[1].toVal(env, w)) - : w.apply(location, env.getValue(HAS_STATEMENT).getValue(), - expressions[1].toVal(env, w), + expressions[1].toVal(compilationContext, w)) + : w.apply(location, compilationContext.environment.getValue(HAS_STATEMENT).getValue(), + expressions[1].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE), - expressions[0].toVal(env, w))); + expressions[0].toVal(compilationContext, w))); break; default: throw new IllegalArgumentException(); } @@ -176,11 +176,11 @@ public class GraphRelation implements SCLRelation { @Override public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters, Expression[] typeConstraintEvidenceParameters) { - Environment env = context.context.environment; + CompilationContext compilationContext = context.context; w.apply(location, - env.getValue(CLAIM).getValue(), - parameters[0].toVal(env, w), + compilationContext.environment.getValue(CLAIM).getValue(), + parameters[0].toVal(compilationContext, w), w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE), - parameters[1].toVal(env, w)); + parameters[1].toVal(compilationContext, w)); } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java index 5d258dd9e..68c584708 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/CodeGeneration.java @@ -160,7 +160,7 @@ public class CodeGeneration { continue; DecomposedExpression decomposed = - DecomposedExpression.decompose(expression); + DecomposedExpression.decompose(errorLog, expression); CodeWriter w = mw.createFunction((SCLConstant)value.getValue(), decomposed.typeParameters, @@ -172,7 +172,7 @@ public class CodeGeneration { IVal[] parameterVals = w.getParameters(); for(int i=0;i>i)&1)==1) - parameters.add(expressions[i].toVal(context.environment, w)); + parameters.add(expressions[i].toVal(context, w)); w.jump(bodyContinuation, w.apply(location, constraint.fetchFromIndex(context, boundMask), parameters.toArray(new IVal[parameters.size()]))); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/IterateListOp.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/IterateListOp.java index aa8737873..3c574b54d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/IterateListOp.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/IterateListOp.java @@ -24,7 +24,7 @@ public class IterateListOp extends PlanOp { @Override public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) { - IVal listValue = list.toVal(context.environment, w); + IVal listValue = list.toVal(context, w); planContext.iterateList(location, w, variable, listValue); } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/MatchOp.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/MatchOp.java index 97fa2e740..cde566949 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/MatchOp.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/MatchOp.java @@ -30,12 +30,12 @@ public class MatchOp extends PlanOp { CodeWriter end = w.createBlock(); IVal[] scrutineeVals = new IVal[1]; - scrutineeVals[0] = scrutinee.toVal(context.environment, w); + scrutineeVals[0] = scrutinee.toVal(context, w); ArrayList rows = new ArrayList(1); rows.add(new Row2(new Expression[] {pattern}, body.getContinuation())); - PatternMatchingCompiler2.split(w, context.environment, scrutineeVals, end.getContinuation(), rows); + PatternMatchingCompiler2.split(w, context, scrutineeVals, end.getContinuation(), rows); planContext.nextOp(body); if(body.isUnfinished()) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java index 398d86762..3d2031ee5 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/DecoratingExpression.java @@ -3,12 +3,12 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; import org.simantics.scl.compiler.elaboration.errors.NotPatternException; import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -113,7 +113,7 @@ public abstract class DecoratingExpression extends SimplifiableExpression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { throw new InternalCompilerError("Cannot generate code for " + getClass().getSimpleName() + "."); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java index 501c7f95d..c7bce4667 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EApply.java @@ -4,6 +4,7 @@ import java.util.ArrayList; 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.NoRepConstant; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; @@ -15,7 +16,6 @@ import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchin import org.simantics.scl.compiler.elaboration.java.ListConstructor; import org.simantics.scl.compiler.elaboration.macros.MacroRule; import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -101,11 +101,11 @@ public class EApply extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { - IVal functionVal = function.toVal(env, w); + public IVal toVal(CompilationContext context, CodeWriter w) { + IVal functionVal = function.toVal(context, w); IVal[] parameterVals = new IVal[parameters.length]; for(int i=0;i vars) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java index e8a5cb81b..7965b5011 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECHRRulesetConstructor.java @@ -1,11 +1,11 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -43,7 +43,7 @@ public class ECHRRulesetConstructor extends Expression { throw new InternalCompilerError("Type of ECHRRulesetConstructor should be already given."); } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { return ruleset.generateCode(w); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java index 502c4f369..6b99e6d37 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EConstant.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.simantics.scl.compiler.common.names.Name; import org.simantics.scl.compiler.common.precedence.Precedence; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; @@ -13,7 +14,6 @@ import org.simantics.scl.compiler.elaboration.errors.NotPatternException; import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType; import org.simantics.scl.compiler.elaboration.expressions.lhstype.PatternMatchingLhs; import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -114,7 +114,7 @@ public class EConstant extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { IVal val = value.getValue(); if(typeParameters.length > 0) { val = val.createSpecialization(typeParameters); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECoveringBranchPoint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECoveringBranchPoint.java index 7f1b7ac20..db675d414 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECoveringBranchPoint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ECoveringBranchPoint.java @@ -1,9 +1,9 @@ package org.simantics.scl.compiler.elaboration.expressions; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.java.VisitBranchPoint; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter; @@ -29,11 +29,11 @@ public class ECoveringBranchPoint extends DecoratingExpression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { ModuleWriter mw = w.getModuleWriter(); Constant constant = mw.getExternalConstant(branchPoint, Types.BRANCH_POINT); w.applyWithEffect(location, Types.PROC, Types.UNIT, VisitBranchPoint.INSTANCE, constant); - return expression.toVal(env, w); + return expression.toVal(context, w); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java index 8395391fa..b329beb19 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EError.java @@ -1,10 +1,10 @@ package org.simantics.scl.compiler.elaboration.expressions; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -46,7 +46,7 @@ public class EError extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { throw new UnsupportedOperationException(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java index d7038438b..4777b2dfb 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EExternalConstant.java @@ -3,6 +3,7 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; @@ -54,7 +55,7 @@ public class EExternalConstant extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { ModuleWriter mw = w.getModuleWriter(); return mw.getExternalConstant(value, getType()); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java index c05b15409..0d3e2eeaf 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EFieldAccess.java @@ -89,6 +89,7 @@ public class EFieldAccess extends SimplifiableExpression { }; } accessorExpression = new EAmbiguous(alternatives); + accessorExpression.location = location; } return new EApply(location, accessorExpression, parent).checkType(context, requiredType); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java index e3bb2fe0a..661de4261 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EIf.java @@ -1,10 +1,10 @@ package org.simantics.scl.compiler.elaboration.expressions; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -62,21 +62,21 @@ public class EIf extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { - IVal conditionVal = condition.toVal(env, w); + public IVal toVal(CompilationContext context, CodeWriter w) { + IVal conditionVal = condition.toVal(context, w); CodeWriter joinPoint = w.createBlock(getType()); CodeWriter thenBlock = w.createBlock(); if(else_ != null) { CodeWriter elseBlock = w.createBlock(); w.if_(conditionVal, thenBlock.getContinuation(), elseBlock.getContinuation()); - IVal elseVal = else_.toVal(env, elseBlock); + IVal elseVal = else_.toVal(context, elseBlock); elseBlock.jump(joinPoint.getContinuation(), elseVal); } else { w.if_(conditionVal, thenBlock.getContinuation(), joinPoint.getContinuation()); } - IVal thenVal = then_.toVal(env, thenBlock); + IVal thenVal = then_.toVal(context, thenBlock); thenBlock.jump(joinPoint.getContinuation(), thenVal); w.continueAs(joinPoint); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java index 08e47bf95..23733bac6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELambdaType.java @@ -1,11 +1,11 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.IVal; import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; @@ -47,8 +47,8 @@ public class ELambdaType extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { - return lambdaToVal(env, w); + public IVal toVal(CompilationContext context, CodeWriter w) { + return lambdaToVal(context, w); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java index d10066f90..2b9e8e2c0 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ELet.java @@ -3,11 +3,11 @@ package org.simantics.scl.compiler.elaboration.expressions; import java.util.ArrayList; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext; import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; import org.simantics.scl.compiler.elaboration.contexts.TypingContext; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.codegen.references.BoundVar; import org.simantics.scl.compiler.internal.codegen.references.IVal; @@ -147,7 +147,7 @@ public class ELet extends Expression { } @Override - public IVal toVal(Environment env, CodeWriter w) { + public IVal toVal(CompilationContext context, CodeWriter w) { // Create bound variables BoundVar[] vars = new BoundVar[assignments.length]; for(int i=0;i rows = new ArrayList(cases.length); for(Case case_ : cases) rows.add(new Row(case_.patterns, case_.value)); IVal[] scrutineeVals = new IVal[scrutinee.length]; for(int i=0;i typeParameterList = new ArrayList(); ArrayList parameterList = new ArrayList(); Type effect = Types.NO_EFFECTS; @@ -42,9 +43,9 @@ public class DecomposedExpression { if(expression instanceof ESimpleLambda) { ESimpleLambda lambda = (ESimpleLambda)expression; parameterList.add(lambda.parameter); - expression = lambda.value; if(Types.canonical(effect) != Types.NO_EFFECTS) - throw new InternalCompilerError(); + errorLog.logWarning(expression.location, "Encountered nested lambdas where outermost lambda contains effects. The reason is probably in the subsumption solver and code should be OK."); + expression = lambda.value; effect = Types.simplifyFinalEffect(lambda.getLocalEffect()); } else if(expression instanceof ELambdaType) { diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching/PatternMatchingCompiler.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching/PatternMatchingCompiler.java index 9bf056bef..12bf42e5b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching/PatternMatchingCompiler.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching/PatternMatchingCompiler.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EApplyType; @@ -18,7 +19,6 @@ import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.expressions.GuardedExpressionGroup; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.elaboration.modules.TypeConstructor; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.internal.codegen.continuations.Branch; import org.simantics.scl.compiler.internal.codegen.continuations.ICont; import org.simantics.scl.compiler.internal.codegen.references.IVal; @@ -54,7 +54,7 @@ public class PatternMatchingCompiler { return newVals; } - private static void splitByConstructors(CodeWriter w, final Environment env, IVal[] scrutinee, final ICont success, ICont failure, List rows, int columnId) { + private static void splitByConstructors(CodeWriter w, final CompilationContext context, IVal[] scrutinee, final ICont success, ICont failure, List rows, int columnId) { THashMap matrixMap = new THashMap(); ArrayList branches = new ArrayList(); ArrayList matrices = new ArrayList(); @@ -167,7 +167,7 @@ public class PatternMatchingCompiler { CodeWriter newW = w.createBlock(); ICont cont = newW.getContinuation(); branches.add(new Branch(null, cont)); - split(newW, env, scrutinee, success, failure, rows.subList(i, rows.size())); + split(newW, context, scrutinee, success, failure, rows.subList(i, rows.size())); failure = cont; } else { @@ -177,7 +177,7 @@ public class PatternMatchingCompiler { } catch (MatchException e) { throw new InternalCompilerError(); } - TypeConstructor cons = (TypeConstructor)env.getTypeDescriptor(con); + TypeConstructor cons = (TypeConstructor)context.environment.getTypeDescriptor(con); int maxBranchCount = cons.isOpen ? Integer.MAX_VALUE : cons.constructors.length; if(branches.size() < maxBranchCount) @@ -185,11 +185,11 @@ public class PatternMatchingCompiler { } for(ExpressionMatrix mx : matrices) - split(mx.w, env, mx.scrutinee, success, failure, mx.rows); + split(mx.w, context, mx.scrutinee, success, failure, mx.rows); w.switch_(scrutinee[columnId], branches.toArray(new Branch[branches.size()])); } - private static void splitByViewPattern(CodeWriter w, Environment env, IVal[] scrutinee, ICont success, + private static void splitByViewPattern(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont success, ICont failure, List rows, int viewPatternColumn) { Row firstRow = rows.get(0); EViewPattern firstViewPattern = (EViewPattern)firstRow.patterns[viewPatternColumn]; @@ -221,19 +221,19 @@ public class PatternMatchingCompiler { IVal[] newScrutinee = Arrays.copyOf(scrutinee, scrutinee.length); newScrutinee[viewPatternColumn] = w.apply(firstViewPattern.location, - firstViewPattern.expression.toVal(env, w), + firstViewPattern.expression.toVal(context, w), scrutinee[viewPatternColumn]); if(i == rows.size()) { - split(w, env, newScrutinee, success, failure, rows); + split(w, context, newScrutinee, success, failure, rows); } else { CodeWriter cont = w.createBlock(); - split(w, env, newScrutinee, success, cont.getContinuation(), rows.subList(0, i)); - split(cont, env, scrutinee, success, failure, rows.subList(i, rows.size())); + split(w, context, newScrutinee, success, cont.getContinuation(), rows.subList(0, i)); + split(cont, context, scrutinee, success, failure, rows.subList(i, rows.size())); } } - public static void split(CodeWriter w, Environment env, IVal[] scrutinee, ICont success, ICont failure, List rows) { + public static void split(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont success, ICont failure, List rows) { Row firstRow = rows.get(0); Expression[] patterns = firstRow.patterns; if(scrutinee.length != patterns.length) @@ -248,13 +248,13 @@ public class PatternMatchingCompiler { viewPatternColumn = i; } else if(!(pattern instanceof EVariable)) { - splitByConstructors(w, env, scrutinee, success, failure, rows, i); + splitByConstructors(w, context, scrutinee, success, failure, rows, i); return; } } if(viewPatternColumn >= 0) { - splitByViewPattern(w, env, scrutinee, success, failure, rows, viewPatternColumn); + splitByViewPattern(w, context, scrutinee, success, failure, rows, viewPatternColumn); return; } @@ -264,16 +264,16 @@ public class PatternMatchingCompiler { if(firstRow.value instanceof GuardedExpressionGroup) { GuardedExpressionGroup group = (GuardedExpressionGroup)firstRow.value; if(rows.size() == 1) { - group.compile(env, w, success, failure); + group.compile(context, w, success, failure); } else { CodeWriter newW = w.createBlock(); ICont cont = newW.getContinuation(); - group.compile(env, w, success, cont); - split(newW, env, scrutinee, success, failure, rows.subList(1, rows.size())); + group.compile(context, w, success, cont); + split(newW, context, scrutinee, success, failure, rows.subList(1, rows.size())); } } else - w.jump(success, firstRow.value.toVal(env, w)); + w.jump(success, firstRow.value.toVal(context, w)); } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java index bd904cf28..8ca51b275 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/matching2/PatternMatchingCompiler2.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.List; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EApplyType; @@ -17,7 +18,6 @@ import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; import org.simantics.scl.compiler.elaboration.expressions.Expression; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.elaboration.modules.TypeConstructor; -import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.internal.codegen.continuations.Branch; import org.simantics.scl.compiler.internal.codegen.continuations.ICont; import org.simantics.scl.compiler.internal.codegen.references.IVal; @@ -53,7 +53,7 @@ public class PatternMatchingCompiler2 { return newVals; } - private static void splitByConstructors(CodeWriter w, final Environment env, IVal[] scrutinee, ICont failure, List rows, int columnId) { + private static void splitByConstructors(CodeWriter w, final CompilationContext context, IVal[] scrutinee, ICont failure, List rows, int columnId) { THashMap matrixMap = new THashMap(); ArrayList branches = new ArrayList(); ArrayList matrices = new ArrayList(); @@ -166,7 +166,7 @@ public class PatternMatchingCompiler2 { CodeWriter newW = w.createBlock(); ICont cont = newW.getContinuation(); branches.add(new Branch(null, cont)); - split(newW, env, scrutinee, failure, rows.subList(i, rows.size())); + split(newW, context, scrutinee, failure, rows.subList(i, rows.size())); failure = cont; } else { @@ -176,7 +176,7 @@ public class PatternMatchingCompiler2 { } catch (MatchException e) { throw new InternalCompilerError(e); } - TypeConstructor cons = (TypeConstructor)env.getTypeDescriptor(con); + TypeConstructor cons = (TypeConstructor)context.environment.getTypeDescriptor(con); int maxBranchCount = cons.isOpen ? Integer.MAX_VALUE : cons.constructors.length; if(branches.size() < maxBranchCount) @@ -184,11 +184,11 @@ public class PatternMatchingCompiler2 { } for(ExpressionMatrix mx : matrices) - split(mx.w, env, mx.scrutinee, failure, mx.rows); + split(mx.w, context, mx.scrutinee, failure, mx.rows); w.switch_(scrutinee[columnId], branches.toArray(new Branch[branches.size()])); } - private static void splitByViewPattern(CodeWriter w, Environment env, IVal[] scrutinee, ICont failure, List rows, int viewPatternColumn) { + private static void splitByViewPattern(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List rows, int viewPatternColumn) { Row2 firstRow = rows.get(0); EViewPattern firstViewPattern = (EViewPattern)firstRow.patterns[viewPatternColumn]; firstRow.patterns[viewPatternColumn] = firstViewPattern.pattern; @@ -219,19 +219,19 @@ public class PatternMatchingCompiler2 { IVal[] newScrutinee = Arrays.copyOf(scrutinee, scrutinee.length); newScrutinee[viewPatternColumn] = w.apply(firstViewPattern.location, - firstViewPattern.expression.toVal(env, w), + firstViewPattern.expression.toVal(context, w), scrutinee[viewPatternColumn]); if(i == rows.size()) { - split(w, env, newScrutinee, failure, rows); + split(w, context, newScrutinee, failure, rows); } else { CodeWriter cont = w.createBlock(); - split(w, env, newScrutinee, cont.getContinuation(), rows.subList(0, i)); - split(cont, env, scrutinee, failure, rows.subList(i, rows.size())); + split(w, context, newScrutinee, cont.getContinuation(), rows.subList(0, i)); + split(cont, context, scrutinee, failure, rows.subList(i, rows.size())); } } - public static void split(CodeWriter w, Environment env, IVal[] scrutinee, ICont failure, List rows) { + public static void split(CodeWriter w, CompilationContext context, IVal[] scrutinee, ICont failure, List rows) { Row2 firstRow = rows.get(0); Expression[] patterns = firstRow.patterns; if(scrutinee.length != patterns.length) @@ -246,13 +246,13 @@ public class PatternMatchingCompiler2 { viewPatternColumn = i; } else if(!(pattern instanceof EVariable)) { - splitByConstructors(w, env, scrutinee, failure, rows, i); + splitByConstructors(w, context, scrutinee, failure, rows, i); return; } } if(viewPatternColumn >= 0) { - splitByViewPattern(w, env, scrutinee, failure, rows, viewPatternColumn); + splitByViewPattern(w, context, scrutinee, failure, rows, viewPatternColumn); return; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java index a5b9a6541..a17244283 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/top/ExpressionEvaluator.java @@ -367,7 +367,7 @@ public class ExpressionEvaluator { // Convert to SSA ModuleWriter mw = new ModuleWriter(namingPolicy.getModuleClassName()); DecomposedExpression decomposed = - DecomposedExpression.decompose(expression); + DecomposedExpression.decompose(errorLog, expression); SCLConstant constant = new SCLConstant( Name.create(moduleName, COMPUTATION_METHOD_NAME), @@ -388,7 +388,7 @@ public class ExpressionEvaluator { IVal[] parameterVals = w.getParameters(); for(int i=0;i print (randomN 10)) + 0 +-- +0 \ No newline at end of file