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

            if (type == null || type.GetTypeInfo().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));
            }
        }
예제 #2
0
        public void EmitLoad(object value, Type type)
        {
            if (value == null)
            {
                Emit(_null ?? (_null = new LoadObjectInstruction(null)));
                return;
            }

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

                if (value is int)
                {
                    var i = (int)value;
                    if (i >= _pushIntMinCachedValue && i <= _pushIntMaxCachedValue)
                    {
                        if (_ints == null)
                        {
                            _ints = new Instruction[_pushIntMaxCachedValue - _pushIntMinCachedValue + 1];
                        }
                        i -= _pushIntMinCachedValue;
                        Emit(_ints[i] ?? (_ints[i] = new LoadObjectInstruction(value)));
                        return;
                    }
                }
            }

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

            if (_objects.Count < _loadObjectCached.Length)
            {
                var index = (uint)_objects.Count;
                _objects.Add(value);
                Emit(_loadObjectCached[index] ?? (_loadObjectCached[index] = new LoadCachedObjectInstruction(index)));
            }
            else
            {
                Emit(new LoadObjectInstruction(value));
            }
        }
예제 #3
0
        public void EmitLoad(object value, Type type)
        {
            if (value == null)
            {
                Emit(_null ?? (_null = new LoadObjectInstruction(null)));
                return;
            }

            if (type?.IsValueType != false)
            {
                switch (value)
                {
                case bool b:
                    EmitLoad(b);
                    return;

                case int i when i >= _pushIntMinCachedValue && i <= _pushIntMaxCachedValue:
                    if (_ints == null)
                    {
                        _ints = new Instruction[_pushIntMaxCachedValue - _pushIntMinCachedValue + 1];
                    }

                    i -= _pushIntMinCachedValue;
                    Emit(_ints[i] ?? (_ints[i] = new LoadObjectInstruction(i)));
                    return;

                default:
                    break;
                }
            }

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

            if (_objects.Count < _loadObjectCached.Length)
            {
                var index = (uint)_objects.Count;
                _objects.Add(value);
                Emit(_loadObjectCached[index] ?? (_loadObjectCached[index] = new LoadCachedObjectInstruction(index)));
            }
            else
            {
                Emit(new LoadObjectInstruction(value));
            }
        }
예제 #4
0
        public void EmitLoad(object value, Type type)
        {
            if (value == null)
            {
                Emit(s_null ?? (s_null = new LoadObjectInstruction(null)));
                return;
            }

            if (type == null || type.GetTypeInfo().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));
            }
        }