Description of Choicepoint.
Inheritance: HeapNode
Exemplo n.º 1
0
        public void Arity()
        {
            Choicepoint c = new Choicepoint();

            c.Arity = 4;

            Assert.AreEqual(4, c.Arity);
        }
Exemplo n.º 2
0
        public void B()
        {
            Choicepoint c = new Choicepoint();

            Choicepoint b = new Choicepoint();

            c.B = b;

            Assert.AreSame(b, c.B);
        }
Exemplo n.º 3
0
        public void CP()
        {
            Choicepoint c = new Choicepoint();

            ProgramNode cp = new ProgramNode();

            c.CP = cp;

            Assert.AreSame(cp, c.CP);
        }
Exemplo n.º 4
0
        public void Create()
        {
            Choicepoint c = new Choicepoint();

            Assert.IsNull(c.B);
            Assert.IsNull(c.CE);
            Assert.IsNull(c.CP);
            Assert.IsNull(c.H);
            Assert.IsNull(c.NextClause);
        }
Exemplo n.º 5
0
 public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, Choicepoint b0, int size)
 {
     _ce = ce;
     _cp = cp;
     _b0 = b0;
     for (int i = 0; i < size; i++)
     {
         AddVariable();
     }
 }
 public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, Choicepoint b0, int size)
 {
     _ce = ce;
     _cp = cp;
     _b0 = b0;
     for (int i = 0; i < size; i++)
     {
         AddVariable();
     }
 }
Exemplo n.º 7
0
        public void CE()
        {
            Choicepoint c = new Choicepoint();

            EnvironmentFrame ce = new EnvironmentFrame();

            c.CE = ce;

            Assert.AreSame(ce, c.CE);
        }
Exemplo n.º 8
0
        public Choicepoint(int arity, 
		                   EnvironmentFrame ce, 
		                   ProgramNode cp, 
		                   Choicepoint b,
		                   ProgramClause nextClause,
		                   int tr,
		                   HeapNode h)
        {
            _arity = arity;
                               _ce = ce;
                               _cp = cp;
                               _b = b;
                               _nextClause = nextClause;
                               _tr = tr;
                               _h = h;
        }
Exemplo n.º 9
0
 public Choicepoint(int arity,
                    EnvironmentFrame ce,
                    ProgramNode cp,
                    Choicepoint b,
                    ProgramClause nextClause,
                    int tr,
                    HeapNode h)
 {
     _arity      = arity;
     _ce         = ce;
     _cp         = cp;
     _b          = b;
     _nextClause = nextClause;
     _tr         = tr;
     _h          = h;
 }
Exemplo n.º 10
0
        public void Custom()
        {
            HeapNode h = new HeapNode();
            EnvironmentFrame ce = new EnvironmentFrame();
            ProgramClause clause = new ProgramClause();
            Choicepoint b = new Choicepoint();
            ProgramNode cp = new ProgramNode();

            Choicepoint c = new Choicepoint(2, ce, cp, b, clause, 3, h);

            Assert.AreSame(h, c.H);
            Assert.AreEqual(2, c.Arity);
            Assert.AreSame(ce, c.CE);
            Assert.AreSame(cp, c.CP);
            Assert.AreSame(b, c.B);
            Assert.AreSame(clause, c.NextClause);
            Assert.AreEqual(3, c.TR);
        }
Exemplo n.º 11
0
        public void atom_1_list()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new AtomPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ListTerm());

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("atom", 1);
            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
        public void TrustMe()
        {
            AbstractMachineState state = SetupMachine();

            TrustMeInstruction i = new TrustMeInstruction();

            i.Process(null);

            AMProgram program = (AMProgram)state.Program;
            AMTrail trail = (AMTrail)state.Trail;

            Choicepoint b = new Choicepoint();
            b.CE = new EnvironmentFrame();
            Choicepoint old = new Choicepoint();
            b.B = old;
            b.CP = new ProgramNode();
            b.TR = 1;
            b.NextClause = new ProgramClause();
            state.B = b;

            i.Execute(state);

            Assert.AreEqual("trust_me", i.Name());
            Assert.AreEqual(0, i.NumberOfArguments());
            Assert.AreSame(state.E, b.CE);
            Assert.AreSame(program.CP, b.CP);
            Assert.AreEqual(b.TR, trail.TR);
            Assert.AreSame(state.B, old);
        }
        public void RetryMeElse()
        {
            AbstractMachineState state = SetupMachine();

            RetryMeElseInstruction i = new RetryMeElseInstruction();

            AMProgram program = (AMProgram)state.Program;
            AMTrail trail = (AMTrail)state.Trail;

            Choicepoint b = new Choicepoint();
            b.CE = new EnvironmentFrame();
            b.B = new Choicepoint();
            b.CP = new ProgramNode();
            b.TR = 1;
            b.NextClause = new ProgramClause();
            state.B = b;

            program.AddLabel("foobar/2", new ProgramClause());

            object[] args = { "foobar/2" };

            i.Process(args);

            i.Execute(state);

            Assert.AreEqual("retry_me_else", i.Name());
            Assert.AreEqual(1, i.NumberOfArguments());
            Assert.AreSame(state.E, b.CE);
            Assert.AreEqual(b.TR, trail.TR);
            Assert.AreEqual(state.B.NextClause, program["foobar/2"]);
        }
        public void Cut()
        {
            AbstractMachineState state = SetupMachine();

            Choicepoint old = new Choicepoint();

            state.E = new EnvironmentFrame(null, null, old, 0);

            CutInstruction i = new CutInstruction();

            i.Process(null);

            i.Execute(state);

            Assert.AreEqual("cut", i.Name());
            Assert.AreEqual(0, i.NumberOfArguments());
            Assert.AreSame(state.B, old);
        }
Exemplo n.º 15
0
        public void var_1_unbound()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new VarPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("var", 1);
            _p.Execute(state);

            Assert.AreNotSame(nextClause, program.P);
        }
Exemplo n.º 16
0
        public void notunifiable_2()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new NotUnifiablePredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];

            X0.Assign(new ConstantTerm("ali"));
            X1.Assign(new ConstantTerm("ali"));

            Choicepoint b = new Choicepoint();

            ProgramClause nextClause = new ProgramClause();

            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);
            Verify("\\=", 2);

            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
Exemplo n.º 17
0
        public void string_1_string()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new CharPredicate();

            AbstractTerm X0 = (AbstractTerm)state["X0"];

            X0.Assign(new ConstantTerm("a"));

            Choicepoint b = new Choicepoint();
            ProgramClause nextClause = new ProgramClause();
            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            Verify("char", 1);
            _p.Execute(state);

            Assert.AreNotSame(nextClause, program.P);
        }
Exemplo n.º 18
0
        public void Indexing()
        {
            Choicepoint c = new Choicepoint();

            Assert.IsNull(c["Y5"]);
        }
Exemplo n.º 19
0
        public void lessthan_2()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

            _p = new LessThanPredicate();

            Verify("<", 2);

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];

            Choicepoint b = new Choicepoint();

            ProgramClause nextClause = new ProgramClause();

            state.B = new Choicepoint(0, null, null, b, nextClause, 2, null);

            X0.Assign(new ConstantTerm("5"));
            X1.Assign(new ConstantTerm("1"));

            // X0 < X1
            _p.Execute(state);

            Assert.AreSame(nextClause, program.P);
        }
Exemplo n.º 20
0
        public void NextClause()
        {
            Choicepoint c = new Choicepoint();

            ProgramClause clause = new ProgramClause();

            c.NextClause = clause;

            Assert.AreSame(clause, c.NextClause);
        }
Exemplo n.º 21
0
        public void H()
        {
            Choicepoint c = new Choicepoint();

            HeapNode h = new HeapNode();

            c.H = h;

            Assert.AreSame(h, c.H);
        }
Exemplo n.º 22
0
        public void SaveRegisters()
        {
            AbstractMachineState state = new AbstractMachineState(new AMFactory());
            ArrayList prog = new ArrayList();
            prog.Add(new HaltInstruction());
            state.Initialize(prog);

            AbstractTerm X0 = (AbstractTerm)state["X0"];
            AbstractTerm X1 = (AbstractTerm)state["X1"];
            AbstractTerm X2 = (AbstractTerm)state["X2"];

            X0.Assign(new ConstantTerm("ali"));
            X1.Assign(new ConstantTerm("samir"));
            X2.Assign(new ConstantTerm("moe"));

            Choicepoint c = new Choicepoint();

            c.SaveRegisters(state, 3);

            Assert.AreEqual("ali", c["X0"].Data());
            Assert.AreEqual("samir", c["X1"].Data());
            Assert.AreEqual("moe", c["X2"].Data());
        }
Exemplo n.º 23
0
        public void SaveVariable()
        {
            Choicepoint c = new Choicepoint();
            AbstractTerm term = new AbstractTerm();

            c.SaveVariable(term);

            Assert.AreSame(c["X0"], term);

            c["X0"].Assign(new ConstantTerm("ali"));

            Assert.AreEqual("ali", c["X0"].Data());
        }
Exemplo n.º 24
0
        public void TR()
        {
            Choicepoint c = new Choicepoint();

            c.TR = 1;

            Assert.AreEqual(1, c.TR);
        }