use of suite.node.Node in project suite by stupidsing.
the class QueryRewriter method rewriteQuery.
private Node rewriteQuery(Node node0) {
Node nodex;
Prototype prototype = Prototype.of(node0);
PrototypeInfo pi;
if ((pi = infoByPrototype.get(prototype)) != null) {
int length = pi.length;
if (length <= 0)
nodex = node0;
else {
Node[] ps = TreeUtil.elements(node0, length);
if (pi.isSkipFirst)
ps = Arrays.copyOfRange(ps, 1, ps.length, Node[].class);
nodex = Tuple.of(ps);
}
} else
nodex = node0;
return nodex;
}
use of suite.node.Node in project suite by stupidsing.
the class SewingExpressionImpl method evaluator.
public Evaluate_ evaluator(Node node) {
Tree tree = Tree.decompose(node);
if (tree != null) {
Operator op = tree.getOperator();
Evaluate_ lhs, rhs;
IntInt_Int fun;
if (op == TermOp.TUPLE_) {
Tree rightTree = Tree.decompose(tree.getRight());
lhs = evaluator(tree.getLeft());
rhs = evaluator(rightTree.getRight());
fun = TreeUtil.evaluateOp(rightTree.getLeft());
} else {
lhs = evaluator(tree.getLeft());
rhs = evaluator(tree.getRight());
fun = TreeUtil.evaluateOp(op);
}
return env -> fun.apply(lhs.evaluate(env), rhs.evaluate(env));
} else if (node instanceof Int) {
int i = ((Int) node).number;
return env -> i;
} else {
Clone_ f = clonerFactory.cloner(node);
return env -> TreeUtil.evaluate(f.apply(env));
}
}
use of suite.node.Node in project suite by stupidsing.
the class SewingGeneralizerImpl method generalizer.
@Override
public Generalize_ generalizer(Node node) {
List<Generalize_> funs = new ArrayList<>();
Generalize_ fun;
while (true) {
Node node0 = node;
Tree tree;
if (node0 instanceof Atom) {
Atom atom = (Atom) node0;
String name = atom.name;
if (ProverConstant.isCut(node0) || ProverConstant.isVariable(name)) {
int index = vm.computeIndex(atom);
fun = env -> env.get(index);
} else if (ProverConstant.isWildcard(name))
fun = env -> new Reference();
else
fun = env -> node0;
} else if (node0 instanceof Dict) {
Generalize_[][] array = //
Read.from2(//
((Dict) node0).map).map(//
(key, value) -> new Generalize_[] { generalizer(key), generalizer(value) }).toArray(Generalize_[].class);
int length = array.length;
fun = env -> {
@SuppressWarnings("unchecked") Pair<Node, Reference>[] pairs = new Pair[length];
for (int i = 0; i < length; i++) pairs[i] = Pair.of(array[i][0].apply(env), Reference.of(array[i][1].apply(env)));
return Dict.of(pairs);
};
} else if ((tree = Tree.decompose(node0)) != null) {
Operator operator = tree.getOperator();
if (operator != TermOp.OR____) {
Generalize_ f = generalizer(tree.getLeft());
funs.add(env -> Tree.of(operator, f.apply(env), null));
node = tree.getRight();
continue;
} else {
// delay generalizing for performance
Generalize_ lf = generalizer(tree.getLeft());
Generalize_ rf = generalizer(tree.getRight());
fun = env -> Tree.of(operator, lf.apply(env), new Suspend(() -> rf.apply(env)));
}
} else if (node0 instanceof Tuple) {
Generalize_[] fs = Read.from(((Tuple) node0).nodes).map(this::generalizer).toArray(Generalize_.class);
int length = fs.length;
fun = env -> {
Node[] array = new Node[length];
for (int i = 0; i < length; i++) array[i] = fs[i].apply(env);
return Tuple.of(array);
};
} else
fun = env -> node0;
funs.add(fun);
break;
}
if (1 < funs.size())
return env -> {
Tree t = Tree.of(null, null, null);
Node node_ = t;
for (Generalize_ fun_ : funs) {
Tree t_ = Tree.decompose(node_);
Tree.forceSetRight(t_, fun_.apply(env));
node_ = t_.getRight();
}
return t.getRight();
};
else
return funs.get(0);
}
use of suite.node.Node in project suite by stupidsing.
the class SewingProverImpl method save.
private Restore save(Runtime rt) {
Cps cps0 = rt.cps;
Env env0 = rt.env;
Node query0 = rt.query;
IList<Trampoline> cutPoint0 = rt.cutPoint;
IList<Trampoline> rems0 = rt.rems;
int pit0 = rt.trail.getPointInTime();
Sink<Node> handler0 = rt.handler;
return rt_ -> {
rt_.cps = cps0;
rt_.env = env0;
rt_.query = query0;
rt_.cutPoint = cutPoint0;
rt_.rems = rems0;
rt_.trail.unwind(pit0);
rt_.handler = handler0;
};
}
use of suite.node.Node in project suite by stupidsing.
the class SewingProverImpl method compileCpsRules.
private Cps compileCpsRules(Prototype prototype, List<Rule> rules, TraceLevel traceLevel) {
Streamlet<Cps> cpss = Read.from(rules).map(rule -> {
Generalizer generalizer = new Generalizer();
Node head = generalizer.generalize(rule.head);
Node tail = generalizer.generalize(rule.tail);
return compileCpsRule(head, tail);
});
Cps cps0 = orCps(cpss);
return saveEnvCps(cps0);
}
Aggregations