1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.compilation.CompilationContext;
4 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
5 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
6 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
8 import org.simantics.scl.compiler.errors.Locations;
9 import org.simantics.scl.compiler.internal.codegen.references.IVal;
10 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
11 import org.simantics.scl.compiler.internal.interpreted.IExpression;
12 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
13 import org.simantics.scl.compiler.types.exceptions.MatchException;
15 import gnu.trove.map.hash.TObjectIntHashMap;
16 import gnu.trove.set.hash.TIntHashSet;
18 public class ECHRRuleset extends Expression {
19 public CHRRuleset ruleset;
22 public ECHRRuleset(CHRRuleset ruleset, Expression in) {
23 this.ruleset = ruleset;
28 public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
29 ruleset.collectVars(allVars, vars);
30 in.collectVars(allVars, vars);
34 protected void updateType() throws MatchException {
35 setType(in.getType());
39 public IVal toVal(CompilationContext context, CodeWriter w) {
40 ruleset.generateCode(w);
41 return in.toVal(context, w);
45 public Expression resolve(TranslationContext context) {
46 if(context.currentRuleset != null) {
47 context.getErrorLog().log(location, "Current version of SCL compiler does not support nested rulesets.");
50 context.currentRuleset = ruleset;
53 context.pushCHRConstraintFrame();
54 ruleset.resolve(context);
55 in = in.resolve(context);
56 context.popCHRConstraintFrame(ruleset.constraints);
59 context.currentRuleset = null;
64 public void setLocationDeep(long loc) {
65 if(location == Locations.NO_LOCATION) {
67 ruleset.setLocationDeep(loc);
68 in.setLocationDeep(loc);
73 public void accept(ExpressionVisitor visitor) {
78 public Expression inferType(TypingContext context) {
79 ruleset.checkType(context);
80 in = in.inferType(context);
85 public Expression simplify(SimplificationContext context) {
86 ruleset.simplify(context);
87 ruleset.compile(context);
88 in = in.simplify(context);
93 public Expression accept(ExpressionTransformer transformer) {
94 return transformer.transform(this);
98 public IExpression toIExpression(ExpressionInterpretationContext context) {
99 throw new UnsupportedOperationException();