public static final Name JavaBuiltin_unsafeCoerce = Name.create("JavaBuiltin", "unsafeCoerce");
public static final Name MList_add = Name.create("MList", "add");
public static final Name MList_create = Name.create("MList", "create");
+ public static final Name MList_freeze = Name.create("MList", "freeze");
public static final Name MList_removeLast = Name.create("MList", "removeLast");
public static final TCon MList_T = Types.con("MList", "T");
public static final Name MSet_add = Name.create("MSet", "add");
}
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;
else
context.add(literal, i);
}
- if(activeLiteralId == -1) {
+ if(activeLiteralId == -1 && inputFact != null) {
context.addInitFact(initConstraint, inputFact);
}
return context.createQueryPlan();
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);
+ }
}
return b.toString();
}
- public abstract void toString(StringBuilder b);
+ public void toString(StringBuilder b) {}
public abstract void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w);
}
import java.util.ArrayList;
import java.util.Arrays;
-import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
import org.simantics.scl.compiler.elaboration.chr.CHRRule;
}
}
- public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) {
- ArrayList<CHRLiteral> head = new ArrayList<CHRLiteral>(statement.head.length);
- for(ListQualifier qualifier : statement.head) {
- CHRLiteral literal = convertListQualifier(context, true, qualifier);
- if(literal != null)
- head.add(literal);
- }
- ArrayList<CHRLiteral> body = new ArrayList<CHRLiteral>(statement.body.length);
- for(ListQualifier qualifier : statement.body) {
- CHRLiteral literal = convertListQualifier(context, false, qualifier);
+ public static CHRQuery convertCHRQuery(TranslationContext context, boolean isHead, ListQualifier[] lqs) {
+ ArrayList<CHRLiteral> query = new ArrayList<CHRLiteral>(lqs.length);
+ for(ListQualifier qualifier : lqs) {
+ CHRLiteral literal = convertListQualifier(context, isHead, qualifier);
if(literal != null)
- body.add(literal);
+ query.add(literal);
}
+ return new CHRQuery(query.toArray(new CHRLiteral[query.size()]));
+ }
+
+ public static CHRRule convertCHRStatement(TranslationContext context, CHRStatement statement) {
return new CHRRule(statement.location,
- new CHRQuery(head.toArray(new CHRLiteral[head.size()])),
- new CHRQuery(body.toArray(new CHRLiteral[body.size()])),
+ convertCHRQuery(context, true, statement.head),
+ convertCHRQuery(context, false, statement.body),
null);
}
TIntArrayList chrConstraintFrames = new TIntArrayList();
ArrayList<CHRConstraintEntry> chrConstraintEntries = new ArrayList<CHRConstraintEntry>();
+ public CHRRuleset currentRuleset;
+
static class Entry {
String name;
Variable variable;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
+import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.exceptions.MatchException;
@Override
final public void collectFreeVariables(THashSet<Variable> vars) {
throw new InternalCompilerError(getClass().getSimpleName() + " does not support collectFreeVariables.");
-
}
@Override
throw new InternalCompilerError(getClass().getSimpleName() + " does not support accept.");
}
+ @Override
+ public Expression accept(ExpressionTransformer transformer) {
+ throw new InternalCompilerError(getClass().getSimpleName() + " does not support accept.");
+ }
+
@Override
public Expression checkBasicType(TypingContext context, Type requiredType) {
throw new InternalCompilerError("Class " +
throw new InternalCompilerError("Class " +
getClass().getSimpleName() + " does not implement method forVariables.");
}
+
+ @Override
+ public void setLocationDeep(long loc) {
+ if(location == Locations.NO_LOCATION)
+ location = loc;
+ }
}
}
@Override
public Expression resolve(TranslationContext context) {
+ if(context.currentRuleset != null) {
+ context.getErrorLog().log(location, "Current version of SCL compiler does not support nested rulesets.");
+ return this;
+ }
+ context.currentRuleset = ruleset;
+
context.pushFrame();
context.pushCHRConstraintFrame();
ruleset.resolve(context);
in = in.resolve(context);
context.popCHRConstraintFrame(ruleset.constraints);
context.popFrame();
+
+ context.currentRuleset = null;
+
return this;
}
@Override
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions;
+
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.common.names.Names;
+import org.simantics.scl.compiler.compilation.CompilationContext;
+import org.simantics.scl.compiler.constants.NoRepConstant;
+import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
+import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
+import org.simantics.scl.compiler.elaboration.chr.plan.PlanContext;
+import org.simantics.scl.compiler.elaboration.chr.plan.PlanOp;
+import org.simantics.scl.compiler.elaboration.chr.plan.PlanRealizer;
+import org.simantics.scl.compiler.elaboration.chr.planning.QueryPlanningContext;
+import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
+import org.simantics.scl.compiler.errors.Locations;
+import org.simantics.scl.compiler.internal.codegen.references.IVal;
+import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
+import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+import org.simantics.scl.compiler.types.exceptions.MatchException;
+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 ECHRSelect extends Expression {
+ CHRQuery query;
+ Variable[] existentialVariables;
+ Expression expression;
+ private ArrayList<PlanOp> planOps;
+ private CHRRuleset currentRuleset;
+
+ public ECHRSelect(Expression expression, CHRQuery query) {
+ this.expression = expression;
+ this.query = query;
+ }
+
+ @Override
+ public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
+ query.collectRefs(allRefs, refs);
+ expression.collectRefs(allRefs, refs);
+ }
+
+ @Override
+ public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
+ query.collectVars(allVars, vars);
+ expression.collectVars(allVars, vars);
+ }
+
+ @Override
+ public void forVariables(VariableProcedure procedure) {
+ query.forVariables(procedure);
+ expression.forVariables(procedure);
+ }
+
+ @Override
+ protected void updateType() throws MatchException {
+ setType(Types.list(expression.getType()));
+ }
+
+ @Override
+ public Expression inferType(TypingContext context) {
+ for(Variable variable : existentialVariables)
+ variable.setType(Types.metaVar(Kinds.STAR));
+ query.checkType(context);
+ expression = expression.inferType(context);
+ return this;
+ }
+
+ @Override
+ public Expression simplify(SimplificationContext simplificationContext) {
+ this.expression = expression.simplify(simplificationContext);
+ query.simplify(simplificationContext);
+
+ CompilationContext compilationContext = simplificationContext.getCompilationContext();
+ QueryPlanningContext context = new QueryPlanningContext(compilationContext, existentialVariables);
+ if(query.createQueryPlan(context, null, -1, null))
+ planOps = context.getPlanOps();
+
+ return this;
+ }
+
+ @Override
+ public IVal toVal(CompilationContext context, CodeWriter w) {
+ IVal list = w.apply(location, context.getValue(Names.MList_create).getValue(), NoRepConstant.UNIT);
+ planOps.add(new PlanOp(location) {
+ @Override
+ public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) {
+ w.apply(location, context.getValue(Names.MList_add).getValue(), list, expression.toVal(context, w));
+ }
+ });
+ PlanRealizer realizer = new PlanRealizer(context, currentRuleset, currentRuleset != null ? currentRuleset.runtimeRulesetVariable : null, null, planOps);
+ realizer.nextOp(w);
+ return w.apply(location, context.getValue(Names.MList_freeze).getValue(), list);
+ }
+
+ @Override
+ public void collectFreeVariables(THashSet<Variable> vars) {
+ query.collectFreeVariables(vars);
+ expression.collectFreeVariables(vars);
+ if(existentialVariables != null)
+ for(Variable variable : existentialVariables)
+ vars.remove(variable);
+ }
+
+ @Override
+ public Expression resolve(TranslationContext context) {
+ currentRuleset = context.currentRuleset;
+
+ context.pushExistentialFrame();
+ query.resolve(context);
+ context.disallowNewExistentials();
+ expression = expression.resolve(context);
+ existentialVariables = context.popExistentialFrame();
+ return this;
+ }
+
+ @Override
+ public void setLocationDeep(long loc) {
+ if(location == Locations.NO_LOCATION) {
+ query.setLocationDeep(loc);
+ expression.setLocationDeep(loc);
+ }
+ }
+
+ @Override
+ public Expression decorate(ExpressionDecorator decorator) {
+ this.expression = decorator.decorate(expression);
+ return this;
+ }
+
+ @Override
+ public void collectEffects(THashSet<Type> effects) {
+ expression.collectEffects(effects);
+ query.collectQueryEffects(effects);
+ effects.add(Types.PROC);
+ }
+
+ @Override
+ public void accept(ExpressionVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public Expression accept(ExpressionTransformer transformer) {
+ return transformer.transform(this);
+ }
+}
import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
+/**
+ * Generated maily from EPreLet
+ */
public class ELet extends Expression {
public Assignment[] assignments;
public Expression in;
--- /dev/null
+package org.simantics.scl.compiler.elaboration.expressions;
+
+import org.simantics.scl.compiler.elaboration.chr.translation.CHRTranslation;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.expressions.list.ListQualifier;
+
+public class EPreCHRSelect extends ASTExpression {
+ ListQualifier[] query;
+ Expression expression;
+
+ public EPreCHRSelect(ListQualifier[] query, Expression expression) {
+ this.query = query;
+ this.expression = expression;
+ }
+
+ @Override
+ public Expression resolve(TranslationContext context) {
+ return new ECHRSelect(expression, CHRTranslation.convertCHRQuery(context, true, query)).resolve(context);
+ }
+
+
+}
import gnu.trove.map.hash.THashMap;
import gnu.trove.procedure.TObjectObjectProcedure;
+/**
+ * Generated mainly from EBlock
+ */
public class EPreLet extends ASTExpression {
List<LetStatement> assignments;
return expression;
}
+ /**
+ * Used during simplification and in toIExpression
+ */
public THashSet<Variable> getFreeVariables() {
THashSet<Variable> result = new THashSet<Variable>();
collectFreeVariables(result);
Expression transform(EBinary expression);
Expression transform(EBind expression);
Expression transform(EBlock expression);
+ Expression transform(ECHRSelect expression);
Expression transform(ECHRRuleset expression);
Expression transform(ECHRRulesetConstructor expression);
Expression transform(EConstant expression);
void visit(EBinary expression);
void visit(EBind expression);
void visit(EBlock expression);
+ void visit(ECHRSelect expression);
void visit(ECHRRuleset expression);
void visit(ECHRRulesetConstructor expression);
void visit(EConstant expression);
package org.simantics.scl.compiler.elaboration.expressions;
import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
import org.simantics.scl.compiler.elaboration.equation.EqBasic;
statement.value = statement.value.accept(this);
}
+ public void transform(CHRQuery query) {
+ for(CHRLiteral lit : query.literals)
+ for(int i=0;i<lit.parameters.length;++i)
+ lit.parameters[i] = lit.parameters[i].accept(this);
+ }
+
public void transform(CHRRuleset ruleset) {
for(CHRRule rule : ruleset.rules) {
- for(CHRLiteral lit : rule.head.literals)
- for(int i=0;i<lit.parameters.length;++i)
- lit.parameters[i] = lit.parameters[i].accept(this);
- for(CHRLiteral lit : rule.body.literals)
- for(int i=0;i<lit.parameters.length;++i)
- lit.parameters[i] = lit.parameters[i].accept(this);
+ transform(rule.head);
+ transform(rule.body);
}
}
return expression;
}
+ @Override
+ public Expression transform(ECHRSelect expression) {
+ expression.expression = expression.expression.accept(this);
+ transform(expression.query);
+ return expression;
+ }
+
@Override
public Expression transform(ECHRRulesetConstructor expression) {
transform(expression.ruleset);
package org.simantics.scl.compiler.elaboration.expressions;
import org.simantics.scl.compiler.elaboration.chr.CHRLiteral;
+import org.simantics.scl.compiler.elaboration.chr.CHRQuery;
import org.simantics.scl.compiler.elaboration.chr.CHRRule;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
import org.simantics.scl.compiler.elaboration.equation.EqBasic;
expression.query.accept(this);
expression.expression.accept(this);
}
+
+ @Override
+ public void visit(ECHRSelect expression) {
+ visit(expression.query);
+ expression.expression.accept(this);
+ }
@Override
public void visit(ESimpleLambda expression) {
equation.accept(this);
}
+ public void visit(CHRQuery query) {
+ for(CHRLiteral literal : query.literals)
+ for(Expression parameter : literal.parameters)
+ parameter.accept(this);
+ }
+
public void visit(CHRRuleset ruleset) {
for(CHRRule rule : ruleset.rules) {
- for(CHRLiteral literal : rule.head.literals)
- for(Expression parameter : literal.parameters)
- parameter.accept(this);
- for(CHRLiteral literal : rule.body.literals)
- for(Expression parameter : literal.parameters)
- parameter.accept(this);
+ visit(rule.head);
+ visit(rule.body);
}
}
public abstract void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs);
public abstract void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars);
public abstract void collectFreeVariables(THashSet<Variable> vars);
+ /**
+ * Called in simplification.
+ */
public abstract CompiledQualifier compile(SimplificationContext context);
public abstract void resolve(TranslationContext context);
public abstract void decorate(ExpressionDecorator decorator);
import org.simantics.scl.compiler.elaboration.expressions.EBlock;
import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset;
import org.simantics.scl.compiler.elaboration.expressions.ECHRRulesetConstructor;
+import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect;
import org.simantics.scl.compiler.elaboration.expressions.EConstant;
import org.simantics.scl.compiler.elaboration.expressions.ECoveringBranchPoint;
import org.simantics.scl.compiler.elaboration.expressions.EEnforce;
public void visit(ESelect expression) {
b.append("ESelect");
}
-
+
+ @Override
+ public void visit(ECHRSelect expression) {
+ b.append("ECHRSelect");
+ }
+
@Override
public void visit(ESimpleLambda expression) {
b.append('\\');
shift ESCAPED_SYMBOL, shift CHAR, shift LBRACE,
shift WHEN, shift ATTACHED_HASH,
shift SELECT, shift SELECT_FIRST, shift SELECT_DISTINCT,
- shift TRANSFORMATION, shift EQ
+ shift TRANSFORMATION, shift EQ, shift CHR_SELECT
;
faexp
| (DO | MDO) statements # Do
| (SELECT | SELECT_FIRST | SELECT_DISTINCT)
exp WHERE queryBlock # Select
+ | CHR_SELECT
+ exp WHERE verboseChrQuery # CHRSelect
| ENFORCE queryBlock # Enforce
//| WHEN queryBlock SEMICOLON exp # When
| var # Var
transformation { return sym(supportCHR() ? SCLTerminals.ID : SCLTerminals.TRANSFORMATION); }
select{whitespace}first { return sym(SCLTerminals.SELECT_FIRST); }
select{whitespace}distinct { return sym(SCLTerminals.SELECT_DISTINCT); }
- select { return sym(SCLTerminals.SELECT); }
+ select { return sym(supportCHR() ? SCLTerminals.CHR_SELECT : SCLTerminals.SELECT); }
enforce { return sym(SCLTerminals.ENFORCE); }
do { return sym(SCLTerminals.DO); }
eq { return sym(options.supportEq ? SCLTerminals.EQ : SCLTerminals.ID); }
}
case 175: break;
case 81:
- { return sym(SCLTerminals.SELECT);
+ { return sym(supportCHR() ? SCLTerminals.CHR_SELECT : SCLTerminals.SELECT);
}
case 176: break;
case 82:
public static final boolean TRACE = false;
private static final int INITIAL_CAPACITY = 16;
- private static final int STATE_COUNT = 358;
- private static final int TERMINAL_COUNT = 84;
- private static final int NONTERMINAL_COUNT = 52;
+ private static final int STATE_COUNT = 357;
+ private static final int TERMINAL_COUNT = 85;
+ private static final int NONTERMINAL_COUNT = 51;
private static final int PRODUCT_COUNT = 135;
private static final int[] ACTION_ROW_ID = new int[STATE_COUNT];
private static final int[] ACTION_COLUMN_ID = new int[TERMINAL_COUNT];
- private static final short[] ACTION_TABLE = new short[6944];
- private static final int[] ERROR_TABLE = new int[940];
+ private static final short[] ACTION_TABLE = new short[6765];
+ private static final int[] ERROR_TABLE = new int[949];
private static final int[] GOTO_ROW_ID = new int[STATE_COUNT];
private static final int[] GOTO_COLUMN_ID = new int[NONTERMINAL_COUNT];
- private static final short[] GOTO_TABLE = new short[1708];
+ private static final short[] GOTO_TABLE = new short[1647];
private static final int[] PRODUCT_LHS = new int[PRODUCT_COUNT];
private static final short STATE_MASK = (short)0x0fff;
"SELECT_DISTINCT",
"TRANSFORMATION",
"EQ",
+ "CHR_SELECT",
"ATTACHED_DOT",
"IN",
"THEN",
"accessor",
"case",
"queryBlock",
+ "verboseChrQuery",
"stringLiteral",
"symbolWithoutMinus",
"listQualifier",
"chrQuery",
- "verboseChrQuery",
- "constraintSpec",
"caseRhs",
"guardedExpArrow",
"equation",
return parse(0);
}
public Object parseCommands() {
- return parse(342);
+ return parse(341);
}
public Object parseImport() {
- return parse(350);
+ return parse(349);
}
public Object parseType() {
- return parse(352);
+ return parse(351);
}
public Object parseExp() {
- return parse(354);
+ return parse(353);
}
public Object parseEquationBlock() {
- return parse(356);
+ return parse(355);
}
case 59:
return reduceSelect();
case 60:
- return reduceEnforce();
+ return reduceCHRSelect();
case 61:
- return reduceVar();
+ return reduceEnforce();
case 62:
- return reduceHashedId();
+ return reduceVar();
case 63:
- return reduceBlank();
+ return reduceHashedId();
case 64:
- return reduceInteger();
+ return reduceBlank();
case 65:
- return reduceFloat();
+ return reduceInteger();
case 66:
- return reduceString();
+ return reduceFloat();
case 67:
- return reduceChar();
+ return reduceString();
case 68:
- return reduceTuple();
+ return reduceChar();
case 69:
- return reduceViewPattern();
+ return reduceTuple();
case 70:
- return reduceRightSection();
+ return reduceViewPattern();
case 71:
- return reduceLeftSection();
+ return reduceRightSection();
case 72:
- return reduceListLiteral();
+ return reduceLeftSection();
case 73:
- return reduceRange();
+ return reduceListLiteral();
case 74:
- return reduceListComprehension();
+ return reduceRange();
case 75:
- return reduceAs();
+ return reduceListComprehension();
case 76:
- return reduceRecord();
+ return reduceAs();
case 77:
- return reduceTransformation();
+ return reduceRecord();
case 78:
- return reduceEq();
+ return reduceTransformation();
case 79:
- return reduceRuleDeclarations();
+ return reduceEq();
case 80:
- return reduceStatements();
+ return reduceRuleDeclarations();
case 81:
- return reduceImportShowing();
+ return reduceStatements();
case 82:
- return reduceImportHiding();
+ return reduceImportShowing();
case 83:
- return reduceImportValueItem();
+ return reduceImportHiding();
case 84:
- return reduceFieldDescription();
+ return reduceImportValueItem();
case 85:
- return reduceGuardedExpEq();
+ return reduceFieldDescription();
case 86:
- return reduceFundep();
+ return reduceGuardedExpEq();
case 87:
- return reduceQueryRuleDeclaration();
+ return reduceFundep();
case 88:
- return reduceAnnotation();
+ return reduceQueryRuleDeclaration();
case 89:
- return reduceGuardQuery();
+ return reduceAnnotation();
case 90:
- return reduceEqualsQuery();
+ return reduceGuardQuery();
case 91:
- return reduceBindQuery();
+ return reduceEqualsQuery();
case 92:
- return reduceCompositeQuery();
+ return reduceBindQuery();
case 93:
- return reduceApply();
+ return reduceCompositeQuery();
case 94:
- return reduceSymbol();
+ return reduceApply();
case 95:
- return reduceEscapedId();
+ return reduceSymbol();
case 96:
- return reduceMinus();
+ return reduceEscapedId();
case 97:
- return reduceLess();
+ return reduceMinus();
case 98:
- return reduceGreater();
+ return reduceLess();
case 99:
- return reduceDot();
+ return reduceGreater();
case 100:
- return reduceFieldAccess();
+ return reduceDot();
case 101:
- return reduceIdAccessor();
+ return reduceFieldAccess();
case 102:
- return reduceStringAccessor();
+ return reduceIdAccessor();
case 103:
- return reduceExpAccessor();
+ return reduceStringAccessor();
case 104:
- return reduceCase();
+ return reduceExpAccessor();
case 105:
- return reduceQueryBlock();
+ return reduceCase();
case 106:
- return reduceStringLiteral();
+ return reduceQueryBlock();
case 107:
- return reduceSymbol();
+ return reduceVerboseCHRQuery();
case 108:
- return reduceEscapedId();
+ return reduceStringLiteral();
case 109:
- return reduceLess();
+ return reduceSymbol();
case 110:
- return reduceGreater();
+ return reduceEscapedId();
case 111:
- return reduceDot();
+ return reduceLess();
case 112:
- return reduceGuardQualifier();
+ return reduceGreater();
case 113:
- return reduceLetQualifier();
+ return reduceDot();
case 114:
- return reduceBindQualifier();
+ return reduceGuardQualifier();
case 115:
- return reduceThenQualifier();
+ return reduceLetQualifier();
case 116:
- return reduceCHRQuery();
+ return reduceBindQualifier();
case 117:
- return reduceVerboseCHRQuery();
+ return reduceThenQualifier();
case 118:
- return reduceConstraintSpec();
+ return reduceCHRQuery();
case 119:
return reduceSimpleCaseRhs();
case 120:
*/
protected abstract Object reduceVerboseCHRStatement();
/**
- * statement ::= CONSTRAINT constructor (WHERE constraintSpec)?
+ * statement ::= CONSTRAINT constructor
*/
protected abstract Object reduceConstraintStatement();
/**
* aexp ::= (SELECT | SELECT_FIRST | SELECT_DISTINCT) exp WHERE queryBlock
*/
protected abstract Object reduceSelect();
+ /**
+ * aexp ::= CHR_SELECT exp WHERE verboseChrQuery
+ */
+ protected abstract Object reduceCHRSelect();
/**
* aexp ::= ENFORCE queryBlock
*/
* queryBlock ::= LBRACE (query (SEMICOLON (query SEMICOLON)* query)?)? RBRACE
*/
protected abstract Object reduceQueryBlock();
+ /**
+ * verboseChrQuery ::= LBRACE listQualifier (SEMICOLON listQualifier)* RBRACE
+ */
+ protected abstract Object reduceVerboseCHRQuery();
/**
* stringLiteral ::= BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)* END_STRING
*/
* chrQuery ::= (listQualifier COMMA)* listQualifier
*/
protected abstract Object reduceCHRQuery();
- /**
- * verboseChrQuery ::= LBRACE listQualifier (SEMICOLON listQualifier)* RBRACE
- */
- protected abstract Object reduceVerboseCHRQuery();
- /**
- * constraintSpec ::= LBRACE exp (SEMICOLON exp)* RBRACE
- */
- protected abstract Object reduceConstraintSpec();
/**
* caseRhs ::= ARROW exp (WHERE statements)?
*/
import org.simantics.scl.compiler.elaboration.expressions.EListLiteral;
import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
import org.simantics.scl.compiler.elaboration.expressions.EMatch;
+import org.simantics.scl.compiler.elaboration.expressions.EPreCHRSelect;
import org.simantics.scl.compiler.elaboration.expressions.ERange;
import org.simantics.scl.compiler.elaboration.expressions.ERealLiteral;
import org.simantics.scl.compiler.elaboration.expressions.ERecord;
return new IncludeStatement(name, value);
}
- @Override
+ /*@Override
protected Object reduceConstraintSpec() {
Expression[] expressions = new Expression[length()/2-1];
for(int i=0;i<expressions.length;++i)
expressions[i] = (Expression)get(2*i+1);
return expressions;
+ }*/
+
+ @Override
+ protected Object reduceCHRSelect() {
+ return new EPreCHRSelect((ListQualifier[])get(3), (Expression)get(1));
}
}
public static final int SELECT_DISTINCT = 61;
public static final int TRANSFORMATION = 62;
public static final int EQ = 63;
- public static final int ATTACHED_DOT = 64;
- public static final int IN = 65;
- public static final int THEN = 66;
- public static final int ELSE = 67;
- public static final int WITH = 68;
- public static final int RBRACKET = 69;
- public static final int DOTDOT = 70;
- public static final int AT = 71;
- public static final int SUSPEND_STRING = 72;
- public static final int CONTINUE_STRING = 73;
- public static final int BINDS = 74;
- public static final int IMPLIES = 75;
- public static final int THEN_AFTER_WHEN = 76;
- public static final int CONSTRAINT = 77;
- public static final int BY = 78;
- public static final int QUERY_OP = 79;
- public static final int FORALL = 80;
- public static final int COMMENT = 81;
- public static final int EOL = 82;
- public static final int EOF = 83;
+ public static final int CHR_SELECT = 64;
+ public static final int ATTACHED_DOT = 65;
+ public static final int IN = 66;
+ public static final int THEN = 67;
+ public static final int ELSE = 68;
+ public static final int WITH = 69;
+ public static final int RBRACKET = 70;
+ public static final int DOTDOT = 71;
+ public static final int AT = 72;
+ public static final int SUSPEND_STRING = 73;
+ public static final int CONTINUE_STRING = 74;
+ public static final int BINDS = 75;
+ public static final int IMPLIES = 76;
+ public static final int THEN_AFTER_WHEN = 77;
+ public static final int CONSTRAINT = 78;
+ public static final int BY = 79;
+ public static final int QUERY_OP = 80;
+ public static final int FORALL = 81;
+ public static final int COMMENT = 82;
+ public static final int EOL = 83;
+ public static final int EOF = 84;
}
import java.util.Collections;
public abstract class GrammarParser {
- public static final boolean TRACE = true;
+ public static final boolean TRACE = false;
private static final int INITIAL_CAPACITY = 16;
private static final int STATE_COUNT = 19;
@Test public void CHR9() { test(); }
@Test public void CHR10() { test(); }
@Test public void CHR11() { test(); }
+ @Test public void CHR12() { test(); }
+ @Test public void CHRSelect1() { test(); }
+ @Test public void CHRSelect2() { test(); }
+ @Test public void CHRSelect3() { test(); }
@Test public void ClosureRecursion() { test(); }
@Test public void Collaz() { test(); }
@Test public void Compose() { test(); }
--- /dev/null
+module { export = [main], features = [chr] }
+import "Prelude"
+
+main = ()
+ where
+ when Foo ?x ?x
+ then print (?x :: Integer)
+
+ when True
+ then Foo 1 2
+ Foo 2 1
+ Foo 2 2
+--
+2
+()
\ No newline at end of file
--- /dev/null
+module {
+ features = [chr]
+}
+import "StandardLibrary"
+
+main = select (?a,?b) where
+ ?a <- [1,2,3]
+ ?b <- [2,3,4]
+--
+[(1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,2), (3,3), (3,4)]
\ No newline at end of file
--- /dev/null
+module {
+ features = [chr]
+}
+import "StandardLibrary"
+
+main =
+ select (?a,?b) where
+ Foo ?a
+ Bar ?b
+ where
+ True => Foo 1
+ True => Foo 2
+
+ True => Bar 3
+ True => Bar 4
+--
+[(2,4), (2,3), (1,4), (1,3)]
\ No newline at end of file
--- /dev/null
+module {
+ features = [chr]
+}
+import "StandardLibrary"
+
+main = ()
+ where
+ constraint Edge Integer Integer
+
+ True => Edge 2 3
+ True => Edge 1 2
+ True => Edge 3 4
+
+ when -Edge ?x ?y
+ [] = select ?z where
+ Edge ?z ?x
+ then print "removed \(?x) \(?y)"
+--
+removed 1 2
+removed 2 3
+()
\ No newline at end of file
main = \ /* no parameters */ -> 3
--
-2:30-2:32: Unexpected token '->' (ARROW). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LAMBDA_MATCH, LBRACKET, LET, LPAREN, MATCH, MDO, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION.
\ No newline at end of file
+2:30-2:32: Unexpected token '->' (ARROW). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, CHR_SELECT, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LAMBDA_MATCH, LBRACKET, LET, LPAREN, MATCH, MDO, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION.
\ No newline at end of file
a = =
b = 4
--
-1:5-1:6: Unexpected token '=' (EQUALS). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LAMBDA_MATCH, LBRACKET, LET, LPAREN, MATCH, MDO, MINUS, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION.
\ No newline at end of file
+1:5-1:6: Unexpected token '=' (EQUALS). Expected one of ATTACHED_HASH, BEGIN_STRING, BLANK, CHAR, CHR_SELECT, DO, ENFORCE, EQ, ESCAPED_SYMBOL, FLOAT, ID, IF, INTEGER, LAMBDA, LAMBDA_MATCH, LBRACKET, LET, LPAREN, MATCH, MDO, MINUS, SELECT, SELECT_DISTINCT, SELECT_FIRST, TRANSFORMATION.
\ No newline at end of file