private void ImportReturn() { bool hasReturnValue = _interpreter.EvaluationStack.TryPop(out StackItem stackItem); if (!hasReturnValue) { return; } switch (stackItem.Kind) { case StackValueKind.Int32: _interpreter.SetReturnValue(((Int32StackItem)stackItem).Value); break; case StackValueKind.Int64: _interpreter.SetReturnValue(((Int64StackItem)stackItem).Value); break; case StackValueKind.Unknown: case StackValueKind.NativeInt: case StackValueKind.Float: case StackValueKind.ByRef: case StackValueKind.ObjRef: case StackValueKind.ValueType: default: break; } }
private void ImportReturn() { var returnType = _method.Signature.ReturnType; if (returnType.IsVoid) { return; } StackItem stackItem = PopWithValidation(); TypeFlags category = returnType.Category; switch (category) { case TypeFlags.Boolean: _interpreter.SetReturnValue(stackItem.AsInt32() != 0); break; case TypeFlags.Char: _interpreter.SetReturnValue((char)stackItem.AsInt32()); break; case TypeFlags.SByte: _interpreter.SetReturnValue((sbyte)stackItem.AsInt32()); break; case TypeFlags.Byte: _interpreter.SetReturnValue((byte)stackItem.AsInt32()); break; case TypeFlags.Int16: _interpreter.SetReturnValue((short)stackItem.AsInt32()); break; case TypeFlags.UInt16: _interpreter.SetReturnValue((ushort)stackItem.AsInt32()); break; case TypeFlags.Int32: case TypeFlags.UInt32: _interpreter.SetReturnValue(stackItem.AsInt32()); break; case TypeFlags.Int64: case TypeFlags.UInt64: _interpreter.SetReturnValue(stackItem.AsInt64()); break; case TypeFlags.IntPtr: case TypeFlags.UIntPtr: _interpreter.SetReturnValue(stackItem.AsIntPtr()); break; case TypeFlags.Single: _interpreter.SetReturnValue((float)stackItem.AsDouble()); break; case TypeFlags.Double: _interpreter.SetReturnValue(stackItem.AsDouble()); break; case TypeFlags.ValueType: _interpreter.SetReturnValue(stackItem.AsValueType()); break; case TypeFlags.Interface: case TypeFlags.Class: case TypeFlags.Array: case TypeFlags.SzArray: _interpreter.SetReturnValue(stackItem.AsObjectRef()); break; case TypeFlags.Enum: case TypeFlags.Nullable: case TypeFlags.ByRef: case TypeFlags.Pointer: case TypeFlags.FunctionPointer: case TypeFlags.GenericParameter: default: // TODO: Support more complex return types break; } }