Search in sources :

Example 36 with Reference

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);
    }
}
Also used : Frame(suite.instructionexecutor.InstructionUtil.Frame) Trail(suite.lp.Trail) TermOp(suite.node.io.TermOp) Reference(suite.node.Reference) Node(suite.node.Node) Tree(suite.node.Tree) Activation(suite.instructionexecutor.InstructionUtil.Activation) Instruction(suite.instructionexecutor.InstructionUtil.Instruction)

Example 37 with Reference

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);
}
Also used : Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) Node(suite.node.Node) ArrayList(java.util.ArrayList)

Example 38 with Reference

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;
}
Also used : Generalizer(suite.lp.doer.Generalizer) Reference(suite.node.Reference) Node(suite.node.Node) ArrayList(java.util.ArrayList)

Aggregations

Reference (suite.node.Reference)38 Node (suite.node.Node)31 Tree (suite.node.Tree)21 Atom (suite.node.Atom)17 ArrayList (java.util.ArrayList)15 Pair (suite.adt.pair.Pair)13 Int (suite.node.Int)13 List (java.util.List)11 Generalizer (suite.lp.doer.Generalizer)10 TermOp (suite.node.io.TermOp)10 Read (suite.streamlet.Read)10 Trail (suite.lp.Trail)9 Dict (suite.node.Dict)9 Tuple (suite.node.Tuple)9 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Binder (suite.lp.doer.Binder)7 Str (suite.node.Str)7 Fail (suite.util.Fail)7 Suite (suite.Suite)6