use of suite.node.Tree in project suite by stupidsing.
the class SldResolution method negate.
private Node negate(Node key) {
Tree tree = Tree.decompose(key, TermOp.TUPLE_);
boolean isAlreadyNegated = tree != null && tree.getLeft() == not;
return isAlreadyNegated ? tree.getRight() : Tree.of(TermOp.TUPLE_, not, key);
}
use of suite.node.Tree in project suite by stupidsing.
the class Assembler method assemble.
public Bytes assemble(Node input) {
Generalizer generalizer = new Generalizer();
Trail trail = new Trail();
List<Pair<Reference, Node>> lnis = new ArrayList<>();
for (Node node0 : Tree.iter(input)) {
Node node = generalizer.generalize(node0);
Tree tree;
if ((tree = Tree.decompose(node, TermOp.EQUAL_)) != null)
if (!Binder.bind(tree.getLeft(), tree.getRight(), trail))
Fail.t("bind failed");
else
;
else if ((tree = Tree.decompose(node, TermOp.TUPLE_)) != null)
lnis.add(Pair.of((Reference) tree.getLeft(), tree.getRight()));
else
Fail.t("cannot assemble " + node);
}
return assemble(generalizer, preassemble.apply(lnis));
}
use of suite.node.Tree in project suite by stupidsing.
the class Assembler method convertByteStream.
private Bytes convertByteStream(Node node) {
BytesBuilder bb = new BytesBuilder();
Tree tree;
while ((tree = Tree.decompose(node, TermOp.AND___)) != null) {
bb.append((byte) ((Int) tree.getLeft()).number);
node = tree.getRight();
}
return bb.toBytes();
}
use of suite.node.Tree in project suite by stupidsing.
the class Amd64Parse method parse.
public Instruction parse(Node node) {
Tree tree = Tree.decompose(node, TermOp.TUPLE_);
Insn insn = Enum.valueOf(Insn.class, ((Atom) tree.getLeft()).name);
Node ops = tree.getRight();
List<Operand> operands = scan(ops, ".0, .1").map(this::parseOperand).toList();
return //
amd64.instruction(//
insn, //
0 < operands.size() ? operands.get(0) : amd64.none, //
1 < operands.size() ? operands.get(1) : amd64.none, 2 < operands.size() ? operands.get(2) : amd64.none);
}
use of suite.node.Tree in project suite by stupidsing.
the class InterpretFunLazy0 method lazy_.
private Fun<IMap<String, Thunk_>, Thunk_> lazy_(Node node) {
Fun<IMap<String, Thunk_>, Thunk_> result;
Tree tree;
Node[] m;
if ((m = Suite.pattern("define .0 := .1 >> .2").match(node)) != null) {
String vk = v(m[0]);
Fun<IMap<String, Thunk_>, Thunk_> value = lazy_(m[1]);
Fun<IMap<String, Thunk_>, Thunk_> expr = lazy_(m[2]);
result = env -> {
Mutable<Thunk_> val = Mutable.nil();
IMap<String, Thunk_> env1 = env.put(vk, () -> val.get().get());
val.set(value.apply(env1)::get);
return expr.apply(env1);
};
} else if ((m = Suite.pattern("if .0 then .1 else .2").match(node)) != null) {
Fun<IMap<String, Thunk_>, Thunk_> if_ = lazy_(m[0]);
Fun<IMap<String, Thunk_>, Thunk_> then_ = lazy_(m[1]);
Fun<IMap<String, Thunk_>, Thunk_> else_ = lazy_(m[2]);
result = env -> (if_.apply(env).get() == Atom.TRUE ? then_ : else_).apply(env);
} else if ((m = Suite.pattern(".0 => .1").match(node)) != null) {
String vk = v(m[0]);
Fun<IMap<String, Thunk_>, Thunk_> value = lazy_(m[1]);
result = env -> () -> new Fun_(in -> value.apply(env.put(vk, in)));
} else if ((m = Suite.pattern(".0 {.1}").match(node)) != null) {
Fun<IMap<String, Thunk_>, Thunk_> fun = lazy_(m[0]);
Fun<IMap<String, Thunk_>, Thunk_> param = lazy_(m[1]);
result = env -> fun(fun.apply(env).get()).apply(param.apply(env));
} else if ((tree = Tree.decompose(node)) != null) {
Operator operator = tree.getOperator();
Fun<IMap<String, Thunk_>, Thunk_> p0 = lazy_(tree.getLeft());
Fun<IMap<String, Thunk_>, Thunk_> p1 = lazy_(tree.getRight());
result = env -> {
Thunk_ r0 = env.get(operator.getName());
Thunk_ r1 = fun(r0.get()).apply(p0.apply(env));
Thunk_ r2 = fun(r1.get()).apply(p1.apply(env));
return r2;
};
} else if (node instanceof Atom) {
String vk = v(node);
result = env -> env.get(vk);
} else
result = env -> () -> node;
return result;
}
Aggregations