import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
-import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
import org.simantics.scl.compiler.elaboration.expressions.block.IncludeStatement;
import org.simantics.scl.compiler.environment.AmbiguousNameException;
import org.simantics.scl.compiler.errors.Locations;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
public class CHRRuleset extends Symbol {
}*/
}
- public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
- for(IncludeStatement include : includes)
- include.value.collectRefs(allRefs, refs);
- for(CHRRule rule : rules)
- rule.collectRefs(allRefs, refs);
- }
-
public void checkType(TypingContext context) {
for(IncludeStatement include : includes)
include.value = include.value.checkType(context, include.ruleset.runtimeRulesetType);
rule.collectVars(allVars, vars);
}
- public void forVariables(VariableProcedure procedure) {
- for(IncludeStatement include : includes)
- include.value.forVariables(procedure);
- for(CHRRule rule : rules)
- rule.forVariables(procedure);
- }
-
- public void collectFreeVariables(THashSet<Variable> vars) {
- for(IncludeStatement include : includes)
- include.value.collectFreeVariables(vars);
- for(CHRRule rule : rules)
- rule.collectFreeVariables(vars);
- }
-
public void setLocationDeep(long loc) {
if(location == Locations.NO_LOCATION) {
this.location = loc;
public IVal generateCode(CodeWriter w) {
for(IncludeStatement include : includes) {
- include.storeVar = include.value.toVal(cachedContext.environment, w);
+ include.storeVar = include.value.toVal(cachedContext, w);
initialPriorityNumber = Math.max(initialPriorityNumber, include.ruleset.initialPriorityNumber + include.ruleset.priorityCount);
}
CHRRulesetObject object = new CHRRulesetObject(runtimeRulesetVariable, this);
PlanRealizer realizer = new PlanRealizer(cachedContext, this, runtimeRulesetVariable, implementationParameters[0], plan.ops);
realizer.nextOp(methodWriter);
if(methodWriter.isUnfinished())
- methodWriter.return_(BooleanConstant.TRUE);
+ methodWriter.return_(rule.location, BooleanConstant.TRUE);
}
}
- if(!includes.isEmpty()) {
+ if(!includes.isEmpty() || extensible) {
{
CodeWriter methodWriter = object.createMethod(w.getModuleWriter(), TVar.EMPTY_ARRAY, Types.PROC, Types.UNIT, new Type[] {Types.CHRContext});
initializer = methodWriter.getFunction();
new JavaMethod(true, runtimeRulesetClassName, "register", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext, include.ruleset.runtimeRulesetType}),
object.getTarget(), methodWriter.getParameters()[0], include.storeVar);
}
- methodWriter.return_(NoRepConstant.UNIT);
+ if(extensible)
+ methodWriter.apply(Locations.NO_LOCATION,
+ new JavaMethod(true, runtimeRulesetClassName, "register", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext}),
+ object.getTarget(), methodWriter.getParameters()[0]);
+ methodWriter.return_(location, NoRepConstant.UNIT);
}
{
CodeWriter methodWriter = object.createMethod(w.getModuleWriter(), TVar.EMPTY_ARRAY, Types.PROC, Types.UNIT, new Type[] {Types.CHRContext});
new JavaMethod(true, runtimeRulesetClassName, "unregister", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext, include.ruleset.runtimeRulesetType}),
object.getTarget(), methodWriter.getParameters()[0], include.storeVar);
}
- methodWriter.return_(NoRepConstant.UNIT);
+ if(extensible)
+ methodWriter.apply(Locations.NO_LOCATION,
+ new JavaMethod(true, runtimeRulesetClassName, "unregister", Types.PROC, Types.UNIT, new Type[] {runtimeRulesetType, Types.CHRContext}),
+ object.getTarget(), methodWriter.getParameters()[0]);
+ methodWriter.return_(location, NoRepConstant.UNIT);
}
}
if(initConstraint != null) {
return runtimeRulesetVariable;
}
- public void collectEffects(THashSet<Type> effects) {
- for(CHRRule rule : rules) {
- for(CHRLiteral literal : rule.head.literals)
- literal.collectQueryEffects(effects);
- for(CHRLiteral literal : rule.head.literals)
- literal.collectEnforceEffects(effects);
- }
- }
-
public void addRule(CHRRule rule) {
rules.add(rule);
rule.parentRuleset = this;