1 package org.simantics.scl.compiler.elaboration.chr.plan;
3 import org.simantics.scl.compiler.compilation.CompilationContext;
4 import org.simantics.scl.compiler.constants.BooleanConstant;
5 import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
6 import org.simantics.scl.compiler.elaboration.expressions.Expression;
7 import org.simantics.scl.compiler.elaboration.expressions.Variable;
8 import org.simantics.scl.compiler.internal.codegen.references.IVal;
9 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
11 public class AccessFactOp extends PlanOp {
14 CHRConstraint constraint;
16 boolean killAfterMatch;
18 public AccessFactOp(long location, Expression inputFact, CHRConstraint constraint, Variable[] variables,
19 boolean killAfterMatch) {
21 this.inputFact = inputFact;
22 this.constraint = constraint;
23 this.variables = variables;
24 this.killAfterMatch = killAfterMatch;
28 public void toString(StringBuilder b) {
33 for(Variable variable : variables)
34 b.append(' ').append(variable);
35 b.append(" = ").append(inputFact);
39 public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) {
40 IVal inputVal = inputFact.toVal(context.environment, w);
41 for(int i=0;i<variables.length;++i)
42 variables[i].setVal(w.apply(location, constraint.accessComponent(i), inputVal));
43 IVal activeId = w.apply(location, constraint.accessId, inputVal);
44 CodeWriter end = constraint.mayBeRemoved() ? w.createBlock() : null;
45 planContext.partnerFacts.add(new PartnerFact(true, activeId, constraint, inputVal, constraint.mayBeRemoved(), killAfterMatch, null, null, end == null ? null : end.getContinuation()));
46 planContext.nextOp(w);
48 end.return_(BooleanConstant.FALSE);