예제 #1
0
 public static void LoadField(ILGenerator il, FieldInfo field)
 {
     if (field.IsLiteral)
     {
         object value = field.GetValue(null);
         if (value is int)
         {
             EmitHelper.LoadInt(il, (int)value);
         }
         else if (value is float)
         {
             il.Emit(OpCodes.Ldc_R4, (float)value);
         }
         else if (value is string)
         {
             il.Emit(OpCodes.Ldstr, (string)value);
         }
         else if (value is bool)
         {
             bool bv = (bool)value;
             if (bv)
             {
                 il.Emit(OpCodes.Ldc_I4_1);
             }
             else
             {
                 il.Emit(OpCodes.Ldc_I4_0);
             }
         }
         else
         {
             throw new Exception("编译器不支持" + field.FieldType.Name + "类型");
         }
     }
     else if (field.IsStatic)
     {
         il.Emit(OpCodes.Ldsfld, field);
     }
     else
     {
         il.Emit(OpCodes.Ldfld, field);
     }
 }
예제 #2
0
 public static void EmitLoad(ILGenerator il, SymbolRefStaticMember symbol)
 {
     if (symbol.ZMember is ZPropertyInfo)
     {
         MethodInfo getMethod = (symbol.ZMember as ZPropertyInfo).SharpProperty.GetGetMethod();
         EmitHelper.CallDynamic(il, getMethod);
     }
     else if (symbol.ZMember is ZFieldInfo)
     {
         EmitHelper.LoadField(il, (symbol.ZMember as ZFieldInfo).SharpField);
     }
     else if (symbol.ZMember is ZEnumElementInfo)
     {
         int enumValue = (int)((symbol.ZMember as ZEnumElementInfo).Value);
         EmitHelper.LoadInt(il, enumValue);
     }
     else
     {
         throw new CompileException();
     }
 }
예제 #3
0
 public static void LoadDefaultValue(ILGenerator il, Type type)
 {
     if (type == typeof(bool))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else if (type == typeof(int))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else if (type == typeof(float))
     {
         il.Emit(OpCodes.Ldc_R4, (float)0.0);
     }
     else if (type == typeof(double))
     {
         il.Emit(OpCodes.Ldc_R8, (float)0.0);
     }
     else if (type == typeof(string))
     {
         il.Emit(OpCodes.Ldstr, "");
     }
     else if (type == typeof(char))
     {
         il.Emit(OpCodes.Ldc_I4_0);
     }
     else
     {
         ConstructorInfo constructor = type.GetConstructor(new Type[] { });
         if (constructor == null)
         {
             il.Emit(OpCodes.Ldnull);
         }
         else
         {
             EmitHelper.NewObj(il, constructor);
         }
     }
 }
예제 #4
0
 public static bool EmitSet_Storm(ILGenerator il, SymbolInfo symbol)
 {
     if (symbol is SymbolVar)
     {
         EmitHelper.StormVar(il, (symbol as SymbolVar).VarBuilder);
     }
     else if (symbol is SymbolArg)
     {
         EmitHelper.StormArg(il, (symbol as SymbolArg).ArgIndex);
     }
     else if (symbol is SymbolPropertyDirect)
     {
         SymbolPropertyDirect prsymbol  = symbol as SymbolPropertyDirect;
         MethodInfo           setMethod = prsymbol.ExProperty.Property.GetSetMethod();
         EmitHelper.CallDynamic(il, setMethod, prsymbol.ExProperty.IsSelf);
     }
     else if (symbol is SymbolDefProperty)
     {
         SymbolDefProperty prsymbol  = (symbol as SymbolDefProperty);
         MethodInfo        setMethod = prsymbol.GetProperty().GetSetMethod();
         EmitHelper.CallDynamic(il, setMethod, true);
     }
     else if (symbol is SymbolDefField)
     {
         SymbolDefField prsymbol = (symbol as SymbolDefField);
         EmitHelper.StormField(il, prsymbol.GetField());
     }
     else if (symbol is SymbolFieldDirect)
     {
         SymbolFieldDirect fymbol = symbol as SymbolFieldDirect;
         EmitHelper.StormField(il, fymbol.ExField.Field);
     }
     else
     {
         return(false);
     }
     return(true);
 }
예제 #5
0
 public static void EmitLoad(ILGenerator il, ZCLocalVar symbolVar)
 {
     EmitHelper.LoadVar(il, symbolVar.VarBuilder);
 }
예제 #6
0
 public static void EmitLoad(ILGenerator il, ZCFieldInfo memberCompiling)
 {
     EmitHelper.LoadField(il, memberCompiling.FieldBuilder);
 }
예제 #7
0
 public static void EmitLoad(ILGenerator il, ZLFieldInfo zfield)
 {
     EmitHelper.LoadField(il, zfield.SharpField);
 }
예제 #8
0
 public static void EmitStorm(ILGenerator il, ZLParamInfo zp)
 {
     EmitHelper.StormArg(il, zp.EmitIndex);
 }
예제 #9
0
 public static void EmitStorm(ILGenerator il, ZCParamInfo argsymbol)
 {
     EmitHelper.StormArg(il, argsymbol.EmitIndex);
 }
예제 #10
0
 public static void EmitStorm(ILGenerator il, ZCLocalVar symbolVar)
 {
     EmitHelper.StormVar(il, symbolVar.VarBuilder);
 }
예제 #11
0
 public static void EmitStorm(ILGenerator il, ZLFieldInfo memberCompiling)
 {
     EmitHelper.StormField(il, memberCompiling.SharpField);
 }