コード例 #1
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            AbstractTerm Vn = ((AbstractTerm)state[_vn]).Dereference();

            if (state.IsReadMode)
            {
                state.Fail = !Vn.Unify((AbstractTerm)state.S);
            }
            else
            {
                AbstractTerm newVariable = new AbstractTerm();
                newVariable.Assign(Vn);
                heap.Push(newVariable);
            }

            state.S = state.S.Next;

            if (state.Fail)
            {
                state.Backtrack();
            }
            else
            {
                program.Next();
            }
        }
コード例 #2
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            AbstractTerm Ai = ((AbstractTerm)state[_ai]).Dereference();

            if (Ai.IsReference)
            {
                heap.Push(new ListTerm());
                Ai.Bind((AbstractTerm)heap.Top());
                state.IsWriteMode = true;
            }
            else if (Ai.IsList)
            {
                state.S          = Ai.Next;
                state.IsReadMode = true;
            }
            else
            {
                state.Fail = true;
            }

            if (state.Fail)
            {
                state.Backtrack();
            }
            else
            {
                program.Next();
            }
        }
コード例 #3
0
        public override void Execute(AbstractMachineState state)
        {
            AMHeap    heap    = (AMHeap)state.DataArea;
            AMProgram program = (AMProgram)state.Program;


            if (_vn[0] == 'Y')
            {
                if (state.E[_vn] == null)
                {
                    throw new Exception("INTERNAL ERROR: Yn variable is null in E");
                }
                AbstractTerm Ai = (AbstractTerm)state[_ai];
                AbstractTerm Vn = (AbstractTerm)state.E[_vn];
                Ai.Assign(Vn);

                program.Next();
            }
            else
            {
                heap.Push(new AbstractTerm());

                AbstractTerm x = (AbstractTerm)state[_vn];
                AbstractTerm a = (AbstractTerm)state[_ai];

                x.Assign((AbstractTerm)heap.Top());
                a.Assign((AbstractTerm)heap.Top());

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

            ExecuteForeignPredicate(state);
        }
コード例 #5
0
        public void Pop_an_empty_heap()
        {
            AMHeap heap = new AMHeap();

            object top = heap.Pop();

            Assert.IsNull(top);
        }
コード例 #6
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            heap.Push(new ConstantTerm(_constant));

            program.Next();
        }
コード例 #7
0
        public void Push_AbstractTerm()
        {
            AMHeap heap = new AMHeap();

            AbstractTerm term = new AbstractTerm();

            heap.Push(term);

            Assert.AreSame(heap.Top(), term);
        }
コード例 #8
0
        public void Push_ConstantTerm()
        {
            AMHeap heap = new AMHeap();

            ConstantTerm con = new ConstantTerm("Hello, World!");

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
コード例 #9
0
        public void Push_StructureTerm()
        {
            AMHeap heap = new AMHeap();

            StructureTerm con = new StructureTerm("Hello, World!", 2);

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
コード例 #10
0
        public void Push_ListTerm()
        {
            AMHeap heap = new AMHeap();

            ListTerm con = new ListTerm();

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
コード例 #11
0
        public void Push_ObjectTerm()
        {
            AMHeap heap = new AMHeap();

            ObjectTerm con = new ObjectTerm();

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
コード例 #12
0
        public void Initialize()
        {
            AMHeap heap = new AMHeap();
            AbstractMachineState state = new AbstractMachineState(new AMFactory());

            heap.Initialize(state);

            Assert.IsNull(heap.H);
            Assert.IsNull(heap.Top());
        }
コード例 #13
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

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

            Console.Write(X0.ToString());

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

            AbstractTerm Vn = (AbstractTerm)state[vn];
            AbstractTerm Ai = (AbstractTerm)state[ai];

            Ai.Assign(Vn);
            program.Next();
        }
コード例 #15
0
        public override void Execute(AbstractMachineState state)
        {
            AMHeap    heap    = (AMHeap)state.DataArea;
            AMProgram program = (AMProgram)state.Program;

            for (int i = 0; i < _n; i++)
            {
                heap.Push(new AbstractTerm());
            }

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

            state.B = state.E.B0;

            // tidy trail here?

            program.Next();
        }
コード例 #17
0
        public void Pop_one_item()
        {
            AMHeap heap = new AMHeap();

            ConstantTerm con = new ConstantTerm("ali");

            heap.Push(con);

            heap.Pop();

            Assert.IsNull(heap.Top());
        }
コード例 #18
0
        public override void Execute(AbstractMachineState state)
        {
            AMHeap    heap    = (AMHeap)state.DataArea;
            AMProgram program = (AMProgram)state.Program;

            heap.Push(new StructureTerm(structureName, arity));

            AbstractTerm Ai = (AbstractTerm)state[ai];

            Ai.Assign((AbstractTerm)heap.Top());

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

            AbstractTerm Ai = (AbstractTerm)state[_ai];

            heap.Push(new ListTerm());

            Ai.Assign((AbstractTerm)heap.Top());

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

            EnvironmentFrame env = new EnvironmentFrame(state.E, program.CP, state.B0, 2);

            // Is this really needed?
            heap.Push(env);

            state.E = (EnvironmentFrame)heap.Top();

            program.Next();
        }
コード例 #21
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();
        }
コード例 #22
0
        public void Pop_two_items()
        {
            AMHeap heap = new AMHeap();

            ConstantTerm con   = new ConstantTerm("ali");
            ConstantTerm first = new ConstantTerm("foo");

            heap.Push(first);
            heap.Push(con);

            heap.Pop();

            Assert.AreSame(first, heap.Top());
        }
コード例 #23
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            AbstractTerm Vn = new AbstractTerm();

            AbstractTerm reg = (AbstractTerm)state[_vn];

            Vn.Assign(reg.Dereference());

            heap.Push(Vn);

            program.Next();
        }
コード例 #24
0
        public void SetVoid()
        {
            AbstractMachineState state = SetupMachine();
            AMHeap heap = (AMHeap)state.DataArea;


            object[] args = { "3" };

            SetVoidInstruction i = new SetVoidInstruction();

            i.Process(args);
            i.Execute(state);

            Assert.AreEqual("set_void", i.Name());
            Assert.AreEqual(1, i.NumberOfArguments());
            Assert.IsTrue(((AbstractTerm)heap.Pop()).IsReference);
            Assert.IsTrue(((AbstractTerm)heap.Pop()).IsReference);
            Assert.IsTrue(((AbstractTerm)heap.Pop()).IsReference);
        }
コード例 #25
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            AbstractTerm Vn = (AbstractTerm)state[_vn];

            if (state.IsReadMode)
            {
                state.Fail = !Vn.Unify((AbstractTerm)state.S);
            }
            else
            {
                AbstractTerm addr = Vn.Dereference();

                if (IsEnvironmentVariable(addr, state))
                {
                    // Push a new variable on the heap
                    AbstractTerm newVariable = new AbstractTerm();
                    heap.Push(newVariable);
                    addr.Bind((AbstractTerm)heap.Top());
                }
                else
                {
                    AbstractTerm newHeapItem = new AbstractTerm();
                    newHeapItem.Assign(addr);
                    heap.Push(newHeapItem);
                }
            }
            if (state.S != null)
            {
                state.S = state.S.Next;
            }

            if (state.Fail)
            {
                state.Backtrack();
            }
            else
            {
                program.Next();
            }
        }
コード例 #26
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;

            AbstractTerm Ai = ((AbstractTerm)state[_ai]).Dereference();

            if (Ai.IsReference)
            {
                heap.Push(new StructureTerm(_structureName, _arity));
                Ai.Bind((AbstractTerm)heap.Top());
                state.IsWriteMode = true;
            }
            else if (Ai.IsStructure)
            {
                if (Ai.Name == _structureName)
                {
                    // set S to next item on heap
                    state.S = Ai.Next;

                    // set read mode
                    state.IsReadMode = true;
                }
                else
                {
                    state.Fail = true;
                }
            }
            else
            {
                state.Fail = true;
            }

            if (state.Fail)
            {
                state.Backtrack();
            }
            else
            {
                program.Next();
            }
        }
コード例 #27
0
        public void SetVariable()
        {
            AbstractMachineState state = SetupMachine();

            SetVariableInstruction i = new SetVariableInstruction();

            object[] args = { "X0" };

            i.Process(args);

            i.Execute(state);

            Assert.AreEqual("set_variable", i.Name());
            Assert.AreEqual(1, i.NumberOfArguments());

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

            AMHeap heap = (AMHeap)state.DataArea;

            Assert.AreSame(X0, heap.Top());
        }
コード例 #28
0
        public override void Execute(AbstractMachineState state)
        {
            AMProgram program = (AMProgram)state.Program;
            AMHeap    heap    = (AMHeap)state.DataArea;
            AMTrail   trail   = (AMTrail)state.Trail;

            state.B.UnsaveRegisters(state, state.B.Arity);

            state.E    = state.B.CE;
            program.CP = state.B.CP;

            trail.Unwind(state.B.TR);

            trail.TR = state.B.TR;

            heap.H = state.B.H;

            state.B = state.B.B;

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

            if (state.IsReadMode)
            {
                for (int i = 0; i < _n; i++)
                {
                    state.S = state.S.Next;
                }
            }
            else
            {
                for (int j = 0; j < _n; j++)
                {
                    heap.Push(new AbstractTerm());
                }
            }

            program.Next();
        }
コード例 #30
0
        private void SetTypes(AbstractTerm obj, object[] arguments)
        {
            AMHeap       da     = (AMHeap)runtime.DataArea;
            AbstractTerm argObj = obj;

            for (int i = 0; i < arguments.Length; i++)
            {
                AbstractTerm a = (AbstractTerm)argObj.Next;
                argObj = (AbstractTerm)argObj.Next;

                if (!a.IsObject)
                {
                    // Need to check if unification is the apropriate method
                    a.Unify(new ConstantTerm(arguments[i].ToString()));
                }
                else
                {
                    // Need to check if unification is the apropriate method
                    a.Unify(new ObjectTerm(arguments[i]));
                }
            }
        }