示例#1
0
        public void AllocateReplacesVariables()
        {
            var executor = new ByteCodeExecutor(new ByteCodePoint[0], new ILiteral[0], 2);

            var someValue = Literal.NewAtom();

            executor.Register(0).SetTo(new SimpleReference(someValue, new SimpleReference()));
            Assert.AreEqual(someValue, executor.Register(0).Term, "Term is initially set");

            executor.Dispatch(new ByteCodePoint(Operation.Allocate, 1, 0));
            Assert.AreNotEqual(someValue, executor.Register(0).Term, "Term is replaced by allocate");
        }
示例#2
0
        public void AllocatePreservesArgumentsByMovingUp()
        {
            var executor = new ByteCodeExecutor(new ByteCodePoint[0], new ILiteral[0], 2);

            var someValue = Literal.NewAtom();

            executor.Register(0).SetTo(new SimpleReference(someValue, new SimpleReference()));
            Assert.AreEqual(someValue, executor.Register(0).Term, "Term is initially set");

            executor.Dispatch(new ByteCodePoint(Operation.Allocate, 1, 1));
            Assert.AreEqual(someValue, executor.Register(1).Term, "Argument is preserved by allocate");
        }
示例#3
0
        public void PermanentVariablesAreRestored()
        {
            var executor = new ByteCodeExecutor(new ByteCodePoint[0], new ILiteral[0], 2);

            // Allocate a permanent variable
            executor.Dispatch(new ByteCodePoint(Operation.Allocate, 1, 0));

            // Set it to something
            var someValue = Literal.NewAtom();

            executor.Register(0).SetTo(new SimpleReference(someValue, new SimpleReference()));
            Assert.AreEqual(someValue, executor.Register(0).Term, "Term is initially set");

            // Allocate another frame
            executor.Dispatch(new ByteCodePoint(Operation.Allocate, 1, 0));
            Assert.AreNotEqual(someValue, executor.Register(0).Term, "Term is replaced by allocate");

            // Restore the original value using deallocate
            executor.Dispatch(new ByteCodePoint(Operation.Deallocate));
            Assert.AreEqual(someValue, executor.Register(0).Term);
        }