public void CompileNullString()
        {
            var compiler = new SimpleCompiler(null);

            var result = compiler.Compile();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Length);
        }
        private static void CompileBytecode(string text, Bytecodes bc)
        {
            var compiler = new SimpleCompiler(text);
            var result   = compiler.Compile();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual((byte)bc, result[0]);
        }
        private static void CompileBytecode(string text, Bytecodes bc, params byte[] bytes)
        {
            var compiler = new SimpleCompiler(text);
            var result   = compiler.Compile();

            Assert.IsNotNull(result);
            Assert.AreEqual(1 + bytes.Length, result.Length);
            Assert.AreEqual((byte)bc, result[0]);

            for (int k = 0; k < bytes.Length; k++)
            {
                Assert.AreEqual(bytes[k], result[k + 1]);
            }
        }
예제 #4
0
        public void IsZeroUsingSimpleCompiler()
        {
            string program = "push 2\n" +
                             "iszero\n" +
                             "push 0\n" +
                             "iszero";

            SimpleCompiler compiler = new SimpleCompiler(program);

            Machine machine = new Machine();

            machine.Execute(compiler.Compile());

            var stack = machine.Stack;

            Assert.IsNotNull(stack);
            Assert.AreEqual(2, stack.Size);
            Assert.AreEqual(DataWord.Zero, stack.ElementAt(1));
            Assert.AreEqual(DataWord.One, stack.ElementAt(0));
        }