public virtual void Execute(MethodContext context, MethodState state, object localInx = null) { if (localInx == null || !((localInx is Int32) || (localInx is Byte))) { throw new OperandsNotSupportedByOperationException(ByteCode.Stloc, localInx); } Local local = context.Locals[(localInx is Int32) ? (Int32)localInx : (Int32)(Byte)localInx]; var slot = new ESSlot() { TypeToken = local.Description.TypeToken, SType = local.Description.SType }; if (local.Description.TypeToken.IsPrimitive) { if (!IsPrimaryType(local.Description.TypeToken.PrimitiveType)) { slot.Val = GetUnaryOperation(local.Description.TypeToken.PrimitiveType, UnaryPrimitiveOpType.GetStackRep)(local.Val); } else { slot.Val = local.Val; } } else { slot.Val = local.Val; } context.EvalStack.Push(slot); }
public void Execute(MethodContext context, MethodState state, object operand = null) { if (context.EvalStack.Count < 1) { throw new InvalidStackSizeException("NotEngine: Evaluation stack should contain an element"); } ESSlot slot = context.EvalStack.Pop(); if (!slot.TypeToken.IsPrimitive) { throw new OperandsNotSupportedByOperationException(ByteCode.Not, slot); } var result = new ESSlot(ESSlotType.Val); if (!IsPrimaryType(slot.TypeToken.PrimitiveType)) { PrimitiveType primitiveType = GetCommonPrimaryType(slot.TypeToken.PrimitiveType, slot.TypeToken.PrimitiveType); //object converted = GetConvertOperation(slot.TypeToken.PrimitiveType, primitiveType)(slot.Val); result.Val = GetUnaryOperation(primitiveType, UnaryPrimitiveOpType.Not)(slot.Val); } else { result.Val = GetUnaryOperation(slot.TypeToken.PrimitiveType, UnaryPrimitiveOpType.Not)(slot.Val); } result.TypeToken = slot.TypeToken; context.EvalStack.Push(result); }
public void Execute(MethodContext context, MethodState state, object operand = null) { if (context.EvalStack.Count < 1) { throw new InvalidStackSizeException("Evaluation stack should contain an element"); } ESSlot refSlot = context.EvalStack.Pop(); if (refSlot.SType != ESSlotType.HORef || ((Int32)refSlot.Val) == GCHeapObj.NullObj.Addr) { throw new InvalidOperationException("Stack contains an invalid data"); } //Get heap object by address GCHeapObj hObj = context.GCHeap.GetObj((Int32)refSlot.Val); var typeObject = context.TypesHeap.GetTypeObject(hObj.TypeToken); if (typeObject == null) { throw new InvalidOperationException("UnboxEngine: Type was not loaded"); } else if (!typeObject.TypeDesc.IsValueType) { throw new InvalidOperationException("Reference type cannot be unboxed"); } ESSlot valSlot = new ESSlot() { SType = ESSlotType.Val, TypeToken = hObj.TypeToken }; if (hObj.TypeToken.IsPrimitive) { valSlot.Val = GetUnaryOperation(hObj.TypeToken.PrimitiveType, UnaryPrimitiveOpType.GetStackRep)(hObj.Val); } else { valSlot.Val = hObj.Val; } context.EvalStack.Push(valSlot); }
public void Execute(MethodContext context, MethodState state, object operand = null) { if (context.EvalStack.Count < 1) { throw new InvalidStackSizeException("Evaluation stack should contain an element to be boxed"); } ESSlot valueSlot = context.EvalStack.Pop(); if (valueSlot.SType != ESSlotType.Val) { throw new InvalidOperationException("Stack contains an invalid data that cannot be boxed"); } //Check if type is loaded if (!context.TypeLoader.TypeIsLoaded(valueSlot.TypeToken)) { throw new InvalidOperationException("Type is not loaded into the domain"); } if (valueSlot.TypeToken.IsPrimitive) { if (!IsPrimaryType(valueSlot.TypeToken.PrimitiveType)) { valueSlot.Val = GetUnaryOperation(valueSlot.TypeToken.PrimitiveType, UnaryPrimitiveOpType.GetStoreRep)(valueSlot.Val); } } TypeObject typeObj = context.TypesHeap.GetTypeObject(valueSlot.TypeToken); GCHeapObj hObj = context.GCHeap.AllocObj(typeObj); hObj.Val = valueSlot.Val; ESSlot refSlot = new ESSlot() { TypeToken = valueSlot.TypeToken, SType = ESSlotType.HORef, Val = hObj.Addr }; context.EvalStack.Push(refSlot); }
public virtual void Execute(MethodContext context, MethodState state, object operand = null) { MtdArg arg = context.Args[(Int32)operand]; ESSlot slot = new ESSlot() { TypeToken = arg.Description.TypeToken, SType = arg.Description.SType }; if (arg.Description.TypeToken.IsPrimitive) { slot.Val = GetUnaryOperation(arg.Description.TypeToken.PrimitiveType, UnaryPrimitiveOpType.GetStackRep)(arg.Val); } else { slot.Val = arg.Val; } context.EvalStack.Push(slot); }
public virtual void Execute(MethodContext context, MethodState state, object operand = null) { if (context.EvalStack.Count < 1) { throw new InvalidStackSizeException("Stack does not contain an element to be stored in locals"); } ESSlot slot = context.EvalStack.Pop(); if (operand == null || !((operand is Int32) || (operand is Byte))) { throw new OperandsNotSupportedByOperationException(ByteCode.Stloc, operand); } Local local = context.Locals[(operand is Int32) ? (Int32)operand : (Int32)(Byte)operand]; if (local.Description.TypeToken.IsPrimitive) { Object val = slot.Val; if (slot.TypeToken.PrimitiveType != local.Description.TypeToken.PrimitiveType) { val = GetConvertOperation(slot.TypeToken.PrimitiveType, local.Description.TypeToken.PrimitiveType)(val); } if (!IsPrimaryType(local.Description.TypeToken.PrimitiveType)) { val = GetUnaryOperation(local.Description.TypeToken.PrimitiveType, UnaryPrimitiveOpType.GetStoreRep)(val); } local.Val = val; } else { if (!context.TypeLoader.FirstIsOfTypeOrDerivedFromSecond(slot.TypeToken, local.Description.TypeToken)) { throw new InvalidLocalsValueException("StLocEngine: Stack element cannot be store in local due to type mismatch"); } local.Val = slot.Val; } }