w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE),
parameters[1].toVal(compilationContext, w));
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.WRITE_GRAPH;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.READ_GRAPH;
+ }
}
w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE),
parameters[1].toVal(compilationContext, w));
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.WRITE_GRAPH;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.READ_GRAPH;
+ }
}
import org.simantics.scl.compiler.types.kinds.Kinds;
import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
public class CHRLiteral extends Symbol {
visitor.visit(this);
return b.toString();
}
-
- public void collectQueryEffects(THashSet<Type> effects) {
- // TODO
- }
-
- public void collectEnforceEffects(THashSet<Type> effects) {
- // TODO
- }
}
import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.parsing.Symbol;
-import org.simantics.scl.compiler.types.Type;
import gnu.trove.map.hash.TObjectIntHashMap;
-import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
public class CHRQuery extends Symbol {
visitor.visit(this);
return b.toString();
}
-
- public void collectQueryEffects(THashSet<Type> effects) {
- for(CHRLiteral literal : literals)
- literal.collectQueryEffects(effects);
- }
-
- public void collectEnforceEffects(THashSet<Type> effects) {
- for(CHRLiteral literal : literals)
- literal.collectEnforceEffects(effects);
- }
}
import org.simantics.scl.compiler.types.Types;
import org.simantics.scl.compiler.types.kinds.Kinds;
+import gnu.trove.set.hash.THashSet;
+
public interface CHRRelation {
public static final TVar A = Types.var(Kinds.STAR);
default String[] getFieldNames() {
return null;
}
+ void collectEnforceEffects(THashSet<Type> effects);
+ void collectQueryEffects(THashSet<Type> effects);
}
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 {
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;
import org.simantics.scl.compiler.types.Types;
import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.set.hash.THashSet;
public class CHRConstraint extends Symbol implements CHRRelation {
public final String name;
public String[] getFieldNames() {
return fieldNames;
}
+
+ @Override
+ public void collectEnforceEffects(THashSet<Type> effects) {
+ effects.add(Types.PROC);
+ }
+
+ @Override
+ public void collectQueryEffects(THashSet<Type> effects) {
+ effects.add(Types.PROC);
+ }
}
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import gnu.trove.set.hash.THashSet;
+
public class ExternalCHRRelation implements CHRRelation {
public final SCLRelation relation;
public String[] getFieldNames() {
return relation.getFieldNames();
}
+
+ @Override
+ public void collectEnforceEffects(THashSet<Type> effects) {
+ effects.add(relation.getEnforceEffect());
+ }
+
+ @Override
+ public void collectQueryEffects(THashSet<Type> effects) {
+ effects.add(relation.getQueryEffect());
+ }
}
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.set.hash.THashSet;
+
public enum SpecialCHRRelation implements CHRRelation {
EQUALS(A, A), // only in head
ASSIGN(A, A), // only in body
public TPred[] getTypeConstraints() {
return TPred.EMPTY_ARRAY;
}
+
+ @Override
+ public void collectEnforceEffects(THashSet<Type> effects) {
+ }
+
+ @Override
+ public void collectQueryEffects(THashSet<Type> effects) {
+ }
}
import org.simantics.scl.compiler.types.TPred;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+
+import gnu.trove.set.hash.THashSet;
public class UnresolvedCHRRelation extends Symbol implements CHRRelation {
public String name;
public TPred[] getTypeConstraints() {
throw new InternalCompilerError("Encountered unresolved CHRRelation during type checking.");
}
+
+ @Override
+ public void collectEnforceEffects(THashSet<Type> effects) {
+ effects.add(Types.PROC);
+ }
+
+ @Override
+ public void collectQueryEffects(THashSet<Type> effects) {
+ effects.add(Types.PROC);
+ }
}
package org.simantics.scl.compiler.elaboration.expressions.visitors;
+import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.expressions.EApply;
-import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess;
import org.simantics.scl.compiler.elaboration.expressions.ELambda;
}
@Override
- public void visit(ECHRRuleset expression) {
- effects.add(Types.PROC);
- super.visit(expression);
+ public void visit(CHRRule rule) {
+ for(CHRLiteral literal : rule.head.literals) {
+ super.visit(literal);
+ literal.relation.collectQueryEffects(effects);
+ }
+ for(CHRLiteral literal : rule.body.literals) {
+ super.visit(literal);
+ literal.relation.collectEnforceEffects(effects);
+ }
}
@Override
public void visit(ECHRSelect expression) {
- effects.add(Types.PROC);
- super.visit(expression);
+ for(CHRLiteral literal : expression.query.literals) {
+ super.visit(literal);
+ literal.relation.collectQueryEffects(effects);
+ }
+ expression.expression.accept(this);
}
@Override
public String toString() {
return "Check";
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.NO_EFFECTS;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.NO_EFFECTS;
+ }
}
public String toString() {
return "=";
}
-
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.NO_EFFECTS;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.NO_EFFECTS;
+ }
}
public String toString() {
return "Execute";
}
-
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.NO_EFFECTS;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.NO_EFFECTS;
+ }
}
public String toString() {
return "<-";
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.NO_EFFECTS;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.NO_EFFECTS;
+ }
}
public String toString() {
return "Statement";
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return GRAPH;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return GRAPH;
+ }
});
addEntityType("Resource", new SCLEntityType() {
@Override
public String toString() {
return "Optional";
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.NO_EFFECTS;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.NO_EFFECTS;
+ }
}
Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate.");
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return writingEffect;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return sections.get(0).effect;
+ }
}
public String toString() {
return name;
}
+
+ @Override
+ public Type getEnforceEffect() {
+ return Types.PROC;
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return Types.PROC;
+ }
}
long location,
Expression[] parameters,
Expression[] typeConstraintEvidenceParameters);
+ Type getEnforceEffect();
+ Type getQueryEffect();
}
return new SCLRelation[] { baseRelation };
}
+ @Override
+ public Type getEnforceEffect() {
+ return baseRelation.getEnforceEffect();
+ }
+
+ @Override
+ public Type getQueryEffect() {
+ return baseRelation.getQueryEffect();
+ }
+
}