package org.simantics.scl.compiler.elaboration.chr; import org.cojen.classfile.TypeDesc; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.constants.Constant; import org.simantics.scl.compiler.constants.JavaConstructor; import org.simantics.scl.compiler.internal.codegen.chr.CHRRuntimeRulesetCodeGenerator; import org.simantics.scl.compiler.internal.codegen.references.BoundVar; import org.simantics.scl.compiler.internal.codegen.references.Val; import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction; import org.simantics.scl.compiler.internal.codegen.ssa.SSAObject; import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable; import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; import org.simantics.scl.compiler.internal.codegen.utils.ModuleBuilder; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.procedure.TIntProcedure; import gnu.trove.set.hash.TIntHashSet; public class CHRRulesetObject extends SSAObject { CHRRuleset ruleset; public BoundVar this_; public BoundVar[] parameters; public TObjectIntHashMap parameterIndexMap; public TypeDesc[] parameterTypeDescs; public CHRRulesetObject(BoundVar target, CHRRuleset ruleset) { super(ruleset.runtimeRulesetType); this.setTarget(target); this.ruleset = ruleset; } @Override public Constant liftClosure(BoundVar newTarget, BoundVar[] parameters) { ruleset.rulesetObject = this; this.this_ = newTarget; this.parameters = parameters; this.parameterIndexMap = new TObjectIntHashMap<>(parameters.length); for(int i=0;i { Val binding = valRef.getBinding(); if(parameterIndexMap.containsKey(binding)) usedParameterIndices.add(parameterIndexMap.get((BoundVar)binding)); }); usedParameterIndices.forEach(new TIntProcedure() { @Override public boolean execute(int i) { loader.defineParameter(i, parameters[i]); return true; } }); // Generate code function.markGenerateOnFly(); function.generateCodeWithAlreadyPreparedParameters(mb); } }