use of suite.node.Data 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.Data in project suite by stupidsing.
the class ProveTracer method expandWithTrace.
public Node expandWithTrace(Node query, Prover prover, Iterate<Node> expand) {
Node query1 = new Cloner().clone(query);
if (currentDepth < 64) {
Record record0 = currentRecord;
int depth0 = currentDepth;
Record record = new Record(record0, query1, currentDepth + 1);
Data<Source<Boolean>> enter = new Data<>(() -> {
currentRecord = record;
currentDepth = record.depth;
record.start = records.size();
records.add(record);
return Boolean.TRUE;
});
Data<Source<Boolean>> leaveOk = new Data<>(() -> {
currentRecord = record0;
currentDepth = depth0;
record.nOkays++;
return Boolean.TRUE;
});
Data<Source<Boolean>> leaveFail = new Data<>(() -> {
currentRecord = record0;
currentDepth = depth0;
record.end = records.size();
return Boolean.FALSE;
});
Node alt = prover.getAlternative();
Node rem = prover.getRemaining();
prover.setAlternative(Tree.of(TermOp.OR____, leaveFail, alt));
prover.setRemaining(Tree.of(TermOp.AND___, leaveOk, rem));
query = expand.apply(query);
query = Tree.of(TermOp.AND___, enter, query);
} else
query = expand.apply(query);
return query;
}
use of suite.node.Data in project suite by stupidsing.
the class Prover method prove0.
public boolean prove0(Node query) {
rem = OK;
alt = FAIL;
while (true) {
// logUtil.info(Formatter.dump(query));
query = query.finalNode();
if (query instanceof Tree) {
Tree tree = (Tree) query;
Node left = tree.getLeft(), right = tree.getRight();
switch((TermOp) tree.getOperator()) {
case OR____:
int pit = trail.getPointInTime();
Node bt = new Data<Source<Boolean>>(() -> {
trail.unwind(pit);
return Boolean.TRUE;
});
alt = andTree(bt, orTree(andTree(right, rem), alt));
query = left;
continue;
case AND___:
rem = andTree(right, rem);
query = left;
continue;
case EQUAL_:
query = isSuccess(bind(left, right));
break;
default:
}
} else if (query instanceof Data) {
query = isSuccess(Data.<Source<Boolean>>get(query).source());
continue;
}
Boolean b = systemPredicates.call(query);
if (b != null)
query = isSuccess(b);
// not handled above
if (query == OK)
if (rem != OK) {
query = rem;
rem = OK;
} else
return true;
else if (query == FAIL)
if (alt != FAIL) {
query = alt;
alt = FAIL;
rem = OK;
} else
return false;
else {
boolean isTrace = config.isTrace();
if (isTrace) {
Set<String> whites = Suite.tracePredicates;
Set<String> blacks = Suite.noTracePredicates;
Prototype prototype = Prototype.of(query);
Node head = prototype != null ? prototype.head : null;
Atom atom = head instanceof Atom ? (Atom) head : null;
String name = atom != null ? atom.name : null;
isTrace &= whites == null || whites.contains(name);
isTrace &= blacks == null || !blacks.contains(name);
}
if (!isTrace)
query = expand(query);
else
query = tracer.expandWithTrace(query, this, this::expand);
}
}
}
use of suite.node.Data in project suite by stupidsing.
the class Formatter method format_.
private void format_(Node node, int parentPrec) {
new //
SwitchNode<Node>(//
node).doIf(Atom.class, n -> {
sb.append(quoteAtomIfRequired(n.name));
}).doIf(Data.class, n -> {
Object data = n.data;
if (data instanceof Chars)
sb.append("Chars<" + quoteStringIfRequired(data.toString()) + ">");
else if (data instanceof Node)
sb.append("Data<" + data.toString() + ">");
else
sb.append("Data<" + data.getClass().getSimpleName() + ">");
}).doIf(Dict.class, n -> {
sb.append("dict<");
for (Entry<Node, Reference> e : n.map.entrySet()) {
format(e.getKey(), TermOp.getLeftPrec(TermOp.AND___));
sb.append(":");
format(e.getValue(), TermOp.getLeftPrec(TermOp.AND___));
sb.append(",");
}
sb.append(">");
}).doIf(Int.class, n -> {
sb.append(n.number);
}).doIf(Reference.class, n -> {
sb.append(n.name());
}).doIf(Str.class, n -> {
sb.append(quoteStringIfRequired(n.value));
}).doIf(Tree.class, n -> {
formatTree(parentPrec, n);
}).doIf(Tuple.class, n -> {
sb.append("tuple<");
for (Node n_ : n.nodes) {
format(n_, TermOp.getLeftPrec(TermOp.AND___));
sb.append(", ");
}
sb.append(">");
}).doIf(Node.class, n -> {
sb.append(n.getClass().getSimpleName() + '@' + Integer.toHexString(System.identityHashCode(n)));
}).nonNullResult();
}
use of suite.node.Data in project suite by stupidsing.
the class CommandDispatcher method elaborate.
private void elaborate(Node node0, Sink<Node> sink) {
int[] count = { 0 };
NodeEnv<Atom> ne = new CompileGeneralizerImpl().g(node0).source();
Node node1 = ne.node;
Node elab = new Data<Source<Boolean>>(() -> {
String dump = ne.dumpVariables();
if (!dump.isEmpty())
opt.prompt().println(dump);
count[0]++;
return Boolean.FALSE;
});
sink.sink(Tree.of(TermOp.AND___, node1, elab));
if (count[0] == 1)
opt.prompt().println(count[0] + " solution\n");
else
opt.prompt().println(count[0] + " solutions\n");
}
Aggregations