当前位置: 首页>>代码示例>>C#>>正文


C# ILGen.EmitLoadArg方法代码示例

本文整理汇总了C#中ILGen.EmitLoadArg方法的典型用法代码示例。如果您正苦于以下问题:C# ILGen.EmitLoadArg方法的具体用法?C# ILGen.EmitLoadArg怎么用?C# ILGen.EmitLoadArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILGen的用法示例。


在下文中一共展示了ILGen.EmitLoadArg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        internal static Type Create(GenContext context, Type baseClass)
        {
            //ModuleBuilder mb = context.ModuleBldr;
            string name = baseClass.Name + "_impl";
            //TypeBuilder baseTB = context.ModuleBldr.DefineType(name, TypeAttributes.Class | TypeAttributes.Public, baseClass);
            TypeBuilder baseTB = context.AssemblyGen.DefinePublicType(name, baseClass, true);

            ObjExpr.MarkAsSerializable(baseTB);

            baseTB.DefineDefaultConstructor(MethodAttributes.Public);

            FieldBuilder metaField = baseTB.DefineField("_meta", typeof(IPersistentMap), FieldAttributes.Public);

            MethodBuilder metaMB = baseTB.DefineMethod("meta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IPersistentMap), Type.EmptyTypes);
            ILGen gen = new ILGen(metaMB.GetILGenerator());
            gen.EmitLoadArg(0);
            gen.EmitFieldGet(metaField);
            gen.Emit(OpCodes.Ret);

            MethodBuilder withMB = baseTB.DefineMethod("withMeta", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.ReuseSlot, typeof(IObj), new Type[] { typeof(IPersistentMap)});
            gen = new ILGen(withMB.GetILGenerator());
            gen.EmitLoadArg(0);
            gen.EmitCall(Compiler.Method_Object_MemberwiseClone);
            gen.Emit(OpCodes.Castclass, baseTB);
            gen.Emit(OpCodes.Dup);
            gen.EmitLoadArg(1);
            gen.EmitFieldSet(metaField);
            gen.Emit(OpCodes.Ret);

            for (int i = 0; i < 20; i++ )
                DefineDelegateFieldAndOverride(baseTB, i);

            return baseTB.CreateType();
        }
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:34,代码来源:AFnImplGenerator.cs

示例2: FixReturn

 internal void FixReturn(ILGen cg)
 {
     cg.EmitLoadArg(_argIndex);
     cg.Emit(OpCodes.Ldloc, _refSlot);
     cg.Emit(OpCodes.Ldfld, _refSlot.LocalType.GetDeclaredField("Value"));
     cg.EmitStoreValueIndirect(_argType.GetElementType());
 }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ReturnFixer.cs

示例3: EmitArgument

        internal static ReturnFixer EmitArgument(ILGen cg, int argIndex, Type argType) {
            cg.EmitLoadArg(argIndex);

            if (!argType.IsByRef) {
                cg.EmitBoxing(argType);
                return null;
            }

            Type elementType = argType.GetElementType();
            cg.EmitLoadValueIndirect(elementType);
            Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
            cg.EmitNew(concreteType, new Type[] { elementType });

            LocalBuilder refSlot = cg.DeclareLocal(concreteType);
            cg.Emit(OpCodes.Dup);
            cg.Emit(OpCodes.Stloc, refSlot);
            return new ReturnFixer(refSlot, argIndex, argType);
        }
开发者ID:Jaykul,项目名称:IronLangs,代码行数:18,代码来源:ReturnFixer.cs

示例4: BuildConstructors

        private void BuildConstructors(IList<ConstructorBuilderInfo>/*!*/ ctors) {
            foreach (var ctor in ctors) {
                // ctor(... RubyClass! class ..., <visible params>) : base(<hidden params>, <visible params>) { _class = class; }
                // ctor(... RubyClass! class ..., <visible params>) : base(... RubyOps.GetContextFromClass(class) ..., <visible params>) { _class = class; }
                // ctor(RubyClass! class) : base(RubyOps.GetDefaultExceptionMessage(class)) { _class = class; }
                ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ctor.ParameterTypes);
                ILGen il = new ILGen(cb.GetILGenerator());

                int paramIndex = 0;
                int argIndex = 0;

                // We need to initialize before calling base ctor since the ctor can call virtual methods.
                // _immediateClass = immediateClass:
                if (!IsDerivedRubyType) {
                    il.EmitLoadArg(0);
                    il.EmitLoadArg(1 + ctor.ClassParamIndex);
                    il.EmitFieldSet(ImmediateClassField);
                }

                // base ctor call:
                il.EmitLoadArg(0);

                ConstructorInfo msgCtor;
                if (ctor.ParameterTypes.Length == 1 && ctor.Adjustment == SignatureAdjustment.InsertClass &&
                    _tb.IsSubclassOf(typeof(Exception)) && IsAvailable(msgCtor = _tb.BaseType.GetConstructor(_exceptionMessageSignature))) {

                    // a parameterless exception constructor should use Ruby default message:
                    il.EmitLoadArg(1);
                    il.EmitCall(Methods.GetDefaultExceptionMessage);
                    il.Emit(OpCodes.Call, msgCtor);
                } else {
                    if (ctor.Adjustment == SignatureAdjustment.InsertClass) {
                        paramIndex++;
                    }

                    while (paramIndex < ctor.ParameterTypes.Length) {
                        if (ctor.Adjustment == SignatureAdjustment.ConvertClassToContext && argIndex == ctor.ContextArgIndex) {
                            il.EmitLoadArg(1 + ctor.ClassParamIndex);
                            il.EmitCall(Methods.GetContextFromModule);
                        } else {
                            ClsTypeEmitter.DefineParameterCopy(cb, paramIndex, ctor.BaseParameters[argIndex]);
                            il.EmitLoadArg(1 + paramIndex);
                        }
                        argIndex++;
                        paramIndex++;
                    }
                    il.Emit(OpCodes.Call, ctor.BaseCtor);
                }

                il.Emit(OpCodes.Ret);
            }
        }
开发者ID:jschementi,项目名称:iron,代码行数:52,代码来源:RubyTypeBuilder.cs

示例5: EmitMain

        static void EmitMain(GenContext context, TypeBuilder proxyTB, string mainName, FieldBuilder mainFB)
        {
            MethodBuilder cb = proxyTB.DefineMethod("Main",MethodAttributes.Public| MethodAttributes.Static,CallingConventions.Standard,typeof(void),new Type[] { typeof(String[]) });
            ILGen gen = new ILGen(cb.GetILGenerator()); ;

            Label noMainLabel = gen.DefineLabel();
            Label endLabel = gen.DefineLabel();

            EmitGetVar(gen, mainFB);
            gen.Emit(OpCodes.Dup);
            gen.Emit(OpCodes.Brfalse_S, noMainLabel);
            gen.Emit(OpCodes.Castclass, typeof(IFn));
            gen.EmitLoadArg(0);                                 // gen.Emit(OpCodes.Ldarg_0);
            gen.EmitCall(Method_RT_seq);                        // gen.Emit(OpCodes.Call, Method_RT_seq);
            gen.EmitCall(Method_IFn_applyTo_Object_ISeq);       // gen.Emit(OpCodes.Call, Method_IFn_applyTo_Object_ISeq);
            gen.Emit(OpCodes.Pop);
            gen.Emit(OpCodes.Br_S, endLabel);

            // no main found
            gen.MarkLabel(noMainLabel);
            EmitUnsupported(gen, mainName);

            gen.MarkLabel(endLabel);
            gen.Emit(OpCodes.Ret);

            //context.AssyBldr.SetEntryPoint(cb);
            context.AssemblyBuilder.SetEntryPoint(cb);
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:28,代码来源:GenClass.cs

示例6: EmitExposers

        private static void EmitExposers(TypeBuilder proxyTB, Type superClass, IPersistentMap exposesFields)
        {
            for ( ISeq s = RT.seq(exposesFields); s != null; s = s.next() )
            {
                IMapEntry me = (IMapEntry)s.first();
                Symbol protectedFieldSym = (Symbol)me.key();
                IPersistentMap accessMap = (IPersistentMap)me.val();

                string fieldName = protectedFieldSym.Name;
                Symbol getterSym = (Symbol)accessMap.valAt(_getKw, null);
                Symbol setterSym = (Symbol)accessMap.valAt(_setKW, null);

                FieldInfo fld = null;

                if ( getterSym != null || setterSym != null )
                    fld = superClass.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance);

                if (getterSym != null)
                {
                    MethodAttributes attribs = MethodAttributes.Public;
                    if (fld.IsStatic)
                        attribs |= MethodAttributes.Static;

                    MethodBuilder mb = proxyTB.DefineMethod(getterSym.Name, attribs, fld.FieldType, Type.EmptyTypes);
                    ILGen gen = new ILGen(mb.GetILGenerator());
                    //if (fld.IsStatic)
                    //    gen.Emit(OpCodes.Ldsfld, fld);
                    //else
                    //{
                    //    gen.Emit(OpCodes.Ldarg_0);
                    //    gen.Emit(OpCodes.Ldfld, fld);
                    //}
                    if (!fld.IsStatic)
                        gen.EmitLoadArg(0);
                    gen.EmitFieldGet(fld);

                    gen.Emit(OpCodes.Ret);
                }

                if (setterSym != null)
                {
                    MethodAttributes attribs = MethodAttributes.Public;
                    if (fld.IsStatic)
                        attribs |= MethodAttributes.Static;

                    MethodBuilder mb = proxyTB.DefineMethod(setterSym.Name, attribs, typeof(void), new Type[] { fld.FieldType });
                    ILGen gen = new ILGen(mb.GetILGenerator());
                    if (fld.IsStatic)
                    {
                        gen.Emit(OpCodes.Ldarg_0);
                        //gen.Emit(OpCodes.Stsfld, fld);
                    }
                    else
                    {
                        gen.Emit(OpCodes.Ldarg_0);
                        gen.Emit(OpCodes.Ldarg_1);
                        //gen.Emit(OpCodes.Stfld, fld);
                    }
                    gen.EmitFieldSet(fld);
                    gen.Emit(OpCodes.Ret);
                }
            }
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:63,代码来源:GenClass.cs

示例7: CreateSuperCall

        private static void CreateSuperCall(TypeBuilder proxyTB, Symbol p, MethodInfo mi)
        {
            Type[] paramTypes = CreateTypeArray(mi.GetParameters());

            MethodBuilder mb = proxyTB.DefineMethod(p.Name, MethodAttributes.Public, CallingConventions.HasThis, mi.ReturnType, paramTypes);
            ILGen gen = new ILGen(mb.GetILGenerator());
            gen.EmitLoadArg(0);                             // gen.Emit(OpCodes.Ldarg_0);
            for (int i = 0; i < paramTypes.Length; i++)
                gen.EmitLoadArg(i + 1);                     // gen.Emit(OpCodes.Ldarg, i + 1);
            gen.Emit(OpCodes.Call, mi);                     // not gen.EmitCall(mi); -- we need call versus callvirt
            gen.Emit(OpCodes.Ret);
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:12,代码来源:GenClass.cs

示例8: CallBaseConstructor

        private static void CallBaseConstructor(ConstructorInfo parentConstructor, ParameterInfo[] pis, ParameterInfo[] overrideParams, ILGen il) {
            il.EmitLoadArg(0);
#if DEBUG
            int lastIndex = -1;
#endif
            for (int i = 0; i < overrideParams.Length; i++) {
                int index = GetOriginalIndex(pis, overrideParams, i);

#if DEBUG
                // we insert a new parameter (the class) but the parametrers should
                // still remain in the same order after the extra parameter is removed.
                if (index >= 0) {
                    Debug.Assert(index > lastIndex);
                    lastIndex = index;
                }
#endif
                if (index >= 0) {
                    il.EmitLoadArg(i + 1);
                }
            }
            il.Emit(OpCodes.Call, parentConstructor);
            il.Emit(OpCodes.Ret);
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:23,代码来源:NewTypeMaker.cs

示例9: EmitArgument

 public static ReturnFixer EmitArgument(ILGen il, ParameterInfo parameter, int index) {
     il.EmitLoadArg(index);
     if (parameter.ParameterType.IsByRef) {
         Type elementType = parameter.ParameterType.GetElementType();
         Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
         LocalBuilder refSlot = il.DeclareLocal(concreteType);
         il.EmitLoadValueIndirect(elementType);
         ConstructorInfo ci = concreteType.GetConstructor(new Type[] { elementType });
         il.Emit(OpCodes.Newobj, ci);
         il.Emit(OpCodes.Stloc, refSlot);
         il.Emit(OpCodes.Ldloc, refSlot);
         return new ReturnFixer(refSlot, parameter, index);
     } else {
         il.EmitBoxing(parameter.ParameterType);
         return null;
     }
 }
开发者ID:Hank923,项目名称:ironruby,代码行数:17,代码来源:NewTypeMaker.cs

示例10: GeneratePrimMethod

        void GeneratePrimMethod(ObjExpr objx, GenContext context)
        {
            TypeBuilder tb = objx.TypeBuilder;
            MethodBuilder mb = tb.DefineMethod("invokePrim", MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual, StaticReturnType, StaticMethodArgTypes);

            //Console.Write("InMd: {0} {1}(", ReturnType.Name, "invokePrim");
            //foreach (Type t in ArgTypes)
            //    Console.Write("{0}", t.Name);
            //Console.WriteLine(")");

            GenInterface.SetCustomAttributes(mb, _methodMeta);
            if (_parms != null)
            {
                for (int i = 0; i < _parms.count(); i++)
                {
                    IPersistentMap meta = GenInterface.ExtractAttributes(RT.meta(_parms.nth(i)));
                    if (meta != null && meta.count() > 0)
                    {
                        ParameterBuilder pb = mb.DefineParameter(i + 1, ParameterAttributes.None, ((Symbol)_parms.nth(i)).Name);
                        GenInterface.SetCustomAttributes(pb, meta);
                    }
                }
            }

            ILGen gen = new ILGen(mb.GetILGenerator());
            gen.EmitLoadArg(0);
            for (int i = 1; i <= _argLocals.count(); i++)
                gen.EmitLoadArg(i);
            gen.EmitCall(_staticMethodBuilder);
            gen.Emit(OpCodes.Ret);

            if (IsExplicit)
                tb.DefineMethodOverride(mb, _explicitMethodInfo);
        }
开发者ID:roffster,项目名称:clojure-clr,代码行数:34,代码来源:ObjMethod.cs

示例11: GenerateFieldOnlyConstructor

        private ConstructorBuilder GenerateFieldOnlyConstructor(TypeBuilder fnTB, Type baseType)
        {
            Type[] ctorTypes = CtorTypes();
            Type[] altCtorTypes = new Type[ctorTypes.Length - _altCtorDrops];
            for (int i = 0; i < altCtorTypes.Length; i++)
                altCtorTypes[i] = ctorTypes[i];

            ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, altCtorTypes);
            ILGen gen = new ILGen(cb.GetILGenerator());

            //Call full constructor
            gen.EmitLoadArg(0);                     // gen.Emit(OpCodes.Ldarg_0);
            for (int i = 0; i < altCtorTypes.Length; i++)
                gen.EmitLoadArg(i + 1);

            for (int i = 0; i < _altCtorDrops; i++)
                gen.EmitNull();

            gen.Emit(OpCodes.Call, _ctorInfo);

            gen.Emit(OpCodes.Ret);
            return cb;
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:23,代码来源:ObjExpr.cs

示例12: GenerateConstructor

        private ConstructorBuilder GenerateConstructor(TypeBuilder fnTB, Type baseType)
        {
            ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, CtorTypes());
            ILGen gen = new ILGen(cb.GetILGenerator());

            //Call base constructor
            ConstructorInfo baseCtorInfo = baseType.GetConstructor(Type.EmptyTypes);
            gen.EmitLoadArg(0);                     // gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Call, baseCtorInfo);

            //// Initialize __varrev__
            //if (_vars.count() > 0)
            //{
            //    gen.EmitLoadArg(0);
            //    gen.EmitPropertyGet(Compiler.Method_Var_Rev);
            //    gen.EmitInt(-1);
            //    gen.Emit(OpCodes.Add);
            //    gen.EmitFieldSet(_varRevField);
            //}

            // Store Meta
            if (SupportsMeta)
            {
                gen.EmitLoadArg(0);
                gen.EmitLoadArg(1);
                gen.Emit(OpCodes.Castclass, typeof(IPersistentMap));
                gen.EmitFieldSet(_metaField);
            }

            // store closed-overs in their fields
            int a = 0;
            int offset = !SupportsMeta ? 1 : 2;

            for (ISeq s = RT.keys(_closes); s != null; s = s.next(), a++)
            {
                LocalBinding lb = (LocalBinding)s.first();
                FieldBuilder fb = _closedOverFields[a];

                gen.EmitLoadArg(0);             // gen.Emit(OpCodes.Ldarg_0);
                gen.EmitLoadArg(a + offset);         // gen.Emit(OpCodes.Ldarg, a + 1);
                gen.Emit(OpCodes.Stfld, fb);
            }
            gen.Emit(OpCodes.Ret);
            return cb;
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:45,代码来源:ObjExpr.cs

示例13: GenerateBaseClassConstructor

        private void GenerateBaseClassConstructor(Type superType, TypeBuilder baseTB)
        {
            ConstructorInfo ci = superType.GetConstructor(Type.EmptyTypes);

            if (ci == null)
                return;

            ConstructorBuilder cb = baseTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, Type.EmptyTypes);
            ILGen gen = new ILGen(cb.GetILGenerator());

            gen.EmitLoadArg(0);
            gen.Emit(OpCodes.Call, ci);
            gen.Emit(OpCodes.Ret);

            // Call base constructor
            //if (_superName != null)
            //{
            //    Type parentType = Type.GetType(_superName);
            //    ConstructorInfo cInfo = parentType.GetConstructor(Type.EmptyTypes);
            //    gen.EmitLoadArg(0);         //gen.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Call, cInfo);
            //}
            //else if (IsVariadic)
            //{
            //    gen.EmitLoadArg(0);                             // gen.Emit(OpCodes.Ldarg_0);
            //    gen.EmitInt(_variadicMethod.RequiredArity);     // gen.Emit(OpCodes.Ldc_I4, _variadicMethod.RequiredArity);
            //    gen.Emit(OpCodes.Call, RestFn_Int_Ctor);
            //}
            //else
            //{
            //    gen.EmitLoadArg(0);                             // en.Emit(OpCodes.Ldarg_0);
            //    gen.Emit(OpCodes.Call, AFunction_Default_Ctor);
            //}
            //gen.Emit(OpCodes.Ret);
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:35,代码来源:ObjExpr.cs

示例14: GenerateSwapThunk

        // TODO: Avoid going through the static, i.e., define the interface method directly.
        void GenerateSwapThunk(TypeBuilder tb)
        {
            if (_keywordCallsites.count() == 0)
                return;

            MethodBuilder mbs = tb.DefineMethod("swapThunk_static", MethodAttributes.Public | MethodAttributes.Static, typeof(void), new Type[] { typeof(int), typeof(ILookupThunk) });

            ParameterExpression pi = Expression.Parameter(typeof(int), "i");
            ParameterExpression pt = Expression.Parameter(typeof(ILookupThunk), "t");

            List<SwitchCase> cases = new List<SwitchCase>(_keywordCallsites.count());
            for (int i = 0; i < _keywordCallsites.count(); i++)
                cases.Add(
                    Expression.SwitchCase(
                        Expression.Block(
                            Expression.Assign(Expression.Field(null, _thunkFields[i]), pt),
                            Expression.Default(typeof(void))),
                        Expression.Constant(i)));

            Expression body = Expression.Switch(pi, cases.ToArray<SwitchCase>());
            LambdaExpression lambda = Expression.Lambda(body, pi, pt);
            lambda.CompileToMethod(mbs);

            MethodBuilder mb = tb.DefineMethod("swapThunk", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual, typeof(void), new Type[] { typeof(int), typeof(ILookupThunk) });
            ILGen gen = new ILGen(mb.GetILGenerator());
            gen.EmitLoadArg(0);
            gen.EmitLoadArg(1);
            gen.EmitCall(mbs);
            gen.Emit(OpCodes.Ret);
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:31,代码来源:ObjExpr.cs

示例15: GenerateNonMetaConstructor

        private ConstructorBuilder GenerateNonMetaConstructor(TypeBuilder fnTB, Type baseType)
        {
            Type[] ctorTypes = CtorTypes();
            Type[] noMetaCtorTypes = new Type[ctorTypes.Length - 1];
            for (int i = 1; i < ctorTypes.Length; i++)
                noMetaCtorTypes[i - 1] = ctorTypes[i];

            ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, noMetaCtorTypes);
            ILGen gen = new ILGen(cb.GetILGenerator());

            gen.EmitLoadArg(0);
            gen.EmitNull();     // null meta
            for (int i = 0; i < noMetaCtorTypes.Length; i++)
                gen.EmitLoadArg(i + 1);
            gen.Emit(OpCodes.Call, _ctorInfo);
            gen.Emit(OpCodes.Ret);

            return cb;
        }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:19,代码来源:ObjExpr.cs


注:本文中的ILGen.EmitLoadArg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。