--- /dev/null
+package org.simantics.scl.compiler.elaboration.chr.plan;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.scl.compiler.compilation.CompilationContext;\r
+import org.simantics.scl.compiler.elaboration.expressions.Expression;\r
+import org.simantics.scl.compiler.internal.codegen.references.IVal;\r
+import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;\r
+import org.simantics.scl.compiler.internal.elaboration.matching2.PatternMatchingCompiler2;\r
+import org.simantics.scl.compiler.internal.elaboration.matching2.Row2;\r
+\r
+public class MatchOp extends PlanOp {\r
+ public Expression scrutinee;\r
+ public Expression pattern;\r
+ \r
+ public MatchOp(long location, Expression scrutinee, Expression pattern) {\r
+ super(location);\r
+ this.scrutinee = scrutinee;\r
+ this.pattern = pattern;\r
+ }\r
+ \r
+ @Override\r
+ public void toString(StringBuilder b) {\r
+ b.append("MATCH ").append(pattern).append(" = ").append(scrutinee);\r
+ }\r
+\r
+ @Override\r
+ public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) {\r
+ CodeWriter body = w.createBlock();\r
+ CodeWriter end = w.createBlock();\r
+ \r
+ IVal[] scrutineeVals = new IVal[1];\r
+ scrutineeVals[0] = scrutinee.toVal(context.environment, w);\r
+\r
+ ArrayList<Row2> rows = new ArrayList<Row2>(1);\r
+ rows.add(new Row2(new Expression[] {pattern}, body.getContinuation()));\r
+\r
+ PatternMatchingCompiler2.split(w, context.environment, scrutineeVals, end.getContinuation(), rows);\r
+ \r
+ planContext.nextOp(body);\r
+ if(body.isUnfinished())\r
+ body.jump(end.getContinuation());\r
+ \r
+ w.continueAs(end);\r
+ }\r
+}\r