コード例 #1
0
        public override int Run(InterpretedFrame frame)
        {
            IStrongBox box = frame.Closure[_index];

            frame.Data[frame.StackIndex++] = box.Value;
            return(+1);
        }
コード例 #2
0
            protected internal override Expression VisitRuntimeVariables(RuntimeVariablesExpression node)
            {
                int count = node.Variables.Count;
                List <IStrongBox>          list  = new List <IStrongBox>();
                List <ParameterExpression> list2 = new List <ParameterExpression>();

                int[] numArray = new int[count];
                for (int i = 0; i < count; i++)
                {
                    IStrongBox item = this.GetBox(node.Variables[i]);
                    if (item == null)
                    {
                        numArray[i] = list2.Count;
                        list2.Add(node.Variables[i]);
                    }
                    else
                    {
                        numArray[i] = -1 - list.Count;
                        list.Add(item);
                    }
                }
                if (list.Count == 0)
                {
                    return(node);
                }
                ConstantExpression expression = Expression.Constant(new RuntimeOps.RuntimeVariables(list.ToArray()), typeof(IRuntimeVariables));

                if (list2.Count == 0)
                {
                    return(expression);
                }
                return(Expression.Call(typeof(RuntimeOps).GetMethod("MergeRuntimeVariables"), Expression.RuntimeVariables(new TrueReadOnlyCollection <ParameterExpression>(list2.ToArray())), expression, Expression.Constant(numArray)));
            }
コード例 #3
0
        public override int Run(InterpretedFrame frame)
        {
            IStrongBox box = frame.Closure[_index];

            box.Value = frame.Peek();
            return(+1);
        }
コード例 #4
0
        // this helper prepares arguments for COM binding by transforming ByVal StongBox arguments
        // into ByRef expressions that represent the argument's Value fields.
        internal static bool[] ProcessArgumentsForCom(ref DynamicMetaObject[] args)
        {
            Debug.Assert(args != null);

            DynamicMetaObject[] newArgs = new DynamicMetaObject[args.Length];
            bool[] isByRefArg           = new bool[args.Length];

            for (int i = 0; i < args.Length; i++)
            {
                DynamicMetaObject curArgument = args[i];

                // set new arg infos to their original values or set default ones
                // we will do this fixup early so that we can assume we always have
                // arginfos in COM binder.

                if (IsByRef(curArgument))
                {
                    newArgs[i]    = curArgument;
                    isByRefArg[i] = true;
                }
                else
                {
                    if (IsStrongBoxArg(curArgument))
                    {
                        var restrictions = curArgument.Restrictions.Merge(
                            GetTypeRestrictionForDynamicMetaObject(curArgument)
                            );

                        // we have restricted this argument to LimitType so we can convert and conversion will be trivial cast.
                        Expression boxedValueAccessor = Expression.Field(
                            Helpers.Convert(
                                curArgument.Expression,
                                curArgument.LimitType
                                ),
                            curArgument.LimitType.GetField("Value")
                            );

                        IStrongBox value      = curArgument.Value as IStrongBox;
                        object     boxedValue = value != null ? value.Value : null;

                        newArgs[i] = new DynamicMetaObject(
                            boxedValueAccessor,
                            restrictions,
                            boxedValue
                            );

                        isByRefArg[i] = true;
                    }
                    else
                    {
                        newArgs[i]    = curArgument;
                        isByRefArg[i] = false;
                    }
                }
            }

            args = newArgs;
            return(isByRefArg);
        }
コード例 #5
0
 public override int Run(InterpretedFrame frame)
 {
     IStrongBox[] boxes = new IStrongBox[this._count];
     for (int i = boxes.Length - 1; i >= 0; i--)
     {
         boxes[i] = (IStrongBox) frame.Pop();
     }
     frame.Push(System.Management.Automation.Interpreter.RuntimeVariables.Create(boxes));
     return 1;
 }
コード例 #6
0
 public override int Run(InterpretedFrame frame)
 {
     IStrongBox[] boxes = new IStrongBox[this._count];
     for (int i = boxes.Length - 1; i >= 0; i--)
     {
         boxes[i] = (IStrongBox)frame.Pop();
     }
     frame.Push(System.Management.Automation.Interpreter.RuntimeVariables.Create(boxes));
     return(1);
 }
コード例 #7
0
            protected internal override Expression VisitParameter(ParameterExpression node)
            {
                IStrongBox box = GetBox(node);

                if (box == null)
                {
                    return(node);
                }
                return(Expression.Field(Expression.Constant(box), "Value"));
            }
コード例 #8
0
ファイル: LocalAccess.cs プロジェクト: wpsmith/corefx
        public override int Run(InterpretedFrame frame)
        {
            var ret = new IStrongBox[_count];

            for (int i = ret.Length - 1; i >= 0; i--)
            {
                ret[i] = (IStrongBox)frame.Pop();
            }
            frame.Push(RuntimeVariables.Create(ret));
            return(+1);
        }
コード例 #9
0
 public ManualResetValueTaskSourceLogic(IStrongBox <ManualResetValueTaskSourceLogic <TResult> > parent)
 {
     _parent            = parent ?? throw new ArgumentNullException(nameof(parent));
     _continuation      = null;
     _continuationState = null;
     _capturedContext   = null;
     _executionContext  = null;
     _completed         = false;
     _result            = default;
     _error             = null;
     _version           = 0;
 }
コード例 #10
0
ファイル: InterpretedFrame.cs プロジェクト: dotnet/corefx
        internal InterpretedFrame(Interpreter interpreter, IStrongBox[] closure)
        {
            Interpreter = interpreter;
            StackIndex = interpreter.LocalCount;
            Data = new object[StackIndex + interpreter.Instructions.MaxStackDepth];

            int c = interpreter.Instructions.MaxContinuationDepth;
            if (c > 0)
            {
                _continuations = new int[c];
            }

            Closure = closure;

            _pendingContinuation = -1;
            _pendingValue = Interpreter.NoValue;
        }
コード例 #11
0
ファイル: StrongBoxTests.cs プロジェクト: rsumner31/corefx2
        public static void Value()
        {
            StrongBox <int> sb = new StrongBox <int>();

            Assert.Equal(0, sb.Value);
            sb.Value = 42;
            Assert.Equal(42, sb.Value);

            IStrongBox isb = sb;

            Assert.Equal(42, (int)isb.Value);
            isb.Value = 84;
            Assert.Equal(84, sb.Value);
            Assert.Equal(84, (int)isb.Value);

            Assert.Throws <InvalidCastException>(() => isb.Value = "test");
        }
コード例 #12
0
            protected internal override Expression VisitRuntimeVariables(RuntimeVariablesExpression node)
            {
                int count   = node.Variables.Count;
                var boxes   = new List <IStrongBox>();
                var vars    = new List <ParameterExpression>();
                var indexes = new int[count];

                for (int i = 0; i < count; i++)
                {
                    IStrongBox box = GetBox(node.Variables[i]);
                    if (box == null)
                    {
                        indexes[i] = vars.Count;
                        vars.Add(node.Variables[i]);
                    }
                    else
                    {
                        indexes[i] = -1 - boxes.Count;
                        boxes.Add(box);
                    }
                }

                // No variables were rewritten. Just return the original node
                if (boxes.Count == 0)
                {
                    return(node);
                }

                var boxesConst = Expression.Constant(new RuntimeVariables(boxes.ToArray()), typeof(IRuntimeVariables));

                // All of them were rewritten. Just return the array as a constant
                if (vars.Count == 0)
                {
                    return(boxesConst);
                }

                // Otherwise, we need to return an object that merges them
                return(Expression.Call(
                           typeof(RuntimeOps).GetMethod("MergeRuntimeVariables"),
                           Expression.RuntimeVariables(new TrueReadOnlyCollection <ParameterExpression>(vars.ToArray())),
                           boxesConst,
                           Expression.Constant(indexes)
                           ));
            }
コード例 #13
0
ファイル: TypeOperations.cs プロジェクト: mikem8361/runtime
        public override int Run(InterpretedFrame frame)
        {
            IStrongBox[]? closure;
            if (ConsumedStack > 0)
            {
                closure = new IStrongBox[ConsumedStack];
                for (int i = closure.Length - 1; i >= 0; i--)
                {
                    closure[i] = (IStrongBox?)frame.Pop() !;
                }
            }
            else
            {
                closure = null;
            }

            Delegate d = _creator.CreateDelegate(closure);

            frame.Push(d);
            return(1);
        }
コード例 #14
0
 public override int Run(InterpretedFrame frame)
 {
     IStrongBox box = frame.Closure ![_index];
コード例 #15
0
ファイル: LocalAccess.cs プロジェクト: madpilot/ironruby
 public override int Run(InterpretedFrame frame) {
     var ret = new IStrongBox[_count];
     for (int i = ret.Length - 1; i >= 0; i--) {
         ret[i] = (IStrongBox)frame.Pop();
     }
     frame.Push(RuntimeVariables.Create(ret));
     return +1;
 }
コード例 #16
0
ファイル: RuntimeVariables.cs プロジェクト: nickchal/pash
 internal static IRuntimeVariables Create(IStrongBox[] boxes)
 {
     return new System.Management.Automation.Interpreter.RuntimeVariables(boxes);
 }
コード例 #17
0
 internal RuntimeVariables(IStrongBox[] boxes)
 {
     _boxes = boxes;
 }
コード例 #18
0
ファイル: RuntimeVariables.cs プロジェクト: nlhepler/mono
 internal static IRuntimeVariables Create(IStrongBox[] boxes) {
     return new RuntimeVariables(boxes);
 }
コード例 #19
0
ファイル: RuntimeVariables.cs プロジェクト: nlhepler/mono
 private RuntimeVariables(IStrongBox[] boxes) {
     _boxes = boxes;
 }
コード例 #20
0
 public ManualResetValueTaskSourceLogic(IStrongBox <ManualResetValueTaskSourceLogic <TResult> > parent) : this()
 {
 }
コード例 #21
0
 internal Delegate CreateDelegate(IStrongBox[] closure)
 {
     // we'll create an interpreted LightLambda
     return new LightLambda(this, closure).MakeDelegate(DelegateType);
 }