Esempio n. 1
0
        public void TestPopIntegerValueToRegister()
        {
            var program = new CompilerIns[10];

            // Push the values to the stack.
            for (var i = 0; i < 5; i++)
            {
                program[i] =
                    new CompilerIns(OpCode.PSH_LIT,
                                    new object[] { i + 1 });
            }

            // Push the values to the registers in
            // reverse order so that they align.
            for (int j = 0, r = 4; j < 5; j++, r--)
            {
                program[j + 5] =
                    new CompilerIns(OpCode.POP,
                                    new object[] { (Registers)r });
            }

            Vm.Run(QuickCompile.RawCompile(program));

            Assert.IsTrue(Vm.Memory.StackTypes.Count == 0);

            var sp = Vm.Cpu.Registers[(Registers.SP, SystemCtx)];
Esempio n. 2
0
        public void TestModuloExceptions()
        {
            var table = new []
            {
                #region TESTS
                new [] { 0, 0 },
                new [] { 0, 2 },
                #endregion
            };

            for (var i = 0; i < table.Length; i++)
            {
                var entry = table[i];

                var program = new CompilerIns[]
                {
                    new CompilerIns(OpCode.MOV_LIT_REG,
                                    new object[] { entry[0], (byte)Registers.R1 }),
                    new CompilerIns(OpCode.MOV_LIT_REG,
                                    new object[] { entry[1], (byte)Registers.R2 }),
                    new CompilerIns(OpCode.MOD_REG_REG,
                                    new object[] { (byte)Registers.R1, (byte)Registers.R2 }),
                };

                Assert.ThrowsException <DivideByZeroException>
                (
                    () => Vm.Run(QuickCompile.RawCompile(program)),
                    $"Expected exception of type DivideByZeroException for test {i}."
                );
            }
        }
Esempio n. 3
0
        public void TestPushLiteralToStack()
        {
            var program = new CompilerIns[10];

            for (var i = 0; i < 10; i++)
            {
                program[i] =
                    new CompilerIns(OpCode.PSH_LIT,
                                    new object[] { i });
            }

            Vm.Run(QuickCompile.RawCompile(program));

            Assert.IsTrue(Vm.Memory.StackTypes.Count == 10);

            var sp = Vm.Cpu.Registers[(Registers.SP, SystemCtx)];