示例#1
0
        public override int Run(InterpretedFrame frame)
        {
            if (frame.Peek() == null)
            {
                throw new NullReferenceException();
            }

            return +1;
        }
示例#2
0
 public override int Run(InterpretedFrame frame)
 {
     Array array = Array.CreateInstance(_elementType, _elementCount);
     for (int i = _elementCount - 1; i >= 0; i--)
     {
         array.SetValue(frame.Pop(), i);
     }
     frame.Push(array);
     return +1;
 }
示例#3
0
 public override int Run(InterpretedFrame frame)
 {
     int length = ConvertHelper.ToInt32NoNull(frame.Pop());
     if (length < 0)
     {
         // to make behavior aligned with array creation emitted by C# compiler
         throw new OverflowException();
     }
     frame.Push(Array.CreateInstance(_elementType, length));
     return +1;
 }
示例#4
0
        public override int Run(InterpretedFrame frame)
        {
            var functionContext = frame.FunctionContext;
            var context = frame.ExecutionContext;

            functionContext._currentSequencePointIndex = _sequencePoint;
            if (_checkBreakpoints)
            {
                if (context._debuggingMode > 0)
                {
                    context.Debugger.OnSequencePointHit(functionContext);
                }
            }
            return +1;
        }
示例#5
0
        public override int Run(InterpretedFrame frame)
        {
            var lengths = new int[_rank];
            for (int i = _rank - 1; i >= 0; i--)
            {
                int length = ConvertHelper.ToInt32NoNull(frame.Pop());

                if (length < 0)
                {
                    // to make behavior aligned with array creation emitted by C# compiler
                    throw new OverflowException();
                }

                lengths[i] = length;
            }
            Array array = Array.CreateInstance(_elementType, lengths);
            frame.Push(array);
            return +1;
        }
示例#6
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(InterpretedFrame.CurrentFrame.Value);
     return(+1);
 }
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(Converter.ConvertToBoolean(frame.Pop()));
     return(+1);
 }
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(Converter.Convert(frame.Pop(), _type));
     return(+1);
 }
示例#9
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Data[frame.StackIndex++] = frame.Interpreter.Objects[_index];
     return(1);
 }
示例#10
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Data[frame.StackIndex++] = _value;
     return(1);
 }
示例#11
0
 public override int Run(InterpretedFrame frame) {
     frame.Pop();
     return +1;
 }
示例#12
0
 public override int Run(InterpretedFrame frame)
 {
     // it’s okay to pop the args in this order due to commutativity of referential equality
     frame.Push(PythonOps.IsNot(frame.Pop(), frame.Pop()));
     return(+1);
 }
示例#13
0
        private void AddBacktrace(IEnumerable <StackFrame> stackTrace, int skipFrames, bool skipInterpreterRunMethod)
        {
            if (stackTrace != null)
            {
                foreach (var frame in InterpretedFrame.GroupStackFrames(stackTrace))
                {
                    string methodName, file;
                    int    line;

                    if (_interpretedFrames != null && _interpretedFrameIndex < _interpretedFrames.Count &&
                        InterpretedFrame.IsInterpretedFrame(frame.GetMethod()))
                    {
                        if (skipInterpreterRunMethod)
                        {
                            skipInterpreterRunMethod = false;
                            continue;
                        }

                        InterpretedFrameInfo info = _interpretedFrames[_interpretedFrameIndex++];

                        if (info.DebugInfo != null)
                        {
                            file = info.DebugInfo.FileName;
                            line = info.DebugInfo.StartLine;
                        }
                        else
                        {
                            file = null;
                            line = 0;
                        }
                        methodName = info.MethodName;

                        // TODO: We need some more general way to recognize and parse non-Ruby interpreted frames
                        TryParseRubyMethodName(ref methodName, ref file, ref line);

                        if (methodName == InterpretedCallSiteName)
                        {
                            // ignore ruby interpreted call sites
                            continue;
                        }
                    }
                    else if (TryGetStackFrameInfo(frame, out methodName, out file, out line))
                    {
                        // special case: the frame will be added with the next frame's source info:
                        if (line == NextFrameLine)
                        {
                            _nextFrameMethodName = methodName;
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    if (_nextFrameMethodName != null)
                    {
                        if (skipFrames == 0)
                        {
                            _trace.Add(MutableString.Create(FormatFrame(file, line, _nextFrameMethodName), _encoding));
                        }
                        else
                        {
                            skipFrames--;
                        }
                        _nextFrameMethodName = null;
                    }

                    if (skipFrames == 0)
                    {
                        _trace.Add(MutableString.Create(FormatFrame(file, line, methodName), _encoding));
                    }
                    else
                    {
                        skipFrames--;
                    }
                }
            }
        }
示例#14
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(_global.CurrentValueLightThrow);
     return(+1);
 }
示例#15
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(PythonOps.MakeEmptyDict());
     return(+1);
 }
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(PythonOps.GetParentContextFromFunction((PythonFunction)frame.Pop()));
     return(+1);
 }
示例#17
0
 public override int Run(InterpretedFrame frame)
 {
     _global.CurrentValue = frame.Peek();
     return(+1);
 }
示例#18
0
 public override int Run(InterpretedFrame frame)
 {
     object obj = frame.Pop();
     frame.Push(((Array)obj).Length);
     return +1;
 }
示例#19
0
 public override int Run(InterpretedFrame frame)
 {
     object value = frame.Pop();
     int index = ConvertHelper.ToInt32NoNull(frame.Pop());
     Array array = (Array)frame.Pop();
     array.SetValue(value, index);
     return +1;
 }
示例#20
0
 public override int Run(InterpretedFrame frame)
 {
     int index = ConvertHelper.ToInt32NoNull(frame.Pop());
     Array array = (Array)frame.Pop();
     frame.Push(array.GetValue(index));
     return +1;
 }
示例#21
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(PythonOps.GetVariable((CodeContext)frame.Pop(), _name, !_isLocal, _lightThrow));
     return(+1);
 }
示例#22
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(LightExceptions.IsLightException(frame.Pop()));
     return(+1);
 }
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(PythonOps.GetGlobalContext((CodeContext)frame.Pop()));
     return(+1);
 }
示例#24
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(PythonOps.MakeClosureCell());
     return(+1);
 }
示例#25
0
        public override int Run(InterpretedFrame frame)
        {
            if (_hasFinally)
            {
                // Push finally.
                frame.PushContinuation(LabelIndex);
            }

            var prevInstrIndex = frame.InstructionIndex;

            frame.InstructionIndex++;

            // Start to run the try/catch/finally blocks
            var instructions = frame.Interpreter.Instructions.Instructions;

            try
            {
                // run the try block
                var index = frame.InstructionIndex;
                while (index >= Handler !.TryStartIndex && index < Handler.TryEndIndex)
                {
                    index += instructions[index].Run(frame);
                    frame.InstructionIndex = index;
                }

                // we finish the try block and is about to jump out of the try/catch blocks
                if (index == Handler.GotoEndTargetIndex)
                {
                    // run the 'Goto' that jumps out of the try/catch/finally blocks
                    Debug.Assert(instructions[index] is GotoInstruction, "should be the 'Goto' instruction that jumps out the try/catch/finally");
                    frame.InstructionIndex += instructions[index].Run(frame);
                }
            }
            catch (Exception exception) when(Handler !.HasHandler(frame, exception, out var exHandler, out var unwrappedException))
            {
                Debug.Assert(!(unwrappedException is RethrowException));
                frame.InstructionIndex += frame.Goto(exHandler.LabelIndex, unwrappedException, true);
                var rethrow = false;

                try
                {
                    // run the catch block
                    var index = frame.InstructionIndex;
                    while (index >= exHandler.HandlerStartIndex && index < exHandler.HandlerEndIndex)
                    {
                        index += instructions[index].Run(frame);
                        frame.InstructionIndex = index;
                    }

                    // we finish the catch block and is about to jump out of the try/catch blocks
                    if (index == Handler.GotoEndTargetIndex)
                    {
                        // run the 'Goto' that jumps out of the try/catch/finally blocks
                        Debug.Assert(instructions[index] is GotoInstruction, "should be the 'Goto' instruction that jumps out the try/catch/finally");
                        frame.InstructionIndex += instructions[index].Run(frame);
                    }
                }
                catch (RethrowException)
                {
                    // a rethrow instruction in a catch block gets to run
                    rethrow = true;
                }

                if (rethrow)
                {
                    throw;
                }
            }
            finally
            {
                if (Handler !.IsFinallyBlockExist)
                {
                    // We get to the finally block in two paths:
                    //  1. Jump from the try/catch blocks. This includes two sub-routes:
                    //        a. 'Goto' instruction in the middle of try/catch block
                    //        b. try/catch block runs to its end. Then the 'Goto(end)' will be trigger to jump out of the try/catch block
                    //  2. Exception thrown from the try/catch blocks
                    // In the first path, the continuation mechanism works and frame.InstructionIndex will be updated to point to the first instruction of the finally block
                    // In the second path, the continuation mechanism is not involved and frame.InstructionIndex is not updated
#if DEBUG
                    var isFromJump = frame.IsJumpHappened();
                    Debug.Assert(!isFromJump || (isFromJump && Handler.FinallyStartIndex == frame.InstructionIndex), "we should already jump to the first instruction of the finally");
#endif
                    // run the finally block
                    // we cannot jump out of the finally block, and we cannot have an immediate rethrow in it
                    var index = frame.InstructionIndex = Handler.FinallyStartIndex;
                    while (index >= Handler.FinallyStartIndex && index < Handler.FinallyEndIndex)
                    {
                        index += instructions[index].Run(frame);
                        frame.InstructionIndex = index;
                    }
                }
            }

            return(frame.InstructionIndex - prevInstrIndex);
        }
示例#26
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(ScriptingRuntimeHelpers.BooleanToObject(LightExceptions.IsLightException(frame.Pop())));
     return(+1);
 }
示例#27
0
 public override int Run(InterpretedFrame frame)
 {
     return(_cases.TryGetValue((T)frame.Pop() !, out var target) ? target : 1);
 }
示例#28
0
 public override int Run(InterpretedFrame frame)
 {
     frame.Push(Convert(frame.Pop()));
     return +1;
 }
示例#29
0
 public override int Run(InterpretedFrame frame)
 {
     // CLR rethrows ThreadAbortException when leaving catch handler if abort is requested on the current thread.
     return(GetLabel(frame).Index - frame.InstructionIndex);
 }
示例#30
0
 public override int Run(InterpretedFrame frame) {
     frame.Data[frame.StackIndex++] = frame.Peek();
     return +1;
 }
 public override int Run(InterpretedFrame frame)
 {
     NullCheck(frame.Peek());
     return(1);
 }