use of suite.node.Node in project suite by stupidsing.
the class InterpretFunLazy method lazy.
public Thunk_ lazy(Node node) {
Node parsed = parse(node);
Map<String, Thunk_> df = new HashMap<>();
df.put(TermOp.AND___.name, binary((a, b) -> new Pair_(a, b)));
df.put("fst", () -> new Fun_(in -> ((Pair_) in.get()).first_));
df.put("if", () -> new Fun_(a -> () -> new Fun_(b -> () -> new Fun_(c -> a.get() == Atom.TRUE ? b : c))));
df.put("snd", () -> new Fun_(in -> ((Pair_) in.get()).second));
for (Entry<Operator, IntInt_Bool> e : TreeUtil.boolOperations.entrySet()) {
IntInt_Bool fun = e.getValue();
df.put(e.getKey().getName(), binary((a, b) -> b(fun.apply(compare(a.get(), b.get()), 0))));
}
for (Entry<Operator, IntInt_Int> e : TreeUtil.intOperations.entrySet()) {
IntInt_Int fun = e.getValue();
df.put(e.getKey().getName(), binary((a, b) -> Int.of(fun.apply(i(a), i(b)))));
}
List<String> keys = df.keySet().stream().sorted().collect(Collectors.toList());
Lazy_ lazy0 = new Lazy_(0, IMap.empty());
Frame frame = new Frame(null);
for (String key : keys) {
lazy0 = lazy0.put(Atom.of(key));
frame.add(df.get(key));
}
return lazy0.lazy_(parsed).apply(frame);
}
use of suite.node.Node in project suite by stupidsing.
the class InterpretFunLazy0 method lazy.
public Thunk_ lazy(Node node) {
Thunk_ error = () -> Fail.t("error termination");
IMap<String, Thunk_> env = IMap.empty();
env = env.put(Atom.TRUE.name, () -> Atom.TRUE);
env = env.put(Atom.FALSE.name, () -> Atom.FALSE);
env = env.put(TermOp.AND___.name, () -> new Fun_(a -> () -> new Fun_(b -> () -> new Pair_(a, b))));
env = env.put(ERROR.name, error);
env = env.put(FST__.name, () -> new Fun_(in -> ((Pair_) in.get()).first));
env = env.put(SND__.name, () -> new Fun_(in -> ((Pair_) in.get()).second));
for (Entry<Operator, IntInt_Bool> e : TreeUtil.boolOperations.entrySet()) {
IntInt_Bool fun = e.getValue();
env = env.put(e.getKey().getName(), () -> new Fun_(a -> () -> new Fun_(b -> () -> b(fun.apply(i(a), i(b))))));
}
for (Entry<Operator, IntInt_Int> e : TreeUtil.intOperations.entrySet()) {
IntInt_Int fun = e.getValue();
env = env.put(e.getKey().getName(), () -> new Fun_(a -> () -> new Fun_(b -> () -> Int.of(fun.apply(i(a), i(b))))));
}
return lazy_(node).apply(env);
}
use of suite.node.Node in project suite by stupidsing.
the class Intrinsics method drain.
public static Node drain(IntrinsicCallback callback, IPointer<Node> pointer) {
Intrinsic drain = new Intrinsic() {
public Node invoke(IntrinsicCallback callback1, List<Node> inputs) {
IPointer<Node> pointer1 = Data.get(inputs.get(0));
Node head;
if ((head = pointer1.head()) != null) {
Node left = callback1.enclose(Intrinsics.id_, head);
Node right = callback1.enclose(this::invoke, new Data<>(pointer1.tail()));
return Tree.of(TermOp.OR____, left, right);
} else
return Atom.NIL;
}
};
return callback.yawn(callback.enclose(drain, new Data<>(pointer)));
}
use of suite.node.Node in project suite by stupidsing.
the class InstructionExtractor method tupleToList.
private List<Node> tupleToList(Node node) {
List<Node> results = new ArrayList<>();
Tree tree;
while ((tree = Tree.decompose(node, TermOp.TUPLE_)) != null) {
results.add(tree.getLeft());
node = tree.getRight();
}
results.add(node);
return results;
}
use of suite.node.Node in project suite by stupidsing.
the class InstructionExtractor method extractInstructions.
private void extractInstructions(Node snippet, List<List<Node>> rsList) {
Deque<Node> deque = new ArrayDeque<>();
deque.add(snippet);
Tree tree;
Node value;
while (!deque.isEmpty()) if ((tree = Tree.decompose(deque.pop(), TermOp.AND___)) != null) {
IdentityKey<Node> key = IdentityKey.of(tree);
Integer ip = ipByLabelId.get(key);
if (ip == null) {
ipByLabelId.put(key, ip = rsList.size());
List<Node> rs = tupleToList(tree.getLeft());
if (rs.get(0) == FRAME)
if ((value = label(rs.get(1))) != null) {
rsList.add(List.of(Atom.of("FRAME-BEGIN")));
extractInstructions(value, rsList);
rsList.add(List.of(Atom.of("FRAME-END")));
} else
Fail.t("bad frame definition");
else {
rsList.add(rs);
for (Node op : List_.right(rs, 1)) if ((value = label(op)) != null)
deque.push(value);
deque.push(tree.getRight());
}
} else
rsList.add(List.of(Atom.of("JUMP"), Int.of(ip)));
}
}
Aggregations