Ejemplo n.º 1
0
        public void Load(DarksVMContext ctx, out ExecutionState state)
        {
            uint        sp        = ctx.Registers[DarksVMConstants.REG_SP].U4;
            DarksVMSlot fieldSlot = ctx.Stack[sp--];
            DarksVMSlot objSlot   = ctx.Stack[sp];

            var field = (FieldInfo)ctx.Instance.Data.LookupReference(fieldSlot.U4 & 0x7fffffff);

            if (!field.IsStatic && objSlot.O == null)
            {
                throw new NullReferenceException();
            }

            if (!((fieldSlot.U4 & 0x80000000) != 0))
            {
                object instance = field.DeclaringType.IsValueType && objSlot.O is IReference
                    ? ((IReference)objSlot.O).GetValue(ctx, PointerType.OBJECT).ToObject(field.DeclaringType)
                    : objSlot.ToObject(field.DeclaringType);
                ctx.Stack[sp] = DarksVMSlot.FromObject(field.GetValue(instance), field.FieldType);
            }
            else
            {
                ctx.Stack[sp] = new DarksVMSlot {
                    O = new FieldRef(objSlot.O, field)
                };
            }

            ctx.Stack.SetTopPosition(sp);
            ctx.Registers[DarksVMConstants.REG_SP].U4 = sp;
            state = ExecutionState.Next;
        }
Ejemplo n.º 2
0
        public void Load(DarksVMContext ctx, out ExecutionState state)
        {
            uint        sp       = ctx.Registers[DarksVMConstants.REG_SP].U4;
            DarksVMSlot typeSlot = ctx.Stack[sp--];
            DarksVMSlot valSlot  = ctx.Stack[sp];

            var valType = (Type)ctx.Instance.Data.LookupReference(typeSlot.U4);

            switch (Type.GetTypeCode(valType))
            {
            case TypeCode.String when valSlot.O == null:
                valSlot.O = ctx.Instance.Data.LookupString(valSlot.U4);
                break;

            default:
                Debug.Assert(valType.IsValueType);
                valSlot.O = valSlot.ToObject(valType);
                break;
            }
            ctx.Stack[sp] = valSlot;

            ctx.Stack.SetTopPosition(sp);
            ctx.Registers[DarksVMConstants.REG_SP].U4 = sp;
            state = ExecutionState.Next;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        private static object PopObject(DarksVMContext ctx, Type type, ref uint sp)
        {
            DarksVMSlot arg = ctx.Stack[sp--];

            return(Type.GetTypeCode(type) == TypeCode.String && arg.O == null?ctx.Instance.Data.LookupString(arg.U4) : arg.ToObject(type));
        }