public unsafe void Load(DarksVMContext ctx, out ExecutionState state) { uint sp = ctx.Registers[DarksVMConstants.REG_SP].U4; DarksVMSlot fieldSlot = ctx.Stack[sp--]; DarksVMSlot valSlot = ctx.Stack[sp--]; DarksVMSlot objSlot = ctx.Stack[sp--]; var field = (FieldInfo)ctx.Instance.Data.LookupReference(fieldSlot.U4); if (!field.IsStatic && objSlot.O == null) { throw new NullReferenceException(); } object value = Type.GetTypeCode(field.FieldType) == TypeCode.String && valSlot.O == null ? ctx.Instance.Data.LookupString(valSlot.U4) : valSlot.ToObject(field.FieldType); if (field.DeclaringType.IsValueType && objSlot.O is IReference) { TypedReference typedRef; ((IReference)objSlot.O).ToTypedReference(ctx, &typedRef, field.DeclaringType); TypedReferenceHelpers.CastTypedRef(&typedRef, field.DeclaringType); field.SetValueDirect(typedRef, value); } else { field.SetValue(objSlot.ToObject(field.DeclaringType), value); } ctx.Stack.SetTopPosition(sp); ctx.Registers[DarksVMConstants.REG_SP].U4 = sp; state = ExecutionState.Next; }
public void ToTypedReference(uint pos, TypedRefPtr typedRef, Type type) { if(pos > topPos) throw new ExecutionEngineException(); var section = sections[(int) (pos >> SectionSize)]; var index = pos & IndexMask; if(type.IsEnum) type = Enum.GetUnderlyingType(type); if(type.IsPrimitive || type.IsPointer) { section[index].ToTypedReferencePrimitive(typedRef); TypedReferenceHelpers.CastTypedRef(typedRef, type); } else { section[index].ToTypedReferenceObject(typedRef, type); } }