1 package org.simantics.scl.compiler.elaboration.chr.plan;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.compilation.CompilationContext;
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
7 import org.simantics.scl.compiler.internal.codegen.references.IVal;
8 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
9 import org.simantics.scl.compiler.internal.elaboration.matching2.PatternMatchingCompiler2;
10 import org.simantics.scl.compiler.internal.elaboration.matching2.Row2;
12 public class MatchOp extends PlanOp {
13 public Expression scrutinee;
14 public Expression pattern;
16 public MatchOp(long location, Expression scrutinee, Expression pattern) {
18 this.scrutinee = scrutinee;
19 this.pattern = pattern;
23 public void toString(StringBuilder b) {
24 b.append("MATCH ").append(pattern).append(" = ").append(scrutinee);
28 public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) {
29 CodeWriter body = w.createBlock();
30 CodeWriter end = w.createBlock();
32 IVal[] scrutineeVals = new IVal[1];
33 scrutineeVals[0] = scrutinee.toVal(context, w);
35 ArrayList<Row2> rows = new ArrayList<Row2>(1);
36 rows.add(new Row2(new Expression[] {pattern}, body.getContinuation()));
38 PatternMatchingCompiler2.split(w, context, scrutineeVals, end.getContinuation(), rows);
40 planContext.nextOp(body);
41 if(body.isUnfinished())
42 body.jump(end.getContinuation());