AddProgramNode() public method

public AddProgramNode ( ProgramNode node ) : void
node ProgramNode
return void
        /// <summary>
        /// Call a predicate that takes no arguments
        /// </summary>
        /// <param name="predicateName">predicate name only.</param>
        /// <returns>success or failure</returns>
        public bool Call(string predicateName)
        {
            AMProgram program = (AMProgram)_program;

            AMInstructionSet iset = new AMInstructionSet();

            if (!program.IsDefined(predicateName + "/0"))
            {
                return(false);
            }

            // Add the call instruction
            program.P = new ProgramNode(iset.CreateInstruction("call", predicateName, "0"));

            program.AddProgramNode(program.P);

            // Add the halt insturction
            program.AddInstruction(iset.CreateInstruction("halt"));

            // Execute the program
            Transition();

            return(!_fail);
        }
        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);
        }
        public bool Call(string predicateName, int arity, object[] args)
        {
            AMProgram        program = (AMProgram)_program;
            AMHeap           heap    = (AMHeap)_dataArea;
            AMInstructionSet iset    = new AMInstructionSet();

            if (!program.IsDefined(predicateName + "/" + arity))
            {
                return(false);
            }
            ArrayList a = new ArrayList();

            ProgramNode entryPoint = null;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i].GetType().ToString())
                {
                case "System.String":
                case "System.Int32":
                case "System.Boolean":
                    if (entryPoint == null)
                    {
                        entryPoint = new ProgramNode(iset.CreateInstruction("put_constant", args[i].ToString(), "X" + i.ToString()));
                        program.AddProgramNode(entryPoint);
                    }
                    else
                    {
                        program.AddInstruction(iset.CreateInstruction("put_constant", args[i].ToString(), "X" + i.ToString()));
                    }
                    break;

                case "Axiom.Runtime.AbstractTerm":
                    a.Add(i);
                    if (entryPoint == null)
                    {
                        entryPoint = new ProgramNode(iset.CreateInstruction("put_variable", "X" + args[i].ToString(), "X" + i.ToString()));
                        program.AddProgramNode(entryPoint);
                    }
                    else
                    {
                        program.AddInstruction(iset.CreateInstruction("put_variable", "X" + args[i].ToString(), "X" + args[i].ToString()));
                    }
                    break;
                }
            }

            // Add the call instruction
            program.AddInstruction(iset.CreateInstruction("call", predicateName, arity.ToString()));

            // Add the halt insturction
            program.AddInstruction(iset.CreateInstruction("halt"));

            program.P = entryPoint;

            // Execute the program
            Transition();

            foreach (int argumentNumber in a)
            {
                AbstractTerm var = (AbstractTerm)args[argumentNumber];
                var.Assign((AbstractTerm)this["X" + argumentNumber.ToString()]);
            }

            return(!_fail);
        }