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 public class ECHRRuleset extends Expression {
16 public CHRRuleset ruleset;
19 public ECHRRuleset(CHRRuleset ruleset, Expression in) {
20 this.ruleset = ruleset;
25 protected void updateType() throws MatchException {
26 setType(in.getType());
30 public IVal toVal(CompilationContext context, CodeWriter w) {
31 ruleset.generateCode(w);
32 return in.toVal(context, w);
36 public Expression resolve(TranslationContext context) {
37 if(context.currentRuleset != null) {
38 context.getErrorLog().log(location, "Current version of SCL compiler does not support nested rulesets.");
41 context.currentRuleset = ruleset;
44 context.pushCHRConstraintFrame();
45 ruleset.resolve(context);
46 in = in.resolve(context);
47 context.popCHRConstraintFrame(ruleset.constraints);
50 context.currentRuleset = null;
55 public void setLocationDeep(long loc) {
56 if(location == Locations.NO_LOCATION) {
58 ruleset.setLocationDeep(loc);
59 in.setLocationDeep(loc);
64 public void accept(ExpressionVisitor visitor) {
69 public Expression inferType(TypingContext context) {
70 ruleset.checkType(context);
71 in = in.inferType(context);
76 public Expression simplify(SimplificationContext context) {
77 ruleset.simplify(context);
78 ruleset.compile(context);
79 in = in.simplify(context);
84 public Expression accept(ExpressionTransformer transformer) {
85 return transformer.transform(this);
89 public IExpression toIExpression(ExpressionInterpretationContext context) {
90 throw new UnsupportedOperationException();