Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void CE()
        {
            Choicepoint c = new Choicepoint();

            EnvironmentFrame ce = new EnvironmentFrame();

            c.CE = ce;

            Assert.AreSame(ce, c.CE);
        }
Exemplo n.º 3
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);
        }
        protected override void EndProcessing()
        {
            EnvironmentFrame frame = Context.EnvironmentStack.Pop();

            if (frame != null)
            {
                if (!String.IsNullOrEmpty(frame.Description))
                {
                    WriteVerbose("Restoring " + frame.Description);
                }
                frame.Restore();
            }
        }
        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();
        }
Exemplo n.º 6
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"]);
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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]);
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public void Allocate()
        {
            AbstractMachineState state = SetupMachine();

            AMHeap heap = (AMHeap)state.DataArea;

            AllocateInstruction i = new AllocateInstruction();

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


            EnvironmentFrame env = (EnvironmentFrame)heap.Top();

            Assert.AreEqual("allocate", i.Name());
            Assert.AreEqual(0, i.NumberOfArguments());
            Assert.AreSame(env, state.E);
            for (int r = 0; r < 20; r++)
            {
                Assert.IsNotNull(env["Y" + r.ToString()]);
            }
        }
Exemplo n.º 12
0
        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());
        }
        protected override void EndProcessing()
        {
            var environmentFrame = new EnvironmentFrame(this.Description);

            Context.EnvironmentStack.Push(environmentFrame);
        }