예제 #1
0
 internal InstructionArray(int maxStackDepth, int maxContinuationDepth, Instruction[] instructions,
     object[] objects, RuntimeLabel[] labels, List<KeyValuePair<int, object>> debugCookies)
 {
     MaxStackDepth = maxStackDepth;
     MaxContinuationDepth = maxContinuationDepth;
     Instructions = instructions;
     DebugCookies = debugCookies;
     Objects = objects;
     Labels = labels;
 }
        public static Instruction Create(Type type, bool liftedToNull = false)
        {
            Debug.Assert(!type.IsEnum);
            if (liftedToNull)
            {
                switch (TypeHelper.GetTypeCode(TypeHelper.GetNonNullableType(type)))
                {
                    case TypeCode.SByte: return s_liftedToNullSByte ?? (s_liftedToNullSByte = new LessThanSByte(null));
                    case TypeCode.Byte: return s_liftedToNullByte ?? (s_liftedToNullByte = new LessThanByte(null));
                    case TypeCode.Char: return s_liftedToNullChar ?? (s_liftedToNullChar = new LessThanChar(null));
                    case TypeCode.Int16: return s_liftedToNullInt16 ?? (s_liftedToNullInt16 = new LessThanInt16(null));
                    case TypeCode.Int32: return s_liftedToNullInt32 ?? (s_liftedToNullInt32 = new LessThanInt32(null));
                    case TypeCode.Int64: return s_liftedToNullInt64 ?? (s_liftedToNullInt64 = new LessThanInt64(null));
                    case TypeCode.UInt16: return s_liftedToNullUInt16 ?? (s_liftedToNullUInt16 = new LessThanUInt16(null));
                    case TypeCode.UInt32: return s_liftedToNullUInt32 ?? (s_liftedToNullUInt32 = new LessThanUInt32(null));
                    case TypeCode.UInt64: return s_liftedToNullUInt64 ?? (s_liftedToNullUInt64 = new LessThanUInt64(null));
                    case TypeCode.Single: return s_liftedToNullSingle ?? (s_liftedToNullSingle = new LessThanSingle(null));
                    case TypeCode.Double: return s_liftedToNullDouble ?? (s_liftedToNullDouble = new LessThanDouble(null));

                    default:
                        throw Error.ExpressionNotSupportedForType("LessThan", type);
                }
            }
            else
            {
                switch (TypeHelper.GetTypeCode(TypeHelper.GetNonNullableType(type)))
                {
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new LessThanSByte(ScriptingRuntimeHelpers.False));
                    case TypeCode.Byte: return s_byte ?? (s_byte = new LessThanByte(ScriptingRuntimeHelpers.False));
                    case TypeCode.Char: return s_char ?? (s_char = new LessThanChar(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new LessThanInt16(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new LessThanInt32(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new LessThanInt64(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new LessThanUInt16(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new LessThanUInt32(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new LessThanUInt64(ScriptingRuntimeHelpers.False));
                    case TypeCode.Single: return s_single ?? (s_single = new LessThanSingle(ScriptingRuntimeHelpers.False));
                    case TypeCode.Double: return s_double ?? (s_double = new LessThanDouble(ScriptingRuntimeHelpers.False));

                    default:
                        throw Error.ExpressionNotSupportedForType("LessThan", type);
                }
            }
        }
예제 #3
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(type.IsArithmetic());
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.Int16: return s_int16 ?? (s_int16 = new SubOvfInt16());
         case TypeCode.Int32: return s_int32 ?? (s_int32 = new SubOvfInt32());
         case TypeCode.Int64: return s_int64 ?? (s_int64 = new SubOvfInt64());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new SubOvfUInt16());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new SubOvfUInt32());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new SubOvfUInt64());
         default:
             return SubInstruction.Create(type);
     }
 }
예제 #4
0
 public static Instruction Create(Type t)
 {
     switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(t)))
     {
         case TypeCode.Boolean: return _Bool ?? (_Bool = new BoolNot());
         case TypeCode.Int64: return _Int64 ?? (_Int64 = new Int64Not());
         case TypeCode.Int32: return _Int32 ?? (_Int32 = new Int32Not());
         case TypeCode.Int16: return _Int16 ?? (_Int16 = new Int16Not());
         case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new UInt64Not());
         case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new UInt32Not());
         case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new UInt16Not());
         case TypeCode.Byte: return _Byte ?? (_Byte = new ByteNot());
         case TypeCode.SByte: return _SByte ?? (_SByte = new SByteNot());
         default:
             throw new InvalidOperationException("Not for " + t.ToString());
     }
 }
예제 #5
0
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type)))
            {
                case TypeCode.SByte: return s_SByte ?? (s_SByte = new OrSByte());
                case TypeCode.Byte: return s_byte ?? (s_byte = new OrByte());
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new OrInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new OrInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new OrInt64());

                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new OrUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new OrUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new OrUInt64());
                case TypeCode.Boolean: return s_bool ?? (s_bool = new OrBool());

                default:
                    throw Error.ExpressionNotSupportedForType("Or", type);
            }
        }
        public static Instruction Create(Type type, bool liftedToNull = false)
        {
            Debug.Assert(!type.GetTypeInfo().IsEnum);
            if (liftedToNull)
            {
                switch (type.GetNonNullableType().GetTypeCode())
                {
                    case TypeCode.SByte: return s_liftedToNullSByte ?? (s_liftedToNullSByte = new LessThanOrEqualSByte(null));
                    case TypeCode.Byte: return s_liftedToNullByte ?? (s_liftedToNullByte = new LessThanOrEqualByte(null));
                    case TypeCode.Char: return s_liftedToNullChar ?? (s_liftedToNullChar = new LessThanOrEqualChar(null));
                    case TypeCode.Int16: return s_liftedToNullInt16 ?? (s_liftedToNullInt16 = new LessThanOrEqualInt16(null));
                    case TypeCode.Int32: return s_liftedToNullInt32 ?? (s_liftedToNullInt32 = new LessThanOrEqualInt32(null));
                    case TypeCode.Int64: return s_liftedToNullInt64 ?? (s_liftedToNullInt64 = new LessThanOrEqualInt64(null));
                    case TypeCode.UInt16: return s_liftedToNullUInt16 ?? (s_liftedToNullUInt16 = new LessThanOrEqualUInt16(null));
                    case TypeCode.UInt32: return s_liftedToNullUInt32 ?? (s_liftedToNullUInt32 = new LessThanOrEqualUInt32(null));
                    case TypeCode.UInt64: return s_liftedToNullUInt64 ?? (s_liftedToNullUInt64 = new LessThanOrEqualUInt64(null));
                    case TypeCode.Single: return s_liftedToNullSingle ?? (s_liftedToNullSingle = new LessThanOrEqualSingle(null));
                    case TypeCode.Double: return s_liftedToNullDouble ?? (s_liftedToNullDouble = new LessThanOrEqualDouble(null));

                    default:
                        throw Error.ExpressionNotSupportedForType("LessThanOrEqual", type);
                }
            }
            else
            {
                switch (type.GetNonNullableType().GetTypeCode())
                {
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new LessThanOrEqualSByte(Utils.BoxedFalse));
                    case TypeCode.Byte: return s_byte ?? (s_byte = new LessThanOrEqualByte(Utils.BoxedFalse));
                    case TypeCode.Char: return s_char ?? (s_char = new LessThanOrEqualChar(Utils.BoxedFalse));
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new LessThanOrEqualInt16(Utils.BoxedFalse));
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new LessThanOrEqualInt32(Utils.BoxedFalse));
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new LessThanOrEqualInt64(Utils.BoxedFalse));
                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new LessThanOrEqualUInt16(Utils.BoxedFalse));
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new LessThanOrEqualUInt32(Utils.BoxedFalse));
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new LessThanOrEqualUInt64(Utils.BoxedFalse));
                    case TypeCode.Single: return s_single ?? (s_single = new LessThanOrEqualSingle(Utils.BoxedFalse));
                    case TypeCode.Double: return s_double ?? (s_double = new LessThanOrEqualDouble(Utils.BoxedFalse));

                    default:
                        throw Error.ExpressionNotSupportedForType("LessThanOrEqual", type);
                }
            }
        }
예제 #7
0
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType();

            switch (underlyingType.GetTypeCode())
            {
                case TypeCode.SByte: return s_SByte ?? (s_SByte = new AndSByte());
                case TypeCode.Int16: return s_Int16 ?? (s_Int16 = new AndInt16());
                case TypeCode.Int32: return s_Int32 ?? (s_Int32 = new AndInt32());
                case TypeCode.Int64: return s_Int64 ?? (s_Int64 = new AndInt64());
                case TypeCode.Byte: return s_Byte ?? (s_Byte = new AndByte());
                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new AndUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new AndUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new AndUInt64());
                case TypeCode.Boolean: return s_Boolean ?? (s_Boolean = new AndBoolean());
                default:
                    throw Error.ExpressionNotSupportedForType("And", type);
            }
        }
예제 #8
0
        public static Instruction Create(Type type)
        {
            Debug.Assert(!type.IsEnum);
            switch (TypeHelper.GetTypeCode(TypeHelper.GetNonNullableType(type)))
            {
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new MulOvfInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new MulOvfInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new MulOvfInt64());
                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new MulOvfUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new MulOvfUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new MulOvfUInt64());
                case TypeCode.Single: return s_single ?? (s_single = new MulOvfSingle());
                case TypeCode.Double: return s_double ?? (s_double = new MulOvfDouble());

                default:
                    throw Error.ExpressionNotSupportedForType("MulOvf", type);
            }
        }
        public static Instruction Create(Type type)
        {
            Debug.Assert(!type.GetTypeInfo().IsEnum);
            switch (TypeUtils.GetNonNullableType(type).GetTypeCode())
            {
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new IncrementInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new IncrementInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new IncrementInt64());
                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new IncrementUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new IncrementUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new IncrementUInt64());
                case TypeCode.Single: return s_single ?? (s_single = new IncrementSingle());
                case TypeCode.Double: return s_double ?? (s_double = new IncrementDouble());

                default:
                    throw Error.ExpressionNotSupportedForType("Increment", type);
            }
        }
예제 #10
0
        public static Instruction Create(Type type, bool liftedToNull)
        {
            // Boxed enums can be unboxed as their underlying types:
            Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType();

            if (liftedToNull)
            {
                switch (underlyingType.GetTypeCode())
                {
                    case TypeCode.Boolean: return s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new EqualBooleanLiftedToNull());
                    case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new EqualSByteLiftedToNull());
                    case TypeCode.Byte: return s_byteLiftedToNull ?? (s_byteLiftedToNull = new EqualByteLiftedToNull());
                    case TypeCode.Char: return s_charLiftedToNull ?? (s_charLiftedToNull = new EqualCharLiftedToNull());
                    case TypeCode.Int16: return s_int16LiftedToNull ?? (s_int16LiftedToNull = new EqualInt16LiftedToNull());
                    case TypeCode.Int32: return s_int32LiftedToNull ?? (s_int32LiftedToNull = new EqualInt32LiftedToNull());
                    case TypeCode.Int64: return s_int64LiftedToNull ?? (s_int64LiftedToNull = new EqualInt64LiftedToNull());

                    case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new EqualUInt16LiftedToNull());
                    case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new EqualUInt32LiftedToNull());
                    case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new EqualUInt64LiftedToNull());

                    case TypeCode.Single: return s_singleLiftedToNull ?? (s_singleLiftedToNull = new EqualSingleLiftedToNull());
                    default:
                        Debug.Assert(underlyingType.GetTypeCode() == TypeCode.Double);
                        return s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new EqualDoubleLiftedToNull());
                }
            }
            else
            {
                switch (underlyingType.GetTypeCode())
                {
                    case TypeCode.Boolean: return s_boolean ?? (s_boolean = new EqualBoolean());
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new EqualSByte());
                    case TypeCode.Byte: return s_byte ?? (s_byte = new EqualByte());
                    case TypeCode.Char: return s_char ?? (s_char = new EqualChar());
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new EqualInt16());
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new EqualInt32());
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new EqualInt64());

                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new EqualUInt16());
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new EqualUInt32());
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new EqualUInt64());

                    case TypeCode.Single: return s_single ?? (s_single = new EqualSingle());
                    case TypeCode.Double: return s_double ?? (s_double = new EqualDouble());

                    default:
                        // Nullable only valid if one operand is constant null, so this assert is slightly too broad.
                        Debug.Assert(type.IsNullableOrReferenceType());
                        return s_reference ?? (s_reference = new EqualReference());

                }
            }
        }
예제 #11
0
        public static Instruction Create(Type type)
        {
            Debug.Assert(TypeUtils.IsArithmetic(type));
            switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
            {
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new AddOvfInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new AddOvfInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new AddOvfInt64());
                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new AddOvfUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new AddOvfUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new AddOvfUInt64());

                default:
                    return AddInstruction.Create(type);
            }
        }
예제 #12
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(TypeUtils.IsArithmetic(type));
     switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
     {
         case TypeCode.Int16: return s_int16 ?? (s_int16 = new AddInt16());
         case TypeCode.Int32: return s_int32 ?? (s_int32 = new AddInt32());
         case TypeCode.Int64: return s_int64 ?? (s_int64 = new AddInt64());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new AddUInt16());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new AddUInt32());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new AddUInt64());
         case TypeCode.Single: return s_single ?? (s_single = new AddSingle());
         case TypeCode.Double: return s_double ?? (s_double = new AddDouble());
         default:
             throw ContractUtils.Unreachable;
     }
 }
        public static Instruction Create(Type type)
        {
            switch (TypeUtils.GetNonNullableType(type).GetTypeCode())
            {
                case TypeCode.Boolean: return _Bool ?? (_Bool = new BoolNot());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new Int64Not());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new Int32Not());
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new Int16Not());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new UInt64Not());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new UInt32Not());
                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new UInt16Not());
                case TypeCode.Byte: return _Byte ?? (_Byte = new ByteNot());
                case TypeCode.SByte: return _SByte ?? (_SByte = new SByteNot());

                default:
                    throw Error.ExpressionNotSupportedForType("Not", type);
            }
        }
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type);

            switch (underlyingType.GetTypeCode())
            {
                case TypeCode.SByte: return s_SByte ?? (s_SByte = new LeftShiftSByte());
                case TypeCode.Byte: return s_byte ?? (s_byte = new LeftShiftByte());
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new LeftShiftInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new LeftShiftInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new LeftShiftInt64());

                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new LeftShiftUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new LeftShiftUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new LeftShiftUInt64());

                default:
                    throw Error.ExpressionNotSupportedForType("LeftShift", type);
            }
        }
예제 #15
0
 public static Instruction Create(Type type)
 {
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.Boolean: return s_Boolean ?? (s_Boolean = new NotBoolean());
         case TypeCode.Int64: return s_Int64 ?? (s_Int64 = new NotInt64());
         case TypeCode.Int32: return s_Int32 ?? (s_Int32 = new NotInt32());
         case TypeCode.Int16: return s_Int16 ?? (s_Int16 = new NotInt16());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new NotUInt64());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new NotUInt32());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new NotUInt16());
         case TypeCode.Byte: return s_Byte ?? (s_Byte = new NotByte());
         case TypeCode.SByte: return s_SByte ?? (s_SByte = new NotSByte());
         default:
             throw Error.ExpressionNotSupportedForType("Not", type);
     }
 }
예제 #16
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(!type.GetTypeInfo().IsEnum);
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.Int16: return s_int16 ?? (s_int16 = new NegateCheckedInt16());
         case TypeCode.Int32: return s_int32 ?? (s_int32 = new NegateCheckedInt32());
         case TypeCode.Int64: return s_int64 ?? (s_int64 = new NegateCheckedInt64());
         case TypeCode.Single: return s_single ?? (s_single = new NegateCheckedSingle());
         case TypeCode.Double: return s_double ?? (s_double = new NegateCheckedDouble());
         default:
             throw Error.ExpressionNotSupportedForType("NegateChecked", type);
     }
 }
예제 #17
0
 public InstructionView(Instruction instruction, string name, int index, int stackDepth, int continuationsDepth)
 {
     _instruction = instruction;
     _name = name;
     _index = index;
     _stackDepth = stackDepth;
     _continuationsDepth = continuationsDepth;
 }
예제 #18
0
        public static Instruction Create(Type type, bool liftedToNull = false)
        {
            Debug.Assert(!type.GetTypeInfo().IsEnum);
            if (liftedToNull)
            {
                switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
                {
                    case TypeCode.SByte: return s_liftedToNullSByte ?? (s_liftedToNullSByte = new GreaterThanOrEqualSByte(null));
                    case TypeCode.Byte: return s_liftedToNullByte ?? (s_liftedToNullByte = new GreaterThanOrEqualByte(null));
                    case TypeCode.Char: return s_liftedToNullChar ?? (s_liftedToNullChar = new GreaterThanOrEqualChar(null));
                    case TypeCode.Int16: return s_liftedToNullInt16 ?? (s_liftedToNullInt16 = new GreaterThanOrEqualInt16(null));
                    case TypeCode.Int32: return s_liftedToNullInt32 ?? (s_liftedToNullInt32 = new GreaterThanOrEqualInt32(null));
                    case TypeCode.Int64: return s_liftedToNullInt64 ?? (s_liftedToNullInt64 = new GreaterThanOrEqualInt64(null));
                    case TypeCode.UInt16: return s_liftedToNullUInt16 ?? (s_liftedToNullUInt16 = new GreaterThanOrEqualUInt16(null));
                    case TypeCode.UInt32: return s_liftedToNullUInt32 ?? (s_liftedToNullUInt32 = new GreaterThanOrEqualUInt32(null));
                    case TypeCode.UInt64: return s_liftedToNullUInt64 ?? (s_liftedToNullUInt64 = new GreaterThanOrEqualUInt64(null));
                    case TypeCode.Single: return s_liftedToNullSingle ?? (s_liftedToNullSingle = new GreaterThanOrEqualSingle(null));
                    case TypeCode.Double: return s_liftedToNullDouble ?? (s_liftedToNullDouble = new GreaterThanOrEqualDouble(null));

                    default:
                        throw Error.ExpressionNotSupportedForType("GreaterThanOrEqual", type);
                }
            }
            else
            {
                switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
                {
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new GreaterThanOrEqualSByte(ScriptingRuntimeHelpers.False));
                    case TypeCode.Byte: return s_byte ?? (s_byte = new GreaterThanOrEqualByte(ScriptingRuntimeHelpers.False));
                    case TypeCode.Char: return s_char ?? (s_char = new GreaterThanOrEqualChar(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new GreaterThanOrEqualInt16(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new GreaterThanOrEqualInt32(ScriptingRuntimeHelpers.False));
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new GreaterThanOrEqualInt64(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new GreaterThanOrEqualUInt16(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new GreaterThanOrEqualUInt32(ScriptingRuntimeHelpers.False));
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new GreaterThanOrEqualUInt64(ScriptingRuntimeHelpers.False));
                    case TypeCode.Single: return s_single ?? (s_single = new GreaterThanOrEqualSingle(ScriptingRuntimeHelpers.False));
                    case TypeCode.Double: return s_double ?? (s_double = new GreaterThanOrEqualDouble(ScriptingRuntimeHelpers.False));

                    default:
                        throw Error.ExpressionNotSupportedForType("GreaterThanOrEqual", type);
                }
            }
        }
예제 #19
0
 public void Emit(Instruction instruction)
 {
     _instructions.Add(instruction);
     UpdateStackDepth(instruction);
 }
예제 #20
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(!type.GetTypeInfo().IsEnum);
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.SByte: return s_SByte ?? (s_SByte = new OnesComplementSByte());
         case TypeCode.Int16: return s_Int16 ?? (s_Int16 = new OnesComplementInt16());
         case TypeCode.Int32: return s_Int32 ?? (s_Int32 = new OnesComplementInt32());
         case TypeCode.Int64: return s_Int64 ?? (s_Int64 = new OnesComplementInt64());
         case TypeCode.Byte: return s_Byte ?? (s_Byte = new OnesComplementByte());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new OnesComplementUInt16());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new OnesComplementUInt32());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new OnesComplementUInt64());
         default:
             throw Error.ExpressionNotSupportedForType("OnesComplement", type);
     }
 }
예제 #21
0
        private void UpdateStackDepth(Instruction instruction)
        {
            Debug.Assert(instruction.ConsumedStack >= 0 && instruction.ProducedStack >= 0 &&
                instruction.ConsumedContinuations >= 0 && instruction.ProducedContinuations >= 0, "bad instruction " + instruction.ToString());

            _currentStackDepth -= instruction.ConsumedStack;
            Debug.Assert(_currentStackDepth >= 0, "negative stack depth " + instruction.ToString());
            _currentStackDepth += instruction.ProducedStack;
            if (_currentStackDepth > _maxStackDepth)
            {
                _maxStackDepth = _currentStackDepth;
            }

            _currentContinuationsDepth -= instruction.ConsumedContinuations;
            Debug.Assert(_currentContinuationsDepth >= 0, "negative continuations " + instruction.ToString());
            _currentContinuationsDepth += instruction.ProducedContinuations;
            if (_currentContinuationsDepth > _maxContinuationDepth)
            {
                _maxContinuationDepth = _currentContinuationsDepth;
            }
        }
예제 #22
0
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch (GetTypeCode(type))
            {
                case TypeCode.SByte: return s_SByte ?? (s_SByte = new ExclusiveOrSByte());
                case TypeCode.Byte: return s_byte ?? (s_byte = new ExclusiveOrByte());
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new ExclusiveOrInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new ExclusiveOrInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new ExclusiveOrInt64());

                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new ExclusiveOrUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new ExclusiveOrUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new ExclusiveOrUInt64());
                case TypeCode.Boolean: return s_bool ?? (s_bool = new ExclusiveOrBool());

                default:
                    throw Error.ExpressionNotSupportedForType("ExclusiveOr", type);
            }
        }
예제 #23
0
 public void EmitLoad(bool value)
 {
     if ((bool)value)
     {
         Emit(s_true ?? (s_true = new LoadObjectInstruction(value)));
     }
     else
     {
         Emit(s_false ?? (s_false = new LoadObjectInstruction(value)));
     }
 }
예제 #24
0
        public static Instruction Create(Type type)
        {
            Debug.Assert(!type.GetTypeInfo().IsEnum);
            switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(TypeUtils.GetNonNullableType(type)))
            {
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new SubOvfInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new SubOvfInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new SubOvfInt64());
                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new SubOvfUInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new SubOvfUInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new SubOvfUInt64());
                case TypeCode.Single: return s_single ?? (s_single = new SubOvfSingle());
                case TypeCode.Double: return s_double ?? (s_double = new SubOvfDouble());

                default:
                    throw Error.ExpressionNotSupportedForType("SubOvf", type);
            }
        }
예제 #25
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));
            }
        }
예제 #26
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(type.IsArithmetic());
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.Int16: return s_int16 ?? (s_int16 = new SubInt16());
         case TypeCode.Int32: return s_int32 ?? (s_int32 = new SubInt32());
         case TypeCode.Int64: return s_int64 ?? (s_int64 = new SubInt64());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new SubUInt16());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new SubUInt32());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new SubUInt64());
         case TypeCode.Single: return s_single ?? (s_single = new SubSingle());
         case TypeCode.Double: return s_double ?? (s_double = new SubDouble());
         default:
             throw ContractUtils.Unreachable;
     }
 }
예제 #27
0
 public static Instruction Create(Type type)
 {
     Debug.Assert(!type.GetTypeInfo().IsEnum);
     switch (type.GetNonNullableType().GetTypeCode())
     {
         case TypeCode.Int16: return s_Int16 ?? (s_Int16 = new DivInt16());
         case TypeCode.Int32: return s_Int32 ?? (s_Int32 = new DivInt32());
         case TypeCode.Int64: return s_Int64 ?? (s_Int64 = new DivInt64());
         case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new DivUInt16());
         case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new DivUInt32());
         case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new DivUInt64());
         case TypeCode.Single: return s_Single ?? (s_Single = new DivSingle());
         case TypeCode.Double: return s_Double ?? (s_Double = new DivDouble());
         default:
             throw Error.ExpressionNotSupportedForType("Div", type);
     }
 }
예제 #28
0
        public static Instruction Create(Type type, bool liftedToNull)
        {
            if (liftedToNull)
            {
                // Boxed enums can be unboxed as their underlying types:
                switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type)))
                {
                    case TypeCode.Boolean: return s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new NotEqualBooleanLiftedToNull());
                    case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull());
                    case TypeCode.Byte: return s_byteLiftedToNull ?? (s_byteLiftedToNull = new NotEqualByteLiftedToNull());
                    case TypeCode.Char: return s_charLiftedToNull ?? (s_charLiftedToNull = new NotEqualCharLiftedToNull());
                    case TypeCode.Int16: return s_int16LiftedToNull ?? (s_int16LiftedToNull = new NotEqualInt16LiftedToNull());
                    case TypeCode.Int32: return s_int32LiftedToNull ?? (s_int32LiftedToNull = new NotEqualInt32LiftedToNull());
                    case TypeCode.Int64: return s_int64LiftedToNull ?? (s_int64LiftedToNull = new NotEqualInt64LiftedToNull());

                    case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull());
                    case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull());
                    case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull());

                    case TypeCode.Single: return s_singleLiftedToNull ?? (s_singleLiftedToNull = new NotEqualSingleLiftedToNull());
                    case TypeCode.Double: return s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new NotEqualDoubleLiftedToNull());

                    case TypeCode.String:
                    case TypeCode.Object:
                        if (!type.GetTypeInfo().IsValueType)
                        {
                            return s_referenceLiftedToNull ?? (s_referenceLiftedToNull = new NotEqualReferenceLiftedToNull());
                        }
                        // TODO: Nullable<T>
                        throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);
                    default:
                        throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
            else
            {
                // Boxed enums can be unboxed as their underlying types:
                switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type)))
                {
                    case TypeCode.Boolean: return s_boolean ?? (s_boolean = new NotEqualBoolean());
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new NotEqualSByte());
                    case TypeCode.Byte: return s_byte ?? (s_byte = new NotEqualByte());
                    case TypeCode.Char: return s_char ?? (s_char = new NotEqualChar());
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new NotEqualInt16());
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new NotEqualInt32());
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new NotEqualInt64());

                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new NotEqualUInt16());
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new NotEqualUInt32());
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new NotEqualUInt64());

                    case TypeCode.Single: return s_single ?? (s_single = new NotEqualSingle());
                    case TypeCode.Double: return s_double ?? (s_double = new NotEqualDouble());

                    case TypeCode.String:
                    case TypeCode.Object:
                        if (!type.GetTypeInfo().IsValueType)
                        {
                            return s_reference ?? (s_reference = new NotEqualReference());
                        }
                        // TODO: Nullable<T>
                        throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);
                    default:
                        throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
        }
예제 #29
0
 public void Emit(Instruction instruction)
 {
     _instructions.Add(instruction);
     UpdateStackDepth(instruction);
 }