Example #1
0
 public ILLazyPrimitiveOperator(ILCoder coding, ILData operand, SingleOperators singleOperator)
     : base(coding)
 {
     this._isSingle  = true;
     this._right     = operand;
     this._sOperator = singleOperator;
 }
Example #2
0
 internal ILLazyPrimitiveComparer(ILCoder coding, ILData left, Comparisons comparer, ILData right)
     : base(coding)
 {
     this._left     = left;
     this._right    = right;
     this._comparer = comparer;
 }
Example #3
0
 public ILLazyLoadElement(ILCoder coding, ILVariable array, ILData index)
     : base(coding)
 {
     this._array   = array;
     this._index   = -1;
     this._ilIndex = index;
 }
Example #4
0
 public ILLazyPrimitiveOperator(ILCoder coding, ILData left, DoubleOperators doubleOperator, ILData right, Type opResultType)
     : base(coding)
 {
     this._left      = left;
     this._right     = right;
     this._dOperator = doubleOperator;
     this._dOpType   = opResultType;
 }
Example #5
0
        public ILLazyCasting(ILCoder coding, ILData value, CastOperations operations, Type related)
            : base(coding)
        {
            this._op    = operations;
            this._value = value;

            if (operations == CastOperations.Box)
            {
                this._castType = typeof(object);
            }
            else
            {
                this._castType = related;
            }
        }
        private void invokeInstanceBuilder()
        {
            ILVariable      obj           = this._instance;
            ILMethodBuilder methodBuilder = this._methodBuilder;

            Type[]   genericArgs  = this._genericArgs;
            ILData[] invokeParams = this._parameters;

            MethodInfo method = methodBuilder.MethodBuilder;

            if (genericArgs == null || genericArgs.Length == 0)
            {
                if (obj.ILType.IsValueType)
                {
                    ((IILPusher)obj).PushAddress();
                }
                else
                {
                    if (obj.ILType.IsGenericParameter)
                    {
                        ((IILPusher)obj).PushAddress();
                        obj.Coding.Generator.Emit(OpCodes.Constrained, obj.ILType);
                    }
                    else
                    {
                        ((IILPusher)obj).Push();
                    }
                }

                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = methodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameterTypes[i];
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameterType == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                obj.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }

                //if (method.IsVirtual)
                //    obj.Generator.Emit(OpCodes.Callvirt, method);
                //else
                obj.Generator.Emit(OpCodes.Call, method);
            }
            else
            {
                if (obj.ILType.IsValueType)
                {
                    ((IILPusher)obj).PushAddress();
                }
                else
                {
                    if (obj.ILType.IsGenericParameter)
                    {
                        ((IILPusher)obj).PushAddress();
                        obj.Coding.Generator.Emit(OpCodes.Constrained, obj.ILType);
                    }
                    else
                    {
                        ((IILPusher)obj).Push();
                    }
                }

                if (invokeParams != null)
                {
                    Type   typeOfObject   = typeof(object);
                    Type[] parameterTypes = methodBuilder.GetParameterTypes();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam = invokeParams[i];
                        if (parameterTypes[i] == typeOfObject)
                        {
                            ((IILPusher)invokeParam).Push();
                            obj.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                        }
                        else
                        {
                            ((IILPusher)invokeParam).Push();
                        }
                    }
                }
                method = method.MakeGenericMethod(genericArgs);
                //if (method.IsVirtual)
                //    obj.Generator.Emit(OpCodes.Callvirt, method);
                //else
                obj.Generator.Emit(OpCodes.Call, method);
            }
        }
        private void invokeStatic()
        {
            MethodInfo staticMethod = this._method;

            Type[]   genericArgs  = this._genericArgs;
            ILData[] invokeParams = this._parameters;

            if (genericArgs == null || genericArgs.Length == 0)
            {
                if (invokeParams != null)
                {
                    Type            typeOfObject = typeof(object);
                    ParameterInfo[] parameters   = staticMethod.GetParameters();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameters[i].ParameterType;
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameters[i].ParameterType == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                this.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }
                this.Generator.Emit(OpCodes.Call, staticMethod);
            }
            else
            {
                if (invokeParams != null)
                {
                    Type            typeOfObject = typeof(object);
                    ParameterInfo[] parameters   = staticMethod.GetParameters();
                    for (int i = 0; i < invokeParams.Length; i++)
                    {
                        ILData invokeParam   = invokeParams[i];
                        Type   parameterType = parameters[i].ParameterType;
                        if (parameterType.IsByRef)
                        {
                            ((IILPusher)invokeParam).PushAddress();
                        }
                        else
                        {
                            if (parameters[i].ParameterType == typeOfObject)
                            {
                                ((IILPusher)invokeParam).Push();
                                this.Generator.Emit(OpCodes.Box, invokeParam.ILType);
                            }
                            else
                            {
                                ((IILPusher)invokeParam).Push();
                            }
                        }
                    }
                }
                staticMethod = staticMethod.MakeGenericMethod(genericArgs);
                this.Generator.Emit(OpCodes.Call, staticMethod);
            }
        }
Example #8
0
 public ILLazyPrimitiveConverter(ILCoder coding, ILData value, Type to)
     : base(coding)
 {
     this._toType = to;
     this._value  = value;
 }
Example #9
0
        protected override void Push()
        {
            if (this._isSingle)
            {
                ((IILPusher)this._right).Push();
                switch (this._sOperator)
                {
                case SingleOperators.Plus:
                    break;

                case SingleOperators.Not:
                    base.Generator.Emit(OpCodes.Not);
                    break;

                case SingleOperators.Neg:
                    base.Generator.Emit(OpCodes.Neg);
                    break;

                case SingleOperators.Increment:
                    if (this._right.ILType == typeof(double))
                    {
                        base.Generator.Emit(OpCodes.Ldc_R8, 1.0);
                    }
                    else if (this._right.ILType == typeof(float))
                    {
                        base.Generator.Emit(OpCodes.Ldc_R4, 1f);
                    }
                    else if (this._right.ILType == typeof(long) || this._right.ILType == typeof(ulong))
                    {
                        base.Generator.Emit(OpCodes.Ldc_I8, 1L);
                    }
                    else
                    {
                        base.Generator.Emit(OpCodes.Ldc_I4_1);
                    }
                    base.Generator.Emit(OpCodes.Add);
                    break;

                case SingleOperators.Decrement:
                    if (this._right.ILType == typeof(double))
                    {
                        base.Generator.Emit(OpCodes.Ldc_R8, 1.0);
                    }
                    else if (this._right.ILType == typeof(float))
                    {
                        base.Generator.Emit(OpCodes.Ldc_R4, 1f);
                    }
                    else if (this._right.ILType == typeof(long) || this._right.ILType == typeof(ulong))
                    {
                        base.Generator.Emit(OpCodes.Ldc_I8, 1L);
                    }
                    else
                    {
                        base.Generator.Emit(OpCodes.Ldc_I4_1);
                    }
                    base.Generator.Emit(OpCodes.Sub);
                    break;

                default:
                    break;
                }
            }
            else
            {
                ILData left  = this._left;
                ILData right = this._right;

                if (this._left.ILType != this.ILType)
                {
                    left = left.Convert(this.ILType);
                }
                if (this._right.ILType != this.ILType)
                {
                    right = right.Convert(this.ILType);
                }

                ((IILPusher)left).Push();
                ((IILPusher)right).Push();


                switch (this._dOperator)
                {
                case DoubleOperators.Add:
                    base.Generator.Emit(OpCodes.Add);
                    break;

                case DoubleOperators.Sub:
                    base.Generator.Emit(OpCodes.Sub);
                    break;

                case DoubleOperators.Mul:
                    base.Generator.Emit(OpCodes.Mul);
                    break;

                case DoubleOperators.Div:
                    if (this.ILType == typeof(int) || this.ILType == typeof(long))
                    {
                        base.Generator.Emit(OpCodes.Div);
                    }
                    else
                    {
                        base.Generator.Emit(OpCodes.Div_Un);
                    }
                    break;

                case DoubleOperators.Rem:
                    if (this.ILType == typeof(int) || this.ILType == typeof(long))
                    {
                        base.Generator.Emit(OpCodes.Rem);
                    }
                    else
                    {
                        base.Generator.Emit(OpCodes.Rem_Un);
                    }
                    break;

                case DoubleOperators.And:
                    base.Generator.Emit(OpCodes.And);
                    break;

                case DoubleOperators.Or:
                    base.Generator.Emit(OpCodes.Or);
                    break;

                case DoubleOperators.Xor:
                    base.Generator.Emit(OpCodes.Xor);
                    break;

                case DoubleOperators.LShift:
                    base.Generator.Emit(OpCodes.Shl);
                    break;

                case DoubleOperators.RShift:
                    if (this.ILType == typeof(int) || this.ILType == typeof(long))
                    {
                        base.Generator.Emit(OpCodes.Shr);
                    }
                    else
                    {
                        base.Generator.Emit(OpCodes.Shr_Un);
                    }
                    break;

                default:
                    break;
                }
            }
        }