Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/org/rascalmpl/library/lang/rascal/syntax/Rascal.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,12 @@ syntax FunctionModifiers
= \modifierlist: FunctionModifier* modifiers ;

syntax Comprehension
= @breakable{results,generators} \set: "{" {Expression ","}+ results "|" {Expression ","}+ generators "}"
| @breakable{from,to,generators} \map: "(" Expression from ":" Expression to "|" {Expression ","}+ generators ")"
| @breakable{results,generators} \list: "[" {Expression ","}+ results "|" {Expression ","}+ generators "]" ;
= @breakable{results,generators} \set : "{" {Expression ","}+ results "|" {Expression ","}+ generators "}"
| @breakable{from,to,generators} \map : "(" Expression from ":" Expression to "|" {Expression ","}+ generators ")"
| @breakable{results,generators} \list: "[" {Expression ","}+ results "|" {Expression ","}+ generators "]"
| @breakable{result,generators} \all : "all" "(" {Expression ","}+ results "|" {Expression ","}+ generators ")"
| @breakable{result,generators} \any : "any" "(" {Expression ","}+ results "|" {Expression ","}+ generators ")"
;

syntax Variant
= nAryConstructor: Name name "(" {TypeArg ","}* arguments KeywordFormals keywordArguments ")" ;
Expand Down
52 changes: 21 additions & 31 deletions src/org/rascalmpl/semantics/dynamic/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@

}


@Override
public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {

Expand All @@ -146,78 +145,69 @@
return left.add(right);

}

}

static public class All extends org.rascalmpl.ast.Expression.All {

public All(ISourceLocation __param1, IConstructor tree,
java.util.List<org.rascalmpl.ast.Expression> __param2) {
super(__param1, tree, __param2);
}

@Override
public IBooleanResult buildBacktracker(IEvaluatorContext __eval) {

return new BasicBooleanResult(__eval, this);

}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Result interpret(IEvaluator<Result<IValue>> __eval) {

__eval.setCurrentAST(this);
__eval.notifyAboutSuspension(this);
public Result interpret(IEvaluator<Result<IValue>> eval) {
eval.setCurrentAST(this);
eval.notifyAboutSuspension(this);

java.util.List<org.rascalmpl.ast.Expression> producers = this
.getGenerators();
java.util.List<org.rascalmpl.ast.Expression> producers = this.getGenerators();
int size = producers.size();
IBooleanResult[] gens = new IBooleanResult[size];
Environment[] olds = new Environment[size];
Environment old = __eval.getCurrentEnvt();
Environment old = eval.getCurrentEnvt();
int i = 0;

try {
olds[0] = __eval.getCurrentEnvt();
__eval.pushEnv();
gens[0] = producers.get(0).getBacktracker(__eval);
olds[0] = eval.getCurrentEnvt();
eval.pushEnv();
gens[0] = producers.get(0).getBacktracker(eval);
gens[0].init();

while (i >= 0 && i < size) {
if (__eval.isInterrupted()) {
throw new InterruptException(__eval.getStackTrace(), __eval.getCurrentAST().getLocation());
if (eval.isInterrupted()) {
throw new InterruptException(eval.getStackTrace(), eval.getCurrentAST().getLocation());

Check warning on line 182 in src/org/rascalmpl/semantics/dynamic/Expression.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Expression.java#L182

Added line #L182 was not covered by tests
}
if (gens[i].hasNext()) {
if (!gens[i].next()) {
return new BoolResult(TF.boolType(), __eval
.__getVf().bool(false), __eval);
return new BoolResult(TF.boolType(), VF.bool(false), eval);
}

if (i == size - 1) {
__eval.unwind(olds[i]);
__eval.pushEnv();
eval.unwind(olds[i]);
eval.pushEnv();
} else {
i++;
gens[i] = producers.get(i).getBacktracker(__eval);
gens[i] = producers.get(i).getBacktracker(eval);
gens[i].init();
olds[i] = __eval.getCurrentEnvt();
__eval.pushEnv();
olds[i] = eval.getCurrentEnvt();
eval.pushEnv();
}
} else {
__eval.unwind(olds[i]);
eval.unwind(olds[i]);
i--;
}
}
} finally {
__eval.unwind(old);
}
finally {
eval.unwind(old);
}

return new BoolResult(TF.boolType(), __eval.__getVf().bool(true),
__eval);

return new BoolResult(TF.boolType(), eval.__getVf().bool(true), eval);
}

}

static public class And extends org.rascalmpl.ast.Expression.And {
Expand Down
Loading