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%2Finternal%2Felaboration%2Fmatching%2FPatternMatchingCompiler.java;h=12bf42e5bed980910034d3aa661938341a743247;hp=9bf056bef825fe3a6c3db4e0cbef0fed1572c6eb;hb=862c09c9608329f326404342d12da61792eece2c;hpb=695ffae899b981f31695e5fdd30ac8fed9fe84b8 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)); } }