Exemplo n.º 1
0
        public void Invocation()
        {
            AffeCompiler comp = new AffeCompiler(typeof(Tests));
            comp.SymbolTable.AddSymbol(new TypeSymbol("BoundClass", typeof(BoundObjectTest)));
            DMCall dm = (DMCall) comp.Compile("Push(BoundObject.InstanceCall());" +
                                              "Push(BoundObject.Property.InstanceCall());" +
                                              "Push(BoundClass.StaticCall());" +
                                              "BoundObject.Field = 1;" +
                                              "BoundObject.FieldProperty = BoundObject.Field + 1;")
                .CreateDelegate(typeof(DMCall), this);

            this.FloatList.Clear();

            dm();

            this.AssertList(new float[] { 1, 1, 2 }, "results");

            Assert.AreEqual(1f, this.BoundObject.Field, "BoundObject.Field");
            Assert.AreEqual(2f, this.BoundObject.FieldProperty, "BoundObject.FieldProperty");
        }
Exemplo n.º 2
0
        public static void Run()
        {
            AffeCompiler compiler = new AffeCompiler(typeof(TestInvoke));
            compiler.SymbolTable.AddSymbol(new TypeSymbol("Console", typeof(Console)));
            compiler.SymbolTable.AddSymbol(new TypeSymbol("string", typeof(string)));
            compiler.SymbolTable.AddSymbol(new TypeSymbol("var", typeof(void)));

            DynamicMethod dm = compiler.Compile("var s = \"test\";Console.Out.WriteLine(s.Substring(1));");

            DMCall d = (DMCall) dm.CreateDelegate(typeof(DMCall), null);

            d();
        }
Exemplo n.º 3
0
        public void Declaration()
        {
            this.State.Clear();

            AffeCompiler comp = new AffeCompiler(typeof(Tests));
            comp.SymbolTable.AddSymbol(new TypeSymbol("int", typeof(int)));

            DMCall dm = (DMCall) comp.Compile("a = 2.5; int i = a; BoundFloat = i;")
                .CreateDelegate(typeof(DMCall), this);

            BoundFloat = 0f;

            dm();

            Assert.AreEqual(2f, this.BoundFloat, "Result");
        }
Exemplo n.º 4
0
        public static void Run()
        {
            AffeCompiler compiler = new AffeCompiler(typeof(TestScope));
            compiler.SymbolTable.AddSymbol(new TypeSymbol("var", typeof(void)));

            DynamicMethod dm = compiler.Compile("if(1){var s = \"hi\"; }var s = 1;print(s);");//var s = i;print(s);");

            DMCall d = (DMCall) dm.CreateDelegate(typeof(DMCall), null);

            d();
        }