public sealed override int Run(InterpretedFrame frame) { int first = frame.StackIndex - _argumentCount; object[] args = GetArgs(frame, first); try { object ret; try { ret = _constructor.Invoke(args); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } frame.Data[first] = ret; frame.StackIndex = first + 1; } finally { if (args != null) { foreach (ByRefUpdater arg in _byrefArgs) { arg.Update(frame, args[arg.ArgumentIndex]); } } } return 1; }
public sealed override int Run(InterpretedFrame frame) { object obj = frame.Pop(); object converted; if (obj == null) { if (_isLiftedToNull) { converted = null; } else { // We cannot have null in a non-lifted numeric context. Throw the exception // about not Nullable object requiring a value. converted = (int)(int?)obj; throw ContractUtils.Unreachable; } } else { converted = Convert(obj); } frame.Push(converted); return +1; }
public override int Run(InterpretedFrame frame) { object value = frame.Pop(); object self = frame.Pop(); _field.SetValue(self, value); return +1; }
public override int Run(InterpretedFrame frame) { object self = frame.Pop(); NullCheck(self); frame.Push(_field.GetValue(self)); return +1; }
public override int Run(InterpretedFrame frame) { if (frame.Peek() == null) { throw new NullReferenceException(); } return +1; }
public void Run(InterpretedFrame frame) { Instruction[] instructions = _instructions.Instructions; int index = frame.InstructionIndex; while (index < instructions.Length) { index += instructions[index].Run(frame); frame.InstructionIndex = index; } }
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; }
public override int Run(InterpretedFrame frame) { var lengths = new int[_rank]; for (int i = _rank - 1; i >= 0; i--) { lengths[i] = ConvertHelper.ToInt32NoNull(frame.Pop()); } var array = Array.CreateInstance(_elementType, lengths); frame.Push(array); return +1; }
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; }
public override int Run(InterpretedFrame frame) { object self = frame.Pop(); if (self == null) { throw new NullReferenceException(); } frame.Push(_field.GetValue(self)); return +1; }
public override int Run(InterpretedFrame frame) { object left = frame.Pop(); object right = frame.Pop(); if (left == null || right == null) { frame.Push(null); return +1; } frame.Push(((long)left) | ((long)right)); return +1; }
public override int Run(InterpretedFrame frame) { var left = frame.Pop(); var right = frame.Pop(); if (left == null || right == null) { frame.Push(null); return +1; } frame.Push((Byte)(((Byte)left) | ((Byte)right))); return +1; }
public override int Run(InterpretedFrame frame) { object left = frame.Pop(); object right = frame.Pop(); if (left == null || right == null) { frame.Push(null); return 1; } frame.Push((byte)((byte)left & (byte)right)); return 1; }
public override int Run(InterpretedFrame frame) { object obj = frame.Pop(); if (obj == null) { frame.Push(null); } else { frame.Push(unchecked(-(float)obj)); } return 1; }
public override int Run(InterpretedFrame frame) { object value = frame.Pop(); if (value == null) { frame.Push(null); } else { frame.Push((short)(~(short)value)); } return 1; }
public override int Run(InterpretedFrame frame) { var value = frame.Pop(); if (value == null) { frame.Push(null); } else { frame.Push((bool)value ? ScriptingRuntimeHelpers.False : ScriptingRuntimeHelpers.True); } return +1; }
public override int Run(InterpretedFrame frame) { object obj = frame.Pop(); if (obj == null) { frame.Push(null); } else { frame.Push(ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)obj - 1))); } return +1; }
public override int Run(InterpretedFrame frame) { object obj = frame.Pop(); if (obj == null) { frame.Push(null); } else { frame.Push(unchecked((UInt16)((UInt16)obj - 1))); } return +1; }
public override int Run(InterpretedFrame frame) { object obj = frame.Pop(); if (obj == null) { frame.Push(null); } else { frame.Push((ushort)(~(ushort)obj)); } return 1; }
public override int Run(InterpretedFrame frame) { object value = frame.Pop(); if (value == null) { frame.Push(null); } else { frame.Push(~(long)value); } return +1; }
public override int Run(InterpretedFrame frame) { object obj = frame.Pop(); if (obj == null) { frame.Push(null); } else { frame.Push(~(long)obj); } return +1; }
public override int Run(InterpretedFrame frame) { object shift = frame.Pop(); object value = frame.Pop(); if (value == null || shift == null) { frame.Push(null); } else { frame.Push((short)((short)value >> (int)shift)); } return 1; }
public override int Run(InterpretedFrame frame) { object right = frame.Pop(); object left = frame.Pop(); if (left == null || right == null) { frame.Push(_nullValue); } else { frame.Push((short)left >= (short)right); } return 1; }
public override int Run(InterpretedFrame frame) { var right = frame.Pop(); var left = frame.Pop(); if (left == null || right == null) { frame.Push(_nullValue); } else { frame.Push(((Char)left) > (Char)right); } return +1; }
public override int Run(InterpretedFrame frame) { var shift = frame.Pop(); var value = frame.Pop(); if (value == null || shift == null) { frame.Push(null); } else { frame.Push(((Int64)value) >> ((int)shift)); } return +1; }
public override int Run(InterpretedFrame frame) { object shift = frame.Pop(); object value = frame.Pop(); if (value == null || shift == null) { frame.Push(null); } else { frame.Push(((long)value) << ((int)shift)); } return +1; }
public override int Run(InterpretedFrame frame) { object right = frame.Pop(); object left = frame.Pop(); if (left == null || right == null) { frame.Push(_nullValue); } else { frame.Push(((char)left) <= (char)right); } return +1; }
public override int Run(InterpretedFrame frame) { object l = frame.Data[frame.StackIndex - 2]; object r = frame.Data[frame.StackIndex - 1]; if (l == null || r == null) { frame.Data[frame.StackIndex - 2] = null; } else { frame.Data[frame.StackIndex - 2] = (UInt16)((UInt16)l / (UInt16)r); } frame.StackIndex--; return 1; }
public override int Run(InterpretedFrame frame) { object l = frame.Data[frame.StackIndex - 2]; object r = frame.Data[frame.StackIndex - 1]; if (l == null || r == null) { frame.Data[frame.StackIndex - 2] = null; } else { frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((int)l - (int)r)); } frame.StackIndex--; return +1; }
public override int Run(InterpretedFrame frame) { object l = frame.Data[frame.StackIndex - 2]; object r = frame.Data[frame.StackIndex - 1]; if (l == null || r == null) { frame.Data[frame.StackIndex - 2] = null; } else { frame.Data[frame.StackIndex - 2] = unchecked((ushort)((ushort)l - (ushort)r)); } frame.StackIndex--; return +1; }
internal void Leave(InterpretedFrame prevFrame) { CurrentFrame = prevFrame; }
protected override void ConvertNull(InterpretedFrame frame) { throw new NullReferenceException(); }
public override int Run(InterpretedFrame frame) { int target; return(_cases.TryGetValue((T)frame.Pop(), out target) ? target : 1); }
public override int Run(InterpretedFrame frame) { object exception = frame.Pop(); throw new RethrowException(); }
public abstract int Run(InterpretedFrame frame);
public sealed override int Run(InterpretedFrame frame) { var first = frame.StackIndex - ArgumentCountProtected; object?[]? args = null; object? instance = null; try { object?ret; if (Target.IsStatic) { args = GetArgs(frame, first, 0); try { ret = Target.Invoke(null, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } else { instance = frame.Data[first]; NullCheck(instance); args = GetArgs(frame, first, 1); if (TryGetLightLambdaTarget(instance, out var targetLambda)) { // no need to Invoke, just interpret the lambda body ret = InterpretLambdaInvoke(targetLambda, args); } else { try { ret = Target.Invoke(instance, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } } if (Target.ReturnType != typeof(void)) { frame.Data[first] = ret; frame.StackIndex = first + 1; } else { frame.StackIndex = first; } } finally { if (args != null) { foreach (var arg in _byrefArgs) { // -1: instance param, just copy back the exact instance invoked with, which // gets passed by reference from reflection for value types. arg.Update(frame, arg.ArgumentIndex == -1 ? instance : args[arg.ArgumentIndex]); } } } return(1); }
public override int Run(InterpretedFrame frame) { frame.Push(ScriptingRuntimeHelpers.BooleanToObject(frame.Pop() == frame.Pop())); return(+1); }
public override int Run(InterpretedFrame frame) { // nop (the exception value is pushed by the interpreter in HandleCatch) return(1); }
public override int Run(InterpretedFrame frame) => 1;
public override int Run(InterpretedFrame frame) { Debug.Assert(_tryHandler != null, "the tryHandler must be set already"); if (_hasFinally) { // Push finally. frame.PushContinuation(_labelIndex); } int prevInstrIndex = frame.InstructionIndex; frame.InstructionIndex++; // Start to run the try/catch/finally blocks Instruction[] instructions = frame.Interpreter.Instructions.Instructions; try { // run the try block int index = frame.InstructionIndex; while (index >= _tryHandler.TryStartIndex && index < _tryHandler.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 == _tryHandler.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(_tryHandler.HasHandler(frame, exception, out ExceptionHandler? exHandler, out object?unwrappedException)) { Debug.Assert(!(unwrappedException is RethrowException)); frame.InstructionIndex += frame.Goto(exHandler.LabelIndex, unwrappedException, gotoExceptionHandler: true); #if FEATURE_THREAD_ABORT // stay in the current catch so that ThreadAbortException is not rethrown by CLR: var abort = exception as ThreadAbortException; if (abort != null) { Interpreter.AnyAbortException = abort; frame.CurrentAbortHandler = exHandler; } #endif bool rethrow = false; try { // run the catch block int 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 == _tryHandler.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 (_tryHandler.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 bool isFromJump = frame.IsJumpHappened(); Debug.Assert(!isFromJump || (isFromJump && _tryHandler.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 int index = frame.InstructionIndex = _tryHandler.FinallyStartIndex; while (index >= _tryHandler.FinallyStartIndex && index < _tryHandler.FinallyEndIndex) { index += instructions[index].Run(frame); frame.InstructionIndex = index; } } } return(frame.InstructionIndex - prevInstrIndex); }
public RuntimeLabel GetLabel(InterpretedFrame frame) { Debug.Assert(_labelIndex != UnknownInstrIndex); return(frame.Interpreter._labels[_labelIndex]); }
public override int Run(InterpretedFrame frame) { Debug.Assert(_offset != Unknown); return(_offset); }
public override int Run(InterpretedFrame frame) { frame.Push(_field.GetValue(null)); return(+1); }
protected override void ConvertNull(InterpretedFrame frame) { frame.Push(null); }
protected abstract void ConvertNull(InterpretedFrame frame);
public override int Run(InterpretedFrame frame) { object from = frame.Pop(); if (from == null) { frame.Push(null); } else { Type underlying = _t.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(_t) : _t; // Order checks in order of likelihood. int first as the vast majority of enums // are int-based, then long as that is sometimes used when required for a large set of flags // and so-on. if (underlying == typeof(int)) { // If from is neither an int nor a type assignable to int (viz. an int-backed enum) // this will cause an InvalidCastException, which is what this operation should // throw in this case. frame.Push(Enum.ToObject(_t, (int)from)); } else if (underlying == typeof(long)) { frame.Push(Enum.ToObject(_t, (long)from)); } else if (underlying == typeof(uint)) { frame.Push(Enum.ToObject(_t, (uint)from)); } else if (underlying == typeof(ulong)) { frame.Push(Enum.ToObject(_t, (ulong)from)); } else if (underlying == typeof(byte)) { frame.Push(Enum.ToObject(_t, (byte)from)); } else if (underlying == typeof(sbyte)) { frame.Push(Enum.ToObject(_t, (sbyte)from)); } else if (underlying == typeof(short)) { frame.Push(Enum.ToObject(_t, (short)from)); } else if (underlying == typeof(ushort)) { frame.Push(Enum.ToObject(_t, (ushort)from)); } else if (underlying == typeof(char)) { // Disallowed in C#, but allowed in CIL frame.Push(Enum.ToObject(_t, (char)from)); } else if (underlying == typeof(bool)) { // Disallowed in C#, but allowed in CIL frame.Push(Enum.ToObject(_t, (bool)from)); } else { throw new InvalidCastException(); } } return(1); }
public override int Run(InterpretedFrame frame) { Debug.Assert(Offset != Unknown); return(frame.Peek() != null ? Offset : 1); }
public override int Run(InterpretedFrame frame) { frame.Data[_index] = new StrongBox <object>(frame.Data[_index]); return(1); }
public override int Run(InterpretedFrame frame) { frame.Push(ScriptingRuntimeHelpers.BooleanToObject(_type.IsInstanceOfType(frame.Pop()))); return(+1); }
public override int Run(InterpretedFrame frame) { frame.Data[_index] = null; return(1); }
public override int Run(InterpretedFrame frame) { frame.Data[frame.StackIndex - 0] = _target(); frame.StackIndex -= -1; return(1); }
internal ExpressionQuoter(Dictionary <ParameterExpression, LocalVariable> hoistedVariables, InterpretedFrame frame) { _variables = hoistedVariables; _frame = frame; }
public override int Run(InterpretedFrame frame) { frame.Data[frame.StackIndex++] = frame.Data[_index]; return(1); }
public override int Run(InterpretedFrame frame) { _target(); frame.StackIndex -= 0; return(1); }
public override int Run(InterpretedFrame frame) { frame.Data[_index] = _defaultValue; return(1); }
public sealed override int Run(InterpretedFrame frame) { int first = frame.StackIndex - _argumentCount; object[] args = null; object instance = null; try { object ret; if (_target.IsStatic) { args = new object[_argumentCount]; for (int i = 0; i < args.Length; i++) { args[i] = frame.Data[first + i]; } try { ret = _target.Invoke(null, args); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } } else { args = new object[_argumentCount - 1]; for (int i = 0; i < args.Length; i++) { args[i] = frame.Data[first + i + 1]; } instance = frame.Data[first]; LightLambda targetLambda; if (TryGetLightLambdaTarget(instance, out targetLambda)) { // no need to Invoke, just interpret the lambda body ret = InterpretLambdaInvoke(targetLambda, args); } else { try { NullCheck(instance); ret = _target.Invoke(instance, args); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } } } if (_target.ReturnType != typeof(void)) { frame.Data[first] = ret; frame.StackIndex = first + 1; } else { frame.StackIndex = first; } } finally { if (args != null) { foreach (var arg in _byrefArgs) { if (arg.ArgumentIndex == -1) { // instance param, just copy back the exact instance invoked with, which // gets passed by reference from reflection for value types. arg.Update(frame, instance); } else { arg.Update(frame, args[arg.ArgumentIndex]); } } } } return(1); }
public override int Run(InterpretedFrame frame) { frame.Push(Activator.CreateInstance(_type)); return(1); }
public override int Run(InterpretedFrame frame) { frame.Push(frame.Pop() == frame.Pop()); return(1); }
public override int Run(InterpretedFrame frame) { frame.Push(_type.IsInstanceOfType(frame.Pop())); return(1); }
public override int Run(InterpretedFrame frame) { return(1); }