Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public void TestAstSwitch()
        {
            var Local = AstLocal.Create <int>("Local");
            var Ast   = ast.Statements(
                ast.Switch(
                    ast.Local(Local),
                    ast.Default(ast.Return("Nor One, nor Three")),
                    ast.Case(1, ast.Return("One")),
                    ast.Case(3, ast.Return("Three"))
                    ),
                ast.Return("Invalid!")
                );

            var Actual   = GeneratorCSharp.GenerateString <GeneratorCSharp>(Ast);
            var Expected = @"
				{
					switch (Local) {
						case 1:
							return ""One"";
						break;
						case 3:
							return ""Three"";
						break;
						default:
							return ""Nor One, nor Three"";
						break;
					}
					return ""Invalid!"";
				}
			"            ;

            Actual   = new Regex(@"\s+").Replace(Actual, " ").Trim();
            Expected = new Regex(@"\s+").Replace(Expected, " ").Trim();

            Assert.AreEqual(Expected, Actual);
        }
Beispiel #4
0
        public void TestAstSwitch()
        {
            var local = AstLocal.Create <int>("Local");
            var ast   = Ast.Statements(
                Ast.Switch(
                    Ast.Local(local),
                    Ast.Default(Ast.Return("Nor One, nor Three")),
                    Ast.Case(1, Ast.Return("One")),
                    Ast.Case(3, Ast.Return("Three"))
                    ),
                Ast.Return("Invalid!")
                );

            var actual   = GeneratorCSharp.GenerateString <GeneratorCSharp>(ast);
            var expected = @"
				{
					switch (Local) {
						case 1:
							return ""One"";
						break;
						case 3:
							return ""Three"";
						break;
						default:
							return ""Nor One, nor Three"";
						break;
					}
					return ""Invalid!"";
				}
			"            ;

            actual   = new Regex(@"\s+").Replace(actual, " ").Trim();
            expected = new Regex(@"\s+").Replace(expected, " ").Trim();

            Assert.Equal(expected, actual);
        }