X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Felaboration%2Fmatching2%2FPatternMatchingCompiler2.java;h=41882f57a5d86448a98ec049cd2783d6cf4ed58b;hb=91682baa9a8252390f09b80fd724f47e5957b234;hp=bd904cf28ef52bbc5e7ddc058a1a9fe28978a672;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git 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..41882f57a 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; @@ -15,9 +16,9 @@ import org.simantics.scl.compiler.elaboration.expressions.ELiteral; import org.simantics.scl.compiler.elaboration.expressions.EVariable; import org.simantics.scl.compiler.elaboration.expressions.EViewPattern; import org.simantics.scl.compiler.elaboration.expressions.Expression; +import org.simantics.scl.compiler.elaboration.java.DynamicConstructor; 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 +54,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(long location, 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(); @@ -93,7 +94,7 @@ public class PatternMatchingCompiler2 { if(constructor_ instanceof EConstant) { SCLValue constructor = ((EConstant)constructor_).getValue(); - ExpressionMatrix matrix = matrixMap.get(constructor.getName()); + ExpressionMatrix matrix = constructor.getValue() == DynamicConstructor.INSTANCE ? null : matrixMap.get(constructor.getName()); if(matrix == null) { CodeWriter newW = w.createBlock(Types.getTypes(parameters)); branches.add(new Branch((Constant)constructor.getValue(), newW.getContinuation())); @@ -166,7 +167,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(location, newW, context, scrutinee, failure, rows.subList(i, rows.size())); failure = cont; } else { @@ -176,7 +177,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 +185,11 @@ public class PatternMatchingCompiler2 { } for(ExpressionMatrix mx : matrices) - split(mx.w, env, mx.scrutinee, failure, mx.rows); - w.switch_(scrutinee[columnId], branches.toArray(new Branch[branches.size()])); + split(location, mx.w, context, mx.scrutinee, failure, mx.rows); + w.switch_(location, 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(long location, 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 +220,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(location, 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(location, w, context, newScrutinee, cont.getContinuation(), rows.subList(0, i)); + split(location, 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(long location, 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,19 +247,19 @@ public class PatternMatchingCompiler2 { viewPatternColumn = i; } else if(!(pattern instanceof EVariable)) { - splitByConstructors(w, env, scrutinee, failure, rows, i); + splitByConstructors(location, w, context, scrutinee, failure, rows, i); return; } } if(viewPatternColumn >= 0) { - splitByViewPattern(w, env, scrutinee, failure, rows, viewPatternColumn); + splitByViewPattern(location, w, context, scrutinee, failure, rows, viewPatternColumn); return; } // The first row has only variable patterns: no matching needed for(int i=0;i