public void AllocatePreservesArgumentsByMovingDown() { var executor = new ByteCodeExecutor(new ByteCodePoint[0], new ILiteral[0], 3); executor.Dispatch(new ByteCodePoint(Operation.Allocate, 2, 0)); var someValue = Literal.NewAtom(); executor.Register(2).SetTo(new SimpleReference(someValue, new SimpleReference())); Assert.AreEqual(someValue, executor.Register(2).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"); }
public void AllocateReplacesPermanentVariables() { var executor = new ByteCodeExecutor(new ByteCodePoint[0], new ILiteral[0], 3); executor.Dispatch(new ByteCodePoint(Operation.Allocate, 2, 0)); var someValue = Literal.NewAtom(); executor.Register(1).SetTo(new SimpleReference(someValue, new SimpleReference())); Assert.AreEqual(someValue, executor.Register(1).Term, "Term is initially set"); executor.Dispatch(new ByteCodePoint(Operation.Allocate, 1, 0)); Assert.AreNotEqual(someValue, executor.Register(0).Term); Assert.AreNotEqual(someValue, executor.Register(1).Term); Assert.AreNotEqual(someValue, executor.Register(2).Term); }
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); }