예제 #1
0
        public void Expression17()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("a", IrisType.Integer);

            string input =
                @"a + 1 < 7 and a - 1 > 2";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldsfld 0
ldc.i4.1
add
ldc.i4.7
clt
ldsfld 0
ldc.i4.1
sub
ldc.i4.2
cgt
and
";

            Assert.AreEqual(expected, output);
        }
예제 #2
0
        public void SimpleTrue()
        {
            string input =
                @"true";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.1
";

            Assert.AreEqual(expected, output);
        }
예제 #3
0
        public void Expression20()
        {
            string input =
                @"'''you''re'''";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldstr ""'you're'""
";

            Assert.AreEqual(expected, output);
        }
예제 #4
0
        public void SimpleHexNumber()
        {
            string input =
                @"#7F";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.s 127
";

            Assert.AreEqual(expected, output);
        }
예제 #5
0
        public void Comment05()
        {
            string input =
                @"'Not a { comment }' // Comment";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldstr ""Not a { comment }""
";

            Assert.AreEqual(expected, output);
        }
예제 #6
0
        public void SimpleString()
        {
            string input =
                @"'Hello World'";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldstr ""Hello World""
";

            Assert.AreEqual(expected, output);
        }
예제 #7
0
        public void Comment03()
        {
            string input =
                @"1 {Comment} + 1";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.1
ldc.i4.1
add
";

            Assert.AreEqual(expected, output);
        }
예제 #8
0
        public void Expression16()
        {
            string input =
                @"true or true";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.1
ldc.i4.1
or
";

            Assert.AreEqual(expected, output);
        }
예제 #9
0
        public void Expression12()
        {
            string input =
                @"1>1";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.1
ldc.i4.1
cgt
";

            Assert.AreEqual(expected, output);
        }
예제 #10
0
        public void Expression07()
        {
            string input =
                @"not false";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.0
ldc.i4.1
xor
";

            Assert.AreEqual(expected, output);
        }
예제 #11
0
        public void Expression06()
        {
            string input =
                @"2--3";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.2
ldc.i4.3
neg
sub
";

            Assert.AreEqual(expected, output);
        }
예제 #12
0
        public void SimpleCall()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("method", Function.Create(IrisType.Integer, new Variable[0]));

            string input =
                @"method()";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"call _Unknown
";

            Assert.AreEqual(expected, output);
        }
예제 #13
0
        public void Expression05()
        {
            string input =
                @"1+2*3";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.1
ldc.i4.2
ldc.i4.3
mul
add
";

            Assert.AreEqual(expected, output);
        }
예제 #14
0
        public void Expression25()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("method", TestHelpers.MakeTestFunction(IrisType.Integer, new IrisType[] { IrisType.Integer.MakeByRefType() }));
            globals.Add("a", IrisType.Integer);

            string input =
                @"method((a))";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldsflda 0
call _Unknown
";

            Assert.AreEqual(expected, output);
        }
예제 #15
0
        public void Expression08()
        {
            string input =
                @"(2+3)/(3+4)";
            string output   = TestHelpers.TestExpressionParser(input);
            string expected =
                @"ldc.i4.2
ldc.i4.3
add
ldc.i4.3
ldc.i4.4
add
div
";

            Assert.AreEqual(expected, output);
        }
예제 #16
0
        public void Expression18()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("a", IrisType.Integer.MakeArrayType());

            string input =
                @"a[7]";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldsfld 0
ldc.i4.7
ldelem.i4
";

            Assert.AreEqual(expected, output);
        }
예제 #17
0
        public void Expression23()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("a", IrisType.Integer.MakeByRefType());

            string input =
                @"a + 1";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldsfld 0
ldind.i4
ldc.i4.1
add
";

            Assert.AreEqual(expected, output);
        }
예제 #18
0
        public void SimpleWithParams()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("global", IrisType.Integer);
            globals.Add("method", TestHelpers.MakeTestFunction(IrisType.Integer, new IrisType[] { IrisType.Integer, IrisType.Integer, IrisType.Boolean, IrisType.Integer }));

            string input =
                @"method(1, -2, false, global)";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldc.i4.1
ldc.i4.2
neg
ldc.i4.0
ldsfld 0
call _Unknown
";

            Assert.AreEqual(expected, output);
        }
예제 #19
0
        public void Expression19()
        {
            GlobalSymbolList globals = new GlobalSymbolList();

            globals.Add("strcmp", TestHelpers.MakeTestFunction(IrisType.Integer, new IrisType[] { IrisType.Integer, IrisType.Integer }));
            globals.Add("a", IrisType.String);
            globals.Add("b", IrisType.String);

            string input =
                @"a = b";
            string output   = TestHelpers.TestExpressionParser(input, globals);
            string expected =
                @"ldsfld 0
ldsfld 1
call _Unknown
ldc.i4.0
ceq
";

            Assert.AreEqual(expected, output);
        }