Beispiel #1
0
        private void InitializeScriptObjects()
        {
            AffeCompiler compiler = new AffeCompiler(typeof(ScriptHost));

            ScriptingEnvironment.InstallBase(compiler);
            ScriptingEnvironment.InstallMath(compiler);

            this.mScriptHost = new ScriptHost();

            this.mInitScript.Compiler     = compiler;
            this.mInitScript.TargetObject = this.mScriptHost;

            this.mFrameScript.Compiler     = compiler;
            this.mFrameScript.TargetObject = this.mScriptHost;

            this.mBeatScript.Compiler     = compiler;
            this.mBeatScript.TargetObject = this.mScriptHost;

            this.mVertexScript.Compiler     = compiler;
            this.mVertexScript.TargetObject = this.mScriptHost;

            this.mNeedInit    = true;
            this.mStaticDirty = true;

            this.mInitScript.MadeDirty   += this.OnInitMadeDirty;
            this.mFrameScript.MadeDirty  += this.OnOtherMadeDirty;
            this.mVertexScript.MadeDirty += this.OnOtherMadeDirty;

            this.CreatePointDataArray();
        }
 protected virtual void SetupCompiler()
 {
     if (this.mTargetObject != null)
     {
         this.mCompiler = new AffeCompiler(this.mTargetObject.GetType());
     }
     else
     {
         this.mCompiler = null;
     }
 }
        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();
        }
        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();
        }
        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");
        }
        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");
        }
Beispiel #7
0
 public static void InstallBase(AffeCompiler compiler)
 {
     Install(compiler.SymbolTable, mBaseSymbols);
 }
Beispiel #8
0
 public static void InstallMath(AffeCompiler compiler)
 {
     Install(compiler.SymbolTable, mMathSymbols);
 }
 public AffeScript(AffeCompiler compiler, object target)
 {
     this.mCompiler     = compiler;
     this.mTargetObject = target;
 }