示例#1
0
 public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, int size)
 {
     _ce = ce;
     _cp = cp;
     for(int i = 0; i < size; i++) {
         AddVariable();
     }
 }
 public EnvironmentFrame(EnvironmentFrame ce, ProgramNode cp, int size)
 {
     _ce = ce;
     _cp = cp;
     for (int i = 0; i < size; i++)
     {
         AddVariable();
     }
 }
示例#3
0
 public void Create()
 {
     EnvironmentFrame f = new EnvironmentFrame();
     Assert.IsNull(f.CE);
     Assert.IsNull(f.CP);
     Assert.IsNull(f.Next);
     Assert.IsNull(f.Previous);
     Assert.IsNull(f.PermanentVariables);
 }
示例#4
0
        public void CE()
        {
            Choicepoint c = new Choicepoint();

            EnvironmentFrame ce = new EnvironmentFrame();

            c.CE = ce;

            Assert.AreSame(ce, c.CE);
        }
示例#5
0
        public void PermanentVariables()
        {
            EnvironmentFrame f = new EnvironmentFrame(null, null, 5);

            Assert.AreSame(f["Y0"], f.PermanentVariables);
            Assert.AreSame(f["Y1"], f.PermanentVariables.Next);
            Assert.AreSame(f["Y2"], f.PermanentVariables.Next.Next);
            Assert.AreSame(f["Y3"], f.PermanentVariables.Next.Next.Next);
            Assert.AreSame(f["Y4"], f.PermanentVariables.Next.Next.Next.Next);
            Assert.IsNull(		    f.PermanentVariables.Next.Next.Next.Next.Next);
        }
示例#6
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]);
            }
        }
示例#7
0
        public void AddVariable()
        {
            EnvironmentFrame f = new EnvironmentFrame();

            Assert.IsNull(f["Y0"]);

            f.AddVariable();
            Assert.IsNotNull(f["Y0"]);

            Assert.IsNull(f["Y1"]);

            f.AddVariable();
            Assert.IsNotNull(f["Y1"]);
        }
示例#8
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;
        }
示例#9
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;
 }
示例#10
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);
        }
        public void SetLocalValue()
        {
            AbstractMachineState state = SetupMachine();

            EnvironmentFrame env = new EnvironmentFrame(null, null, 3);
            state.E = env;

            SetLocalValueInstruction i = new SetLocalValueInstruction();

            object[] args = { "X0" };

            i.Process(args);

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

            i.Execute(state);

            Assert.AreEqual("set_local_value", i.Name());
            Assert.AreEqual(1, i.NumberOfArguments());
            Assert.AreSame(X0.Dereference(), ((AbstractTerm)state["H"]).Dereference());
        }
        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);
        }