示例#1
0
        //
        // Emits the right opcode to store to an array
        //
        public void EmitArrayStore(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetSetMethod());
                return;
            }

            var type = ac.Element;

            if (type.Kind == MemberKind.Enum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            switch (type.BuiltinType)
            {
            case BuiltinTypeSpec.Type.Byte:
            case BuiltinTypeSpec.Type.SByte:
            case BuiltinTypeSpec.Type.Bool:
                Emit(OpCodes.Stelem_I1);
                return;

            case BuiltinTypeSpec.Type.Short:
            case BuiltinTypeSpec.Type.UShort:
            case BuiltinTypeSpec.Type.Char:
                Emit(OpCodes.Stelem_I2);
                return;

            case BuiltinTypeSpec.Type.Int:
            case BuiltinTypeSpec.Type.UInt:
                Emit(OpCodes.Stelem_I4);
                return;

            case BuiltinTypeSpec.Type.Long:
            case BuiltinTypeSpec.Type.ULong:
                Emit(OpCodes.Stelem_I8);
                return;

            case BuiltinTypeSpec.Type.Float:
                Emit(OpCodes.Stelem_R4);
                return;

            case BuiltinTypeSpec.Type.Double:
                Emit(OpCodes.Stelem_R8);
                return;
            }

            switch (type.Kind)
            {
            case MemberKind.Struct:
                Emit(OpCodes.Stobj, type);
                break;

            case MemberKind.TypeParameter:
                Emit(OpCodes.Stelem, type);
                break;

            case MemberKind.PointerType:
                Emit(OpCodes.Stelem_I);
                break;

            default:
                Emit(OpCodes.Stelem_Ref);
                break;
            }
        }
        //
        // Emits the right opcode to store to an array
        //
        public void EmitArrayStore(ArrayContainer ac)
        {
            if (ac.Rank > 1)
            {
                if (IsAnonymousStoreyMutateRequired)
                {
                    ac = (ArrayContainer)ac.Mutate(CurrentAnonymousMethod.Storey.Mutator);
                }

                ig.Emit(OpCodes.Call, ac.GetSetMethod());
                return;
            }

            var type = ac.Element;

            if (type.IsEnum)
            {
                type = EnumSpec.GetUnderlyingType(type);
            }

            if (type == TypeManager.byte_type || type == TypeManager.sbyte_type || type == TypeManager.bool_type)
            {
                Emit(OpCodes.Stelem_I1);
            }
            else if (type == TypeManager.short_type || type == TypeManager.ushort_type || type == TypeManager.char_type)
            {
                Emit(OpCodes.Stelem_I2);
            }
            else if (type == TypeManager.int32_type || type == TypeManager.uint32_type)
            {
                Emit(OpCodes.Stelem_I4);
            }
            else if (type == TypeManager.int64_type || type == TypeManager.uint64_type)
            {
                Emit(OpCodes.Stelem_I8);
            }
            else if (type == TypeManager.float_type)
            {
                Emit(OpCodes.Stelem_R4);
            }
            else if (type == TypeManager.double_type)
            {
                Emit(OpCodes.Stelem_R8);
            }
            else if (type == TypeManager.intptr_type)
            {
                Emit(OpCodes.Stobj, type);
            }
            else if (TypeManager.IsStruct(type))
            {
                Emit(OpCodes.Stobj, type);
            }
            else if (type.IsGenericParameter)
            {
                Emit(OpCodes.Stelem, type);
            }
            else if (type.IsPointer)
            {
                Emit(OpCodes.Stelem_I);
            }
            else
            {
                Emit(OpCodes.Stelem_Ref);
            }
        }