use of suite.node.Tree in project suite by stupidsing.
the class InstructionExtractor method getRegisterNumber.
private int getRegisterNumber(List<Node> rs, int index) {
if (index < rs.size()) {
Node node = rs.get(index).finalNode();
Tree tree;
if (node instanceof Int)
return ((Int) node).number;
else if (node instanceof Reference) {
// transient register
// allocates new register in current local frame
Instruction frameBegin = frameBegins.getFirst();
int registerNumber = frameBegin.op0++;
Binder.bind(node, Int.of(registerNumber), trail);
return registerNumber;
} else if ((tree = Tree.decompose(node, TermOp.COLON_)) != null) {
Node key = tree.getLeft(), value = tree.getRight();
if (key == KEYC)
return allocateInPool(value);
else if (key == KEYL)
return ipByLabelId.get(IdentityKey.of(value));
else if (key == KEYR)
return 0;
}
return Fail.t("cannot parse instruction " + rs.get(0) + " operand " + node);
} else
return 0;
}
use of suite.node.Tree in project suite by stupidsing.
the class LogicInstructionExecutor method handle.
@Override
protected void handle(Exec exec, Instruction insn) {
Activation current = exec.current;
Frame frame = current.frame;
Node[] regs = frame != null ? frame.registers : null;
Trail trail = prover.getTrail();
Instruction insn1;
switch(insn.insn) {
case BACKUPCSP_____:
regs[insn.op0] = exec.current.previous;
break;
case BACKUPDSP_____:
regs[insn.op0] = number(exec.sp);
break;
case BIND__________:
if (!Binder.bind(regs[insn.op0], regs[insn.op1], trail))
// fail
current.ip = insn.op2;
break;
case BINDMARK______:
regs[insn.op0] = number(trail.getPointInTime());
break;
case BINDUNDO______:
trail.unwind(i(regs[insn.op0]));
break;
case DECOMPOSETREE0:
Node node = regs[insn.op0].finalNode();
insn1 = getInstructions()[current.ip++];
TermOp op = TermOp.find(((Atom) constantPool.get(insn1.op0)).name);
int rl = insn1.op1;
int rr = insn1.op2;
if (node instanceof Tree) {
Tree tree = (Tree) node;
if (tree.getOperator() == op) {
regs[rl] = tree.getLeft();
regs[rr] = tree.getRight();
} else
current.ip = insn.op1;
} else if (node instanceof Reference) {
Tree tree = Tree.of(op, regs[rl] = new Reference(), regs[rr] = new Reference());
trail.addBind((Reference) node, tree);
} else
current.ip = insn.op1;
break;
case PROVEINTERPRET:
if (!prover.prove(regs[insn.op0]))
current.ip = insn.op1;
break;
case PROVESYS______:
if (!systemPredicates.call(regs[insn.op0]))
current.ip = insn.op1;
break;
case RESTORECSP____:
exec.current.previous = (Activation) regs[insn.op0];
break;
case RESTOREDSP____:
exec.sp = i(regs[insn.op0]);
break;
default:
Fail.t("unknown instruction " + insn);
}
}
use of suite.node.Tree in project suite by stupidsing.
the class Complexity method complexity.
public int complexity(Node node) {
int max = 0, base = 0;
while (true) {
Tree tree = Tree.decompose(node);
if (tree != null) {
base++;
max = max(max, base + complexity(tree.getLeft()));
node = tree.getRight();
} else
return max;
}
}
use of suite.node.Tree in project suite by stupidsing.
the class Cyclic method isCyclic.
public boolean isCyclic(Node node) {
IdentityKey<Node> idHashNode = IdentityKey.of(node);
boolean isCyclic;
if (!checkedNodes.contains(idHashNode)) {
if (checkingNodes.add(idHashNode)) {
Tree tree = Tree.decompose(node);
isCyclic = tree != null && (isCyclic(tree.getLeft()) || isCyclic(tree.getRight()));
checkingNodes.remove(idHashNode);
} else
isCyclic = true;
checkedNodes.add(idHashNode);
} else
isCyclic = false;
return isCyclic;
}
use of suite.node.Tree in project suite by stupidsing.
the class TreeUtil method elements.
public static Node[] elements(Node node0, int n) {
Node[] params = new Node[n];
Node node = node0;
Tree tree;
for (int i = 0; i < n - 1; i++) if ((tree = Tree.decompose(node, TermOp.TUPLE_)) != null) {
params[i] = tree.getLeft();
node = tree.getRight();
} else
Fail.t("not enough parameters in " + node0);
params[n - 1] = node;
return params;
}
Aggregations