public void TestAstSetGetLValue()
        {
            var astIndex  = Ast.Immediate(777);
            var astSetGet = Ast.SetGetLValue(
                Ast.CallStatic((Action <int, int>)TestAstSetGetLValue_Set, astIndex,
                               Ast.SetGetLValuePlaceholder <int>()),
                Ast.CallStatic((Func <int, int>)TestAstSetGetLValue_Get, astIndex)
                );
            var astFunc = Ast.Statements(
                Ast.Assign(astSetGet, 11),
                Ast.Assign(astSetGet, 12),
                Ast.Assign(astSetGet, astSetGet + 3),
                Ast.Return()
                );

            //Console.WriteLine(GeneratorIL.GenerateToString<Action>(AstFunc));

            var realOutput = TestUtils.CaptureOutput(() =>
            {
                _generatorIl.GenerateDelegate <Action>("Test", astFunc)();
            });

            var expectedOutput = string.Join("\r\n", new[]
            {
                "Set: 777, 11",
                "Set: 777, 12",
                "Get: 777",
                "Set: 777, 1002",
            });

            Assert.Equal(expectedOutput.Trim(), realOutput.Trim());
        }
Ejemplo n.º 2
0
        public void TestAstSetGetLValue()
        {
            var astIndex  = Ast.Immediate(777);
            var astSetGet = Ast.SetGetLValue(
                Ast.CallStatic((Action <int, int>)TestAstSetGetLValue_Set, astIndex,
                               Ast.SetGetLValuePlaceholder <int>()),
                Ast.CallStatic((Func <int, int>)TestAstSetGetLValue_Get, astIndex)
                );

            Assert.Equal("GeneratorCSharpTest.TestAstSetGetLValue_Set(777, 11);",
                         GeneratorCSharp.Reset().GenerateRoot(Ast.Assign(astSetGet, 11)).ToString());
            Assert.Equal("GeneratorCSharpTest.TestAstSetGetLValue_Set(777, 12);",
                         GeneratorCSharp.Reset().GenerateRoot(Ast.Assign(astSetGet, 12)).ToString());
            Assert.Equal(
                "GeneratorCSharpTest.TestAstSetGetLValue_Set(777, (GeneratorCSharpTest.TestAstSetGetLValue_Get(777) + 1));",
                GeneratorCSharp.Reset().GenerateRoot(Ast.Assign(astSetGet, astSetGet + 1)).ToString());
        }
Ejemplo n.º 3
0
        public void TestMethod1()
        {
            var ast2 = ast.Statements(
                ast.Assign(ast.Argument <int>(0, "Argument0"), 777),
                ast.Return()
                );

            Console.WriteLine(AstSerializer.SerializeAsXml(ast2));
        }
Ejemplo n.º 4
0
        public void TestMethod2()
        {
            var pool    = new IlInstanceHolderPool(typeof(int), 16);
            var item    = pool.Alloc();
            var astNode = ast.Statements(
                ast.Assign(ast.StaticFieldAccess(item.FieldInfo), ast.Argument <int>(0, "Value")),
                ast.Return()
                );

            _testOutputHelper.WriteLine(GeneratorCSharp.GenerateString <GeneratorCSharp>(astNode));
            var generatorIl = new GeneratorIl();
            var itemSet     = generatorIl.GenerateDelegate <Action <int> >("ItemSet", astNode);

            itemSet(10);
            Assert.Equal(10, item.Value);
        }
Ejemplo n.º 5
0
        public void TestMethod2()
        {
            var Pool    = new ILInstanceHolderPool(typeof(int), 16);
            var Item    = Pool.Alloc();
            var AstNode = ast.Statements(
                ast.Assign(ast.StaticFieldAccess(Item.FieldInfo), ast.Argument <int>(0, "Value")),
                ast.Return()
                );

            Console.WriteLine(GeneratorCSharp.GenerateString <GeneratorCSharp>(AstNode));
            var GeneratorIL = new GeneratorIL();
            var ItemSet     = GeneratorIL.GenerateDelegate <Action <int> >("ItemSet", AstNode);

            ItemSet(10);
            Assert.AreEqual(10, Item.Value);
        }