示例#1
0
            public unsafe void LoadElementPtr(int index, VMStack stack)
            {
                if (Type is DynamicArrayTypeInfo arrayType)
                {
                    int elementSize = arrayType.ElementType.SizeOf();

                    var elemptr = new VMPointer(this);
                    elemptr.MemOffset += (index * elementSize);

                    stack.Push(elemptr);
                }
                else
                {
                    throw new System.InvalidOperationException();
                }
            }
示例#2
0
 public unsafe void LoadElement(int index, VMStack stack)
 {
     if (Type is DynamicArrayTypeInfo arrayType)
     {
         int elementSize = arrayType.ElementType.SizeOf();
         using (var handle = Memory.Pin(index * elementSize))
         {
             for (int i = 0; i < elementSize; i++)
             {
                 stack.Push(handle.Ptr[i]);
             }
         }
     }
     else
     {
         throw new System.InvalidOperationException();
     }
 }
示例#3
0
            public unsafe void StoreField(int index, VMStack stack)
            {
                if (Type is StructTypeInfo structType)
                {
                    if (index < 0 || index >= structType.Fields.Count)
                    {
                        throw new System.ArgumentOutOfRangeException();
                    }

                    var field     = structType.Fields[index];
                    var fieldSize = field.FieldType.SizeOf();
                    using (var handle = Memory.Pin(field.FieldOffset))
                    {
                        for (int i = 0; i < fieldSize; i++)
                        {
                            handle.Ptr[i] = stack.PopUInt8();
                        }
                    }
                }
                else
                {
                    throw new System.InvalidOperationException();
                }
            }