public void EmitLoad(object value, Type type)
        {
            if (value == null)
            {
                Emit(s_null ??= new LoadObjectInstruction(null));
                return;
            }

            if (type == null || type.IsValueType)
            {
                if (value is bool)
                {
                    EmitLoad((bool)value);
                    return;
                }

                if (value is int)
                {
                    int i = (int)value;
                    if (i >= PushIntMinCachedValue && i <= PushIntMaxCachedValue)
                    {
                        if (s_ints == null)
                        {
                            s_ints = new Instruction[PushIntMaxCachedValue - PushIntMinCachedValue + 1];
                        }

                        i -= PushIntMinCachedValue;
                        Emit(s_ints[i] ?? (s_ints[i] = new LoadObjectInstruction(value)));
                        return;
                    }
                }
            }

            if (_objects == null)
            {
                _objects = new List <object>();
                if (s_loadObjectCached == null)
                {
                    s_loadObjectCached = new Instruction[CachedObjectCount];
                }
            }

            if (_objects.Count < s_loadObjectCached.Length)
            {
                uint index = (uint)_objects.Count;
                _objects.Add(value);
                Emit(s_loadObjectCached[index] ?? (s_loadObjectCached[index] = new LoadCachedObjectInstruction(index)));
            }
            else
            {
                Emit(new LoadObjectInstruction(value));
            }
        }
Beispiel #2
0
 public void EmitLoad(object value, Type type)
 {
     unsafe
     {
         if (value != null)
         {
             if (type == null || type.IsValueType)
             {
                 if (!(value is bool))
                 {
                     if (value is int)
                     {
                         int num = (int)value;
                         if (num >= -100 && num <= 100)
                         {
                             if (InstructionList._ints == null)
                             {
                                 InstructionList._ints = new Instruction[201];
                             }
                             num = num - -100;
                             InstructionList instructionList = this;
                             Instruction     instruction     = InstructionList._ints[num];
                             Instruction     instruction1    = instruction;
                             if (instruction == null)
                             {
                                 LoadObjectInstruction loadObjectInstruction = new LoadObjectInstruction(value);
                                 Instruction           instruction2          = loadObjectInstruction;
                                 InstructionList._ints[num] = loadObjectInstruction;
                                 instruction1 = instruction2;
                             }
                             instructionList.Emit(instruction1);
                             return;
                         }
                     }
                 }
                 else
                 {
                     this.EmitLoad((bool)value);
                     return;
                 }
             }
             if (this._objects == null)
             {
                 this._objects = new List <object>();
                 if (InstructionList._loadObjectCached == null)
                 {
                     InstructionList._loadObjectCached = new Instruction[0x100];
                 }
             }
             if (this._objects.Count >= (int)InstructionList._loadObjectCached.Length)
             {
                 this.Emit(new LoadObjectInstruction(value));
                 return;
             }
             else
             {
                 int count = (int)this._objects.Count;
                 this._objects.Add(value);
                 InstructionList instructionList1 = this;
                 Instruction     instruction3     = InstructionList._loadObjectCached[count];
                 Instruction     instruction4     = instruction3;
                 if (instruction3 == null)
                 {
                     LoadCachedObjectInstruction loadCachedObjectInstruction = new LoadCachedObjectInstruction(count);
                     Instruction instruction5 = loadCachedObjectInstruction;
                     InstructionList._loadObjectCached[count] = loadCachedObjectInstruction;
                     instruction4 = instruction5;
                 }
                 instructionList1.Emit(instruction4);
                 return;
             }
         }
         else
         {
             InstructionList instructionList2 = this;
             Instruction     instruction6     = InstructionList._null;
             Instruction     instruction7     = instruction6;
             if (instruction6 == null)
             {
                 LoadObjectInstruction loadObjectInstruction1 = new LoadObjectInstruction(null);
                 instruction7          = loadObjectInstruction1;
                 InstructionList._null = loadObjectInstruction1;
             }
             instructionList2.Emit(instruction7);
             return;
         }
     }
 }