コード例 #1
0
        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);
        }
コード例 #2
0
        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"]);
        }
コード例 #3
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);
        }
コード例 #4
0
        public void Arity()
        {
            Choicepoint c = new Choicepoint();

            c.Arity = 4;

            Assert.AreEqual(4, c.Arity);
        }
コード例 #5
0
        public void TR()
        {
            Choicepoint c = new Choicepoint();



            c.TR = 1;

            Assert.AreEqual(1, c.TR);
        }
コード例 #6
0
        public void NextClause()
        {
            Choicepoint c = new Choicepoint();

            ProgramClause clause = new ProgramClause();

            c.NextClause = clause;

            Assert.AreSame(clause, c.NextClause);
        }
コード例 #7
0
        public void B()
        {
            Choicepoint c = new Choicepoint();

            Choicepoint b = new Choicepoint();

            c.B = b;

            Assert.AreSame(b, c.B);
        }
コード例 #8
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);
        }
コード例 #9
0
        public void H()
        {
            Choicepoint c = new Choicepoint();

            HeapNode h = new HeapNode();

            c.H = h;

            Assert.AreSame(h, c.H);
        }
コード例 #10
0
        public void CE()
        {
            Choicepoint c = new Choicepoint();

            EnvironmentFrame ce = new EnvironmentFrame();

            c.CE = ce;

            Assert.AreSame(ce, c.CE);
        }
コード例 #11
0
        public void CP()
        {
            Choicepoint c = new Choicepoint();

            ProgramNode cp = new ProgramNode();

            c.CP = cp;

            Assert.AreSame(cp, c.CP);
        }
コード例 #12
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());
        }
コード例 #13
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMTrail trail = (AMTrail)state.Trail;
            AMHeap heap = (AMHeap)state.DataArea;

            ProgramClause nextClause = program[_label];
            Choicepoint B = new Choicepoint(program.NumberOfArguments, state.E, program.CP, state.B, nextClause, trail.TR, heap.H);
            B.SaveRegisters(state, program.NumberOfArguments);
            state.B = B;

            program.Next();
        }
コード例 #14
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMTrail   trail   = (AMTrail)state.Trail;
            AMHeap    heap    = (AMHeap)state.DataArea;

            ProgramClause nextClause = program[_label];
            Choicepoint   B          = new Choicepoint(program.NumberOfArguments, state.E, program.CP, state.B, nextClause, trail.TR, heap.H);

            B.SaveRegisters(state, program.NumberOfArguments);
            state.B = B;

            program.Next();
        }
コード例 #15
0
        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);
        }
コード例 #16
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);
        }
コード例 #17
0
        public void bound_1_bound()
        {
            AbstractMachineState state   = SetupMachine();
            AMProgram            program = (AMProgram)state.Program;

            _p = new BoundPredicate();

            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("bound", 1);
            _p.Execute(state);

            Assert.AreNotSame(nextClause, program.P);
        }
コード例 #18
0
        public void var_1_bound()
        {
            AbstractMachineState state   = SetupMachine();
            AMProgram            program = (AMProgram)state.Program;

            _p = new VarPredicate();

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

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

            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.AreSame(nextClause, program.P);
        }
コード例 #19
0
        public void atom_1_struct()
        {
            AbstractMachineState state   = SetupMachine();
            AMProgram            program = (AMProgram)state.Program;

            _p = new AtomPredicate();

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


            X0.Assign(new StructureTerm("f", 1));

            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);
        }
コード例 #20
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);
        }
コード例 #21
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());
        }
コード例 #22
0
        public void Indexing()
        {
            Choicepoint c = new Choicepoint();

            Assert.IsNull(c["Y5"]);
        }