Push() public method

public Push ( HeapNode newItem ) : void
newItem HeapNode
return void
Esempio n. 1
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());
        }
Esempio n. 2
0
        public void Push_AbstractTerm()
        {
            AMHeap heap = new AMHeap();

            AbstractTerm term = new AbstractTerm();
            heap.Push(term);

            Assert.AreSame(heap.Top(), term);
        }
Esempio n. 3
0
        public void Push_ConstantTerm()
        {
            AMHeap heap = new AMHeap();

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

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
Esempio n. 4
0
        public void Pop_one_item()
        {
            AMHeap heap = new AMHeap();

            ConstantTerm con = new ConstantTerm("ali");

            heap.Push(con);

            heap.Pop();

            Assert.IsNull(heap.Top());
        }
        public bool Call(string predicatename, int arity, object[] args, bool more)
        {
            AMProgram        program = (AMProgram)_program;
            AMHeap           heap    = (AMHeap)_dataArea;
            AMInstructionSet iset    = new AMInstructionSet();

            // argument indexes
            ArrayList argumentIndexes = new ArrayList();

            if (!more)
            {
                _passedVariables = new ArrayList();
            }


            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] != null)
                {
                    switch (args[i].GetType().ToString())
                    {
                    case "System.String":
                    case "System.Int32":
                    case "System.Boolean":
                        if (!more)
                        {
                            AbstractTerm var = new ConstantTerm(args[i].ToString());
                            heap.Push(var);
                            _passedVariables.Add(-1);
                            AbstractTerm Xn = (AbstractTerm)this["X" + i];
                            Xn.Assign(var);
                        }
                        break;

                    case "Axiom.Runtime.AbstractTerm":
                        if (!more)
                        {
                            AbstractTerm heapVariable = new AbstractTerm();
                            heap.Push(heapVariable);
                            _passedVariables.Add(heapVariable);
                            AbstractTerm Xn = (AbstractTerm)this["X" + i];
                            Xn.Assign(heapVariable);
                        }
                        break;
                    }
                }
            }

            if (!more)
            {
                program.P = new ProgramNode(iset.CreateInstruction("call", predicatename, arity.ToString()));
                program.AddProgramNode(program.P);
                program.AddInstruction(iset.CreateInstruction("halt"));
            }

            // Execute the program
            Transition();

            for (int i = 0; i < _passedVariables.Count; i++)
            {
                if (!(_passedVariables[i] is int))
                {
                    AbstractTerm v = (AbstractTerm)_passedVariables[i];
                    AbstractTerm argumentVariable = (AbstractTerm)args[i];
                    argumentVariable.Assign(v.Dereference());
                }
            }

            return(!_fail);
        }
Esempio n. 6
0
        public void Push_ListTerm()
        {
            AMHeap heap = new AMHeap();

            ListTerm con = new ListTerm();

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
Esempio n. 7
0
        public void Push_StructureTerm()
        {
            AMHeap heap = new AMHeap();

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

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }
Esempio n. 8
0
        public void Push_ObjectTerm()
        {
            AMHeap heap = new AMHeap();

            ObjectTerm con = new ObjectTerm();

            heap.Push(con);

            Assert.AreSame(con, heap.Top());
        }