コード例 #1
0
 public static void EmitLoad(ILGenerator il, SymbolBase symbol)
 {
     if (symbol is SymbolLocalVar)
     {
         var symbolVar = symbol as SymbolLocalVar;
         EmitHelper.LoadVar(il, symbolVar.VarBuilder);
     }
     else if (symbol is SymbolArg)
     {
         SymbolArg argsymbol = (symbol as SymbolArg);
         EmitHelper.LoadArg(il, argsymbol.ArgIndex);
     }
     else if (symbol is SymbolDefProperty)
     {
         SymbolDefProperty symbol2   = (symbol as SymbolDefProperty);
         MethodInfo        getMethod = symbol2.Property.GetGetMethod();
         EmitHelper.CallDynamic(il, getMethod);
     }
     else if (symbol is SymbolDefField)
     {
         SymbolDefField symbol2 = (symbol as SymbolDefField);
         EmitHelper.LoadField(il, symbol2.Field);
     }
     else if (symbol is SymbolRefStaticMember)
     {
         EmitLoad(il, symbol as SymbolRefStaticMember);
     }
     else
     {
         throw new CompileException();
     }
 }
コード例 #2
0
 public static void SetLocalArrayElementValue(ILGenerator il, LocalBuilder arrayLocal, int index, Action emitValue)
 {
     EmitHelper.LoadVar(il, arrayLocal);
     EmitHelper.LoadInt(il, index);
     emitValue();
     il.Emit(OpCodes.Stelem_Ref);
 }
コード例 #3
0
 public static void Inc(ILGenerator il, LocalBuilder local)
 {
     EmitHelper.LoadVar(il, local);
     il.Emit(OpCodes.Ldc_I4_1);
     il.Emit(OpCodes.Add);
     EmitHelper.StormVar(il, local);
 }
コード例 #4
0
        //public static void CallDynamic(ILGenerator il, MethodInfo method)
        //{
        //il.Emit(OpCodes.Callvirt, method);

        /*if (method.IsAbstract || method.IsVirtual)
         * {
         *  il.Emit(OpCodes.Callvirt, method);
         * }
         * else
         * {
         *  il.Emit(OpCodes.Call, method);
         * }*/
        /* Console.WriteLine(string.Format("{0} IsStatic:{1}", method.Name, method.IsStatic));
         * if (method.IsStatic)
         * {
         *   il.Emit(OpCodes.Call, method);
         * }
         * else
         * {
         *   il.Emit(OpCodes.Callvirt, method);
         * }
         * }*/
        /*
         * public static void CallDynamic(ILGenerator il, MethodInfo method,Type objType)
         * {
         *  if (objType == method.DeclaringType)
         *      il.Emit(OpCodes.Call, method);
         *  else
         *      il.Emit(OpCodes.Callvirt, method);
         * }*/

        public static bool EmitSymbolGet(ILGenerator il, SymbolInfo symbol)
        {
            if (symbol is SymbolVar)
            {
                var symbolVar = symbol as SymbolVar;
                EmitHelper.LoadVar(il, symbolVar.VarBuilder);
            }
            else if (symbol is SymbolArg)
            {
                SymbolArg argsymbol = (symbol as SymbolArg);
                il.Emit(OpCodes.Ldarg, argsymbol.ArgIndex);
            }
            else if (symbol is SymbolEnumItem)
            {
                SymbolEnumItem eisymbol = (symbol as SymbolEnumItem);
                EmitHelper.LoadInt(il, (int)eisymbol.EnumValue);
            }
            else if (symbol is SymbolPropertyDirect)
            {
                SymbolPropertyDirect prsymbol  = symbol as SymbolPropertyDirect;
                MethodInfo           getMethod = prsymbol.ExProperty.Property.GetGetMethod();
                EmitHelper.CallDynamic(il, getMethod, prsymbol.ExProperty.IsSelf);
            }
            else if (symbol is SymbolFieldDirect)
            {
                SymbolFieldDirect fymbol = symbol as SymbolFieldDirect;
                EmitHelper.LoadField(il, fymbol.ExField.Field);
            }
            else if (symbol is SymbolDefProperty)
            {
                SymbolDefProperty prsymbol = (symbol as SymbolDefProperty);
                if (!prsymbol.IsStatic)
                {
                    il.Emit(OpCodes.Ldarg_0);
                }
                MethodInfo getMethod = prsymbol.GetProperty().GetGetMethod();
                EmitHelper.CallDynamic(il, getMethod, true);
            }
            else if (symbol is SymbolDefField)
            {
                SymbolDefField prsymbol = (symbol as SymbolDefField);
                if (!prsymbol.IsStatic)
                {
                    il.Emit(OpCodes.Ldarg_0);
                }
                //il.Emit(OpCodes.Ldfld, prsymbol.Builder);
                EmitHelper.LoadField(il, prsymbol.GetField());
            }
            else if (symbol is SymbolDefClass)
            {
                return(true);
            }
            else
            {
                return(false);
            }
            return(true);
        }
コード例 #5
0
ファイル: EmitSymbolHelper.cs プロジェクト: pyzh/ZLanguage3
 public static void EmitLoad(ILGenerator il, ZCLocalVar symbolVar)
 {
     EmitHelper.LoadVar(il, symbolVar.VarBuilder);
 }