use of suite.node.Node in project suite by stupidsing.
the class ThunkUtil method yawnList.
public static Outlet<Node> yawnList(Iterate<Node> yawn, Node node, boolean isFacilitateGc) {
return Outlet.of(new Source<>() {
private Node node_ = node;
private boolean first = true;
public Node source() {
Tree tree;
// first node is not a thunk, remainings are
if (!first)
node_ = yawn.apply(node_);
else
first = false;
if ((tree = Tree.decompose(node_)) != null) {
Node result = yawn.apply(tree.getLeft());
node_ = tree.getRight();
if (isFacilitateGc)
Tree.forceSetRight(tree, null);
return result;
} else if (node_ == Atom.NIL)
return null;
else
return Fail.t("not a list, unable to expand");
}
});
}
use of suite.node.Node in project suite by stupidsing.
the class ThunkUtil method deepYawn.
/**
* Evaluates the whole (lazy) term to actual by invoking all the thunks.
*/
public static Node deepYawn(Iterate<Node> yawn, Node node) {
node = yawn.apply(node);
if (node instanceof Tree) {
Tree tree = (Tree) node;
Node left = deepYawn(yawn, tree.getLeft());
Node right = deepYawn(yawn, tree.getRight());
node = Tree.of(tree.getOperator(), left, right);
}
return node;
}
use of suite.node.Node in project suite by stupidsing.
the class EvaluateUtil method configureFunExecutor.
private FunInstructionExecutor configureFunExecutor(FunCompilerConfig fcc) {
Node node = fccNodeFun.apply(fcc.isLazy());
Node code = doFcc(node, fcc);
if (code != null)
if (fcc.isLazy())
return new LazyFunInstructionExecutor(code);
else
return new EagerFunInstructionExecutor(code);
else
return Fail.t("function compilation failure");
}
use of suite.node.Node in project suite by stupidsing.
the class Suite method evaluateFilterFun.
public static void evaluateFilterFun(String program, Reader reader, Writer writer, boolean isLazy, boolean isDo) {
try {
Node node0 = parse(program);
Node node1 = applyStringReader(node0, reader);
Node node2 = isDo ? Suite.applyPerform(node1, Atom.of("string")) : node1;
Node node3 = applyWriter(node2);
evaluateFunToWriter(fcc(node3, isLazy), writer);
} catch (IOException ex) {
Fail.t(ex);
}
}
use of suite.node.Node in project suite by stupidsing.
the class TypeChecker method getType.
private Node getType(Node data) {
Node type;
Tree tree;
if (data instanceof Reference)
type = variableTypes.computeIfAbsent(IdentityKey.of(data), k -> new Reference()).finalNode();
else if ((tree = Tree.decompose(data)) != null)
if (tree.getOperator() == TermOp.AND___) {
type = Suite.substitute(".0;", getType(tree.getLeft()));
bind(type, getType(tree.getRight()));
} else if (tree.getOperator() == TermOp.TUPLE_) {
Node name = tree.getLeft();
if (name instanceof Atom) {
Node node = tree.getRight();
Node[] ps = TreeUtil.elements(node, TreeUtil.nElements(node));
type = getEnumType(name, Tree.of(TermOp.TUPLE_, Read.from(ps).map(this::getType).toList()));
} else
// free type
return new Reference();
} else {
Atom name = Atom.of(tree.getOperator().getName());
Node lt = getType(tree.getLeft());
Node rt = getType(tree.getRight());
type = getEnumType(name, Tree.of(TermOp.TUPLE_, lt, rt));
}
else if (data == Atom.NIL)
type = Suite.substitute("_;");
else if (data instanceof Atom)
type = getEnumType(data, Atom.NIL);
else
type = Atom.of(data.getClass().getSimpleName());
return type;
}
Aggregations