Пример #1
0
        internal Func <object[], StrongBox <object>[], InterpretedFrame, int> CreateDelegate()
        {
            Expression body = this.Visit(this._loop);
            ReadOnlyCollectionBuilder <Expression> expressions = new ReadOnlyCollectionBuilder <Expression>();
            ReadOnlyCollectionBuilder <Expression> builder2    = new ReadOnlyCollectionBuilder <Expression>();

            foreach (KeyValuePair <ParameterExpression, LoopVariable> pair in this._loopVariables)
            {
                LocalVariable variable;
                if (!this._outerVariables.TryGetValue(pair.Key, out variable))
                {
                    variable = this._closureVariables[pair.Key];
                }
                Expression right = variable.LoadFromArray(this._frameDataVar, this._frameClosureVar);
                if (variable.InClosureOrBoxed)
                {
                    ParameterExpression boxStorage = pair.Value.BoxStorage;
                    expressions.Add(Expression.Assign(boxStorage, right));
                    this.AddTemp(boxStorage);
                }
                else
                {
                    expressions.Add(Expression.Assign(pair.Key, Utils.Convert(right, pair.Key.Type)));
                    if ((pair.Value.Access & ExpressionAccess.Write) != ExpressionAccess.None)
                    {
                        builder2.Add(Expression.Assign(right, Utils.Box(pair.Key)));
                    }
                    this.AddTemp(pair.Key);
                }
            }
            if (builder2.Count > 0)
            {
                expressions.Add(Expression.TryFinally(body, Expression.Block(builder2)));
            }
            else
            {
                expressions.Add(body);
            }
            expressions.Add(Expression.Label(this._returnLabel, Expression.Constant(this._loopEndInstructionIndex - this._loopStartInstructionIndex)));
            return(Expression.Lambda <Func <object[], StrongBox <object>[], InterpretedFrame, int> >((this._temps != null) ? Expression.Block((IEnumerable <ParameterExpression>) this._temps.ToReadOnlyCollection(), (IEnumerable <Expression>)expressions) : Expression.Block(expressions), new ParameterExpression[] { this._frameDataVar, this._frameClosureVar, this._frameVar }).Compile());
        }
Пример #2
0
        protected override Expression VisitGoto(GotoExpression node)
        {
            BranchLabel label;
            LabelTarget key        = node.Target;
            Expression  expression = this.Visit(node.Value);

            if (!this._labelMapping.TryGetValue(key, out label))
            {
                return(node.Update(key, expression));
            }
            if ((label.TargetIndex >= this._loopStartInstructionIndex) && (label.TargetIndex < this._loopEndInstructionIndex))
            {
                return(node.Update(key, expression));
            }
            return(Expression.Return(this._returnLabel, ((expression != null) && (expression.Type != typeof(void))) ? Expression.Call(this._frameVar, InterpretedFrame.GotoMethod, Expression.Constant(label.LabelIndex), Utils.Box(expression)) : Expression.Call(this._frameVar, InterpretedFrame.VoidGotoMethod, new Expression[] { Expression.Constant(label.LabelIndex) }), node.Type));
        }