Ejemplo n.º 1
0
 public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, int size)
 {
     _ce = ce;
     _cp = cp;
     for(int i = 0; i < size; i++) {
         AddVariable();
     }
 }
Ejemplo n.º 2
0
        public void CP()
        {
            Choicepoint c = new Choicepoint();

            ProgramNode cp = new ProgramNode();

            c.CP = cp;

            Assert.AreSame(cp, c.CP);
        }
Ejemplo n.º 3
0
 public void AddInstruction(AbstractInstruction instruction)
 {
     if (_program == null)
     {
         _program = new ProgramNode(instruction);
         _programTop = _program;
         _p = _program;
         return;
     }
     _programTop.Next = new ProgramNode(instruction);
     _programTop = _programTop.Next;
 }
Ejemplo n.º 4
0
        public void CE_CP_Size()
        {
            ProgramNode _cp = new ProgramNode();
            EnvironmentFrame _ce = new EnvironmentFrame();

            EnvironmentFrame f = new EnvironmentFrame(_ce, _cp, 10);

            Assert.AreSame(_ce, f.CE);
            Assert.AreSame(_cp, f.CP);
            for(int i = 0; i < 10; i++) {
                string varName = "Y" + i.ToString();
                Assert.IsNotNull(f[varName]);
            }
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 public ProgramNode(AbstractInstruction instruction)
 {
     _instruction = instruction;
     _next        = null;
 }
Ejemplo n.º 8
0
 public ProgramNode()
 {
     _instruction = null;
     _next        = null;
 }
        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);
        }
Ejemplo n.º 10
0
 public void Next()
 {
     _p = _p.Next;
 }
Ejemplo n.º 11
0
 public void AddProgramNode(ProgramNode node)
 {
     if (_program == null)
     {
         _program = node;
         _programTop = _program;
         return;
     }
     _programTop.Next = node;
     _programTop = _programTop.Next;
 }
Ejemplo n.º 12
0
 public ProgramNode()
 {
     _instruction = null;
     _next = null;
 }
Ejemplo n.º 13
0
 public void Next()
 {
     _p = _p.Next;
 }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
 public ProgramNode(AbstractInstruction instruction, ProgramNode next)
 {
     _instruction = instruction;
     _next        = next;
 }
Ejemplo n.º 16
0
 public ProgramNode(AbstractInstruction instruction)
 {
     _instruction = instruction;
     _next = null;
 }
Ejemplo n.º 17
0
 public ProgramNode(AbstractInstruction instruction, ProgramNode next)
 {
     _instruction = instruction;
     _next = next;
 }
        public void Deallocate()
        {
            AbstractMachineState state = SetupMachine();
            AMProgram program = (AMProgram)state.Program;

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

            DeallocateInstruction i = new DeallocateInstruction();

            i.Execute(state);

            Assert.AreEqual("deallocate", i.Name());
            Assert.AreEqual(0, i.NumberOfArguments());
            Assert.AreSame(CP, program.CP);
            Assert.AreSame(env, state.E);
        }
Ejemplo n.º 19
0
        public override void Initialize(ArrayList program)
        {
            foreach (AbstractInstruction i in program)
            {
                if (i.Name() == "procedure")
                {
                    ProcedureInstruction p = (ProcedureInstruction)i;
                    ProgramClause pClause = new ProgramClause(p.ProcedureName, p.Arity);
                    AddLabel(pClause.Name + "/" + pClause.Arity, pClause);
                }
                else
                {
                    AddInstruction(i);
                }
            }

            _p = _program;
        }