示例#1
0
        public static void EmitLoadLocal(FleeILGenerator ilg, int index)
        {
            Debug.Assert(index >= 0, "Invalid index");

            if (index >= 0 & index <= 3)
            {
                switch (index)
                {
                case 0:
                    ilg.Emit(OpCodes.Ldloc_0);
                    break;

                case 1:
                    ilg.Emit(OpCodes.Ldloc_1);
                    break;

                case 2:
                    ilg.Emit(OpCodes.Ldloc_2);
                    break;

                case 3:
                    ilg.Emit(OpCodes.Ldloc_3);
                    break;
                }
            }
            else
            {
                Debug.Assert(index < 256, "local index too large");
                ilg.Emit(OpCodes.Ldloc_S, Convert.ToByte(index));
            }
        }
示例#2
0
文件: Utility.cs 项目: Nucs/Regen
        public static void EmitLoadLocalAddress(FleeILGenerator ilg, int index) {
            Debug.Assert(index >= 0, "Invalid index");

            if (index <= byte.MaxValue) {
                ilg.Emit(OpCodes.Ldloca_S, Convert.ToByte(index));
            } else {
                ilg.Emit(OpCodes.Ldloca, index);
            }
        }
示例#3
0
 private static void EmitConvert(FleeILGenerator ilg, OpCode convertOpcode)
 {
     if ((ilg != null))
     {
         ilg.Emit(convertOpcode);
     }
 }
示例#4
0
        private static bool ImplicitConvertToReferenceType(Type sourceType, Type destType, FleeILGenerator ilg)
        {
            if (destType.IsValueType == true)
            {
                return(false);
            }

            if (object.ReferenceEquals(sourceType, typeof(Null)))
            {
                // Null is always convertible to a reference type
                return(true);
            }

            if (destType.IsAssignableFrom(sourceType) == false)
            {
                return(false);
            }

            if (sourceType.IsValueType == true)
            {
                if ((ilg != null))
                {
                    ilg.Emit(OpCodes.Box, sourceType);
                }
            }

            return(true);
        }
示例#5
0
        public static void EmitArrayStore(FleeILGenerator ilg, Type elementType)
        {
            TypeCode tc = Type.GetTypeCode(elementType);

            switch (tc)
            {
            case TypeCode.Byte:
            case TypeCode.SByte:
            case TypeCode.Boolean:
                ilg.Emit(OpCodes.Stelem_I1);
                break;

            case TypeCode.Int16:
            case TypeCode.UInt16:
                ilg.Emit(OpCodes.Stelem_I2);
                break;

            case TypeCode.Int32:
            case TypeCode.UInt32:
                ilg.Emit(OpCodes.Stelem_I4);
                break;

            case TypeCode.Int64:
            case TypeCode.UInt64:
                ilg.Emit(OpCodes.Stelem_I8);
                break;

            case TypeCode.Single:
                ilg.Emit(OpCodes.Stelem_R4);
                break;

            case TypeCode.Double:
                ilg.Emit(OpCodes.Stelem_R8);
                break;

            case TypeCode.Object:
            case TypeCode.String:
                ilg.Emit(OpCodes.Stelem_Ref);
                break;

            default:
                // Must be a non-primitive value type
                ilg.Emit(OpCodes.Stelem, elementType);
                break;
            }
        }
示例#6
0
        private static bool EmitOverloadedImplicitConvert(Type sourceType, Type destType, FleeILGenerator ilg)
        {
            // Look for an implicit operator on the destination type
            MethodInfo mi = Utility.GetSimpleOverloadedOperator("Implicit", sourceType, destType);

            if (mi == null)
            {
                // No match
                return(false);
            }

            if ((ilg != null))
            {
                ilg.Emit(OpCodes.Call, mi);
            }

            return(true);
        }