public void Handle(Instruction instruction, CilHandlerContext context) { var type = context.Resolver.Type((TypeReference)instruction.Operand, context.GenericScope); var instance = context.Stack.Pop(); context.Stack.Push(type.IsInstanceOfType(instance) ? instance : null); }
public void Handle(Instruction instruction, CilHandlerContext context) { var array = (Array)ObjectWrapper.UnwrapIfRequired(context.Stack.Pop()); var value = array.GetLength(0); context.Stack.Push(value); }
public void Handle(Instruction instruction, CilHandlerContext context) { var method = context.Resolver.Method((MethodReference)instruction.Operand, context.GenericScope); var parameters = method.GetParameters(); var arguments = new object[parameters.Length]; for (var i = parameters.Length - 1; i >= 0; i--) { arguments[i] = TypeSupport.Convert(context.Stack.Pop(), parameters[i].ParameterType); } if (instruction.OpCode == OpCodes.Newobj) { var instance = context.Invoker.Invoke(method, null, arguments, context.Method); context.Stack.Push(instance); return; } var target = (object)null; if (!method.IsStatic) { target = TypeSupport.Convert(context.Stack.Pop(), method.DeclaringType); } var result = context.Invoker.Invoke(method, target, arguments, context.Method); if (!method.IsConstructor && ((MethodInfo)method).ReturnType != typeof(void)) { context.Stack.Push(result); } }
public void Handle(Instruction instruction, CilHandlerContext context) { var right = context.Stack.Pop(); var left = context.Stack.Pop(); context.Stack.Push(Calculate(instruction, left, right)); }
public void Handle(Instruction instruction, CilHandlerContext context) { var right = context.Stack.Pop(); var left = context.Stack.Pop(); context.Stack.Push(Compare(instruction, left, right) ? 1 : 0); }
private bool IsBinaryConditionTrue(Func <object, object, bool> isTrue, CilHandlerContext context) { var right = context.Stack.Pop(); var left = context.Stack.Pop(); return(isTrue(left, right)); }
private bool IsConditionTrue(Instruction instruction, CilHandlerContext context) { switch (instruction.OpCode.Code) { case Code.Br: case Code.Br_S: return(true); case Code.Brtrue: case Code.Brtrue_S: return(TypeSupport.Convert <bool>(context.Stack.Pop())); case Code.Brfalse: case Code.Brfalse_S: return(!TypeSupport.Convert <bool>(context.Stack.Pop())); case Code.Beq_S: return(IsBinaryConditionTrue(Primitives.Equal, context)); case Code.Bne_Un_S: return(IsBinaryConditionTrue(Primitives.NotEqual, context)); case Code.Blt_S: return(IsBinaryConditionTrue(Primitives.IsLessThan, context)); case Code.Ble_S: return(IsBinaryConditionTrue(Primitives.IsLessThanOrEqual, context)); default: throw new NotImplementedException(); } }
public void Handle(Instruction instruction, CilHandlerContext context) { var length = (int)Primitives.Convert(context.Stack.Pop(), typeof(int)); var arrayType = context.Resolver.Type(new ArrayType((TypeReference)instruction.Operand), context.GenericScope); context.Stack.Push(TypeSupport.CreateArray(arrayType, length)); }
public void Handle(Instruction instruction, CilHandlerContext context) { var index = TypeSupport.Convert <IntPtr>(context.Stack.Pop()); var array = (Array)ObjectWrapper.UnwrapIfRequired(context.Stack.Pop()); var value = array.GetValue(index.ToInt64()); context.Stack.Push(value); }
public void Handle(Instruction instruction, CilHandlerContext context) { int index; if (!SpecialMap.TryGetValue(instruction.OpCode, out index)) { index = (int)instruction.Operand; } context.Stack.Push(GetArgumentValueOrThis(context, index)); }
public void Handle(Instruction instruction, CilHandlerContext context) { var value = context.Stack.Pop(); var index = TypeSupport.Convert <IntPtr>(context.Stack.Pop()); var array = (Array)ObjectWrapper.UnwrapIfRequired(context.Stack.Pop()); array.SetValue( TypeSupport.Convert(value, array.GetType().GetElementType()), index.ToInt64() ); }
public void Handle(Instruction instruction, CilHandlerContext context) { if (!IsConditionTrue(instruction, context)) { return; } var target = (Instruction)instruction.Operand; context.NextInstruction = target; }
public void Handle(Instruction instruction, CilHandlerContext context) { int index; if (!SpecialMap.TryGetValue(instruction.OpCode, out index)) { index = ((VariableDefinition)instruction.Operand).Index; } context.Stack.Push(context.Variables[index]); }
public void Handle(Instruction instruction, CilHandlerContext context) { var type = context.Resolver.Type((TypeReference)instruction.Operand, context.GenericScope); var instance = context.Stack.Pop(); if (!type.IsInstanceOfType(instance)) { throw new InvalidCastException($"Specified cast is not valid (instance: {instance}, type: {type})."); } context.Stack.Push(instance); }
public void Handle(Instruction instruction, CilHandlerContext context) { var special = SpecialMap.GetValueOrDefault(instruction.OpCode); if (special != null) { context.Stack.Push(special); return; } context.Stack.Push(instruction.Operand); }
public void Handle(Instruction instruction, CilHandlerContext context) { var value = context.Stack.Pop(); int index; if (!SpecialMap.TryGetValue(instruction.OpCode, out index)) { index = ((VariableDefinition)instruction.Operand).Index; } context.SetVariable(index, value); }
public void Handle(Instruction instruction, CilHandlerContext context) { var method = context.Resolver.Method((MethodReference)instruction.Operand, context.GenericScope); var interpreted = method as InterpretedMethod; if (interpreted != null) { context.Stack.Push(new NonRuntimeMethodPointer(interpreted)); return; } context.Stack.Push(method.MethodHandle.GetFunctionPointer()); }
private object GetArgumentValueOrThis(CilHandlerContext context, int index) { if (context.Definition.HasThis) { if (index == 0) { return(context.Target); } index -= 1; } return(context.Arguments[index]); }
public void Handle(Instruction instruction, CilHandlerContext context) { var field = context.Resolver.Field((FieldReference)instruction.Operand, context.GenericScope); var target = (object)null; if (instruction.OpCode == OpCodes.Ldfld) { target = TypeSupport.Convert(context.Stack.Pop(), field.DeclaringType); } var value = field.GetValue(target); context.Stack.Push(value); }
public void Handle(Instruction instruction, CilHandlerContext context) { var reference = (MemberReference)instruction.Operand; var typeReference = reference as TypeReference; if (typeReference == null) { throw new NotImplementedException(); } var resolved = context.Resolver.Type(typeReference, context.GenericScope); var nonRuntime = resolved as NonRuntimeType; if (nonRuntime != null) { context.Stack.Push(nonRuntime.TypeHandle); return; } context.Stack.Push(resolved.TypeHandle); }
public void Handle(Instruction instruction, CilHandlerContext context) { var target = (Instruction)instruction.Operand; context.NextInstruction = target; }
public void Handle(Instruction instruction, CilHandlerContext context) { context.Stack.Push(context.Stack.Peek()); }
public void Handle(Instruction instruction, CilHandlerContext context) { context.Stack.Pop(); }
public void Handle(Instruction instruction, CilHandlerContext context) { // nop }
public void Handle(Instruction instruction, CilHandlerContext context) { var converted = Primitives.Convert(context.Stack.Pop(), TypeMap[instruction.OpCode]); context.Stack.Push(converted); }