use of suite.jdk.gen.FunExpression.FunExpr in project suite by stupidsing.
the class CompileExpressionImpl method evaluator.
public Evaluate_ evaluator(Node node) {
FunCreator<Evaluate_> fc = FunCreator.of(Evaluate_.class, false);
return fc.create(new Iterate<>() {
private FunExpr env;
public FunExpr apply(FunExpr env) {
this.env = env;
return compile_(node);
}
private FunExpr compile_(Node node) {
return new //
SwitchNode<FunExpr>(//
node).match2(".0 + .1", (a, b) -> {
return compileOperator(a, b, "+");
}).match2(".0 - .1", (a, b) -> {
return compileOperator(a, b, "-");
}).match2(".0 * .1", (a, b) -> {
return compileOperator(a, b, "*");
}).match2(".0 / .1", (a, b) -> {
return compileOperator(a, b, "/");
}).match2(".0 and .1", (a, b) -> {
return compileOperator(a, b, "&&");
}).match2(".0 or .1", (a, b) -> {
return compileOperator(a, b, "||");
}).match2(".0 shl .1", (a, b) -> {
return compileOperator(a, b, "<<");
}).match2(".0 shr .1", (a, b) -> {
return compileOperator(a, b, ">>");
}).applyIf(Int.class, i -> {
return f.int_(i.number);
}).applyIf(Node.class, i -> {
Clone_ n_ = clonerFactory.cloner(node);
Evaluate_ evaluate = env -> TreeUtil.evaluate(n_.apply(env));
return f.object(evaluate).invoke("evaluate", env);
}).nonNullResult();
}
private FunExpr compileOperator(Node a, Node b, String op) {
FunExpr fe0 = compile_(a);
FunExpr fe1 = compile_(b);
return f.bi(op, fe0, fe1);
}
}).apply(Map.ofEntries());
}
Aggregations