use of suite.node.Reference 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.Reference in project suite by stupidsing.
the class Constants method bindSecrets.
public static Fixie<String, String, String, String, String, String, String, String, String, String> bindSecrets(String pattern) {
Generalizer generalizer = new Generalizer();
String[] m;
if (secrets().prove(generalizer.generalize(Suite.parse(pattern)))) {
List<String> list = new ArrayList<>();
int i = 0;
Node n;
while (!((n = generalizer.getVariable(Atom.of("." + i++))).finalNode() instanceof Reference)) list.add(Formatter.display(n));
m = list.toArray(new String[0]);
} else
m = null;
if (m != null) {
int length = m.length;
return //
Fixie.of(//
0 < length ? m[0] : null, //
1 < length ? m[1] : null, //
2 < length ? m[2] : null, //
3 < length ? m[3] : null, //
4 < length ? m[4] : null, //
5 < length ? m[5] : null, //
6 < length ? m[6] : null, //
7 < length ? m[7] : null, //
8 < length ? m[8] : null, 9 < length ? m[9] : null);
} else
return Fail.t("Cannot match " + pattern);
}
use of suite.node.Reference in project suite by stupidsing.
the class Constants method secrets.
public static String[] secrets(String pattern) {
Generalizer generalizer = new Generalizer();
if (secrets().prove(generalizer.generalize(Suite.parse(pattern)))) {
List<String> list = new ArrayList<>();
int i = 0;
Node n;
while (!((n = generalizer.getVariable(Atom.of("." + i++))).finalNode() instanceof Reference)) list.add(Formatter.display(n));
return list.toArray(new String[0]);
} else
return null;
}
Aggregations