コード例 #1
0
 public DynamicMethod Compile(Block root)
 {
     return new AffeCompilerState(this.mHostType, this.mTable.Copy(),
                                  this.mState).Compile(root);
 }
コード例 #2
0
        internal DynamicMethod Compile(Block root)
        {
            DynamicMethod dm = new DynamicMethod("affeMethod", typeof(void),
                                                 new Type[] { this.mHostType },
                                                 this.mHostType);

            this.il = dm.GetILGenerator();

            root = (Block) root.Analyze(this);

            this.mReturnLabel = this.il.DefineLabel();

            if (this.mState != null) {
                this.mStateLocal = this.il.DeclareLocal(typeof(ScriptState));
                this.il.Emit(OpCodes.Ldarg_0);
                this.il.Emit(OpCodes.Ldfld, this.mState);
                this.il.Emit(OpCodes.Stloc, this.mStateLocal);
            }

            foreach (VariableSymbol vs in this.mAutoVars) {
                if (this.mStateLocal != null) {
                    this.il.Emit(OpCodes.Ldloc, this.mStateLocal);
                    this.il.Emit(OpCodes.Ldstr, vs.Name);
                    this.il.Emit(OpCodes.Call,
                                 mStateGet.MakeGenericMethod(new Type[] { vs.Type }));
                } else {
                    this.il.Emit(OpCodes.Call, mGetDefault.MakeGenericMethod(new Type[] { vs.Type }));
                }

                this.il.Emit(OpCodes.Stloc, vs.Local);
            }

            if (this.mState != null)
                this.il.BeginExceptionBlock();

            root.Emit(this);

            if (this.mState != null) {
                this.il.BeginFinallyBlock();

                foreach (VariableSymbol vs in this.mAutoVars) {
                    this.il.Emit(OpCodes.Ldloc, this.mStateLocal);
                    this.il.Emit(OpCodes.Ldstr, vs.Name);
                    this.il.Emit(OpCodes.Ldloc, vs.Local);

                    if (vs.Local.LocalType.IsValueType)
                        this.il.Emit(OpCodes.Box, vs.Local.LocalType);

                    this.il.Emit(OpCodes.Call, mStateSet);
                }

                this.il.EndExceptionBlock();
            }

            this.il.MarkLabel(this.mReturnLabel);

            this.il.Emit(OpCodes.Ret);

            return dm;
        }
コード例 #3
0
        public override Node Analyze(AffeCompilerState state)
        {
            this.Body = (Block) this.Body.Analyze(state);

            return this;
        }
コード例 #4
0
 public WhileLoop(Expression condition, Block body)
     : base(body)
 {
     this.Condition = condition;
 }
コード例 #5
0
 protected Loop(Block body)
 {
     this.Body = body;
 }
コード例 #6
0
        public override Node Analyze(AffeCompilerState state)
        {
            this.ElseStatements = (Block) this.ElseStatements.Analyze(state);

            return base.Analyze(state);
        }
コード例 #7
0
        public IfElse(Expression condition, Block ifstatements,
		              Block elsestatements)
            : base(condition, ifstatements)
        {
            this.ElseStatements = elsestatements;
        }
コード例 #8
0
        public override Node Analyze(AffeCompilerState state)
        {
            this.Condition = state.CastTo((Expression) this.Condition.Analyze(state),
                                          typeof(bool));

            this.IfStatements = (Block) this.IfStatements.Analyze(state);

            return this;
        }
コード例 #9
0
 public If(Expression condition, Block ifstatements)
 {
     this.Condition = condition;
     this.IfStatements = ifstatements;
 }