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.Type;
14 import org.simantics.scl.compiler.types.exceptions.MatchException;
16 public class ECHRRuleset extends Expression {
17 public CHRRuleset ruleset;
20 public ECHRRuleset(CHRRuleset ruleset, Expression in) {
21 this.ruleset = ruleset;
26 protected void updateType() throws MatchException {
27 setType(in.getType());
31 public IVal toVal(CompilationContext context, CodeWriter w) {
32 ruleset.generateCode(w);
33 return in.toVal(context, w);
37 public Expression resolve(TranslationContext context) {
38 if(context.currentRuleset != null) {
39 context.getErrorLog().log(location, "Current version of SCL compiler does not support nested rulesets.");
42 context.currentRuleset = ruleset;
45 context.pushCHRConstraintFrame();
46 ruleset.resolve(context);
47 in = in.resolve(context);
48 context.popCHRConstraintFrame(ruleset.constraints);
51 context.currentRuleset = null;
56 public void setLocationDeep(long loc) {
57 if(location == Locations.NO_LOCATION) {
59 ruleset.setLocationDeep(loc);
60 in.setLocationDeep(loc);
65 public void accept(ExpressionVisitor visitor) {
70 public Expression inferType(TypingContext context) {
71 ruleset.checkType(context);
72 in = in.inferType(context);
77 public Expression checkBasicType(TypingContext context, Type requiredType) {
78 ruleset.checkType(context);
79 in = in.checkType(context, requiredType);
84 public Expression simplify(SimplificationContext context) {
85 ruleset.simplify(context);
86 ruleset.compile(context);
87 in = in.simplify(context);
92 public Expression accept(ExpressionTransformer transformer) {
93 return transformer.transform(this);
97 public IExpression toIExpression(ExpressionInterpretationContext context) {
98 throw new UnsupportedOperationException();