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


C# ILGen.EmitInt方法代码示例

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


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

示例1: Compile

 public override void Compile(Executive engine, object form, ILGen il, LocalAccess locals, Stack<Type> st, object[] args)
 {
     il.Emit(OpCodes.Ldarg_1);
     il.EmitInt(locals.DefineConstant(args[0]));
     il.Emit(OpCodes.Ldelem_Ref);
     st.Push(typeof(System.Object));
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: GenerateGetRequiredArityMethod

        static MethodBuilder GenerateGetRequiredArityMethod(TypeBuilder tb, int requiredArity)
        {
            MethodBuilder mb = tb.DefineMethod(
                "getRequiredArity",
                MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual,
                typeof(int),
                Type.EmptyTypes);

            ILGen gen = new ILGen(mb.GetILGenerator());
            gen.EmitInt(requiredArity);
            gen.Emit(OpCodes.Ret);

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

示例3: EmitConstantGet

 private static void EmitConstantGet(ILGen il, int index, Type type) {
     il.Emit(OpCodes.Ldarg_0);
     il.EmitInt(index);
     il.Emit(OpCodes.Ldelem_Ref);
     if (type != typeof(object)) {
         il.Emit(OpCodes.Castclass, type);
     }
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:8,代码来源:DelegateSignatureInfo.cs

示例4: DefineCtors

        static void DefineCtors(TypeBuilder proxyTB, 
            Type superClass,
            string initName,
            string postInitName,
            ISeq ctorsTypes,
            FieldBuilder initFB,
            FieldBuilder postInitFB,
            FieldBuilder stateFB,
            string factoryName)
        {
            for (ISeq s = ctorsTypes; s != null; s = s.next())
            {
                IMapEntry me = (IMapEntry)s.first();
                ISeq thisParamTypesV = (ISeq)me.key();
                ISeq baseParamTypesV = (ISeq)me.val();

                Type[] thisParamTypes = CreateTypeArray(thisParamTypesV);
                Type[] baseParamTypes = CreateTypeArray(baseParamTypesV);

                BindingFlags flags = BindingFlags.CreateInstance| BindingFlags.NonPublic| BindingFlags.Public| BindingFlags.Instance;
                ConstructorInfo superCtor = superClass.GetConstructor(flags,null,baseParamTypes,null);

                if (superCtor == null || superCtor.IsPrivate)
                    throw new InvalidOperationException("Base class constructor missing or private");

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

                Label noInitLabel = gen.DefineLabel();
                Label noPostInitLabel = gen.DefineLabel();
                Label endPostInitLabel = gen.DefineLabel();
                Label endLabel = gen.DefineLabel();

                LocalBuilder locSuperArgs = gen.DeclareLocal(typeof(object));
                LocalBuilder locInitVal = gen.DeclareLocal(typeof(object));

                if (initFB != null)
                {
                    // init supplied
                    EmitGetVar(gen, initFB);
                    gen.Emit(OpCodes.Dup);
                    gen.Emit(OpCodes.Brfalse_S, noInitLabel);
                    gen.Emit(OpCodes.Castclass, typeof(IFn));

                    // box init args
                    for (int i = 0; i < thisParamTypes.Length; i++)
                    {
                        gen.EmitLoadArg(i + 1);                     // gen.Emit(OpCodes.Ldarg, i + 1);
                        if (thisParamTypes[i].IsValueType)
                            gen.Emit(OpCodes.Box,thisParamTypes[i]);
                    }

                    gen.EmitCall(Compiler.Methods_IFn_invoke[thisParamTypes.Length]);   // gen.Emit(OpCodes.Call, Compiler.Methods_IFn_invoke[thisParamTypes.Length]);

                    // Expecting:  [[super-ctor-args...] state]

                    // store the init return in a local
                    gen.Emit(OpCodes.Dup);
                    gen.Emit(OpCodes.Stloc,locInitVal);

                    // store the first element in a local
                    gen.EmitInt(0);                             // gen.Emit(OpCodes.Ldc_I4_0);
                    gen.EmitCall(Method_RT_nth);                // gen.Emit(OpCodes.Call, Method_RT_nth);
                    gen.Emit(OpCodes.Stloc, locSuperArgs);

                    // Stack this + super-ctor-args + call base-class ctor.
                    gen.EmitLoadArg(0);                         // gen.Emit(OpCodes.Ldarg_0);
                    for (int i = 0; i < baseParamTypes.Length; i++)
                    {
                        gen.Emit(OpCodes.Ldloc, locSuperArgs);
                        gen.EmitInt(i);                         // gen.Emit(OpCodes.Ldc_I4, i);
                        gen.EmitCall(Method_RT_nth);            // gen.Emit(OpCodes.Call, Method_RT_nth);
                        if (baseParamTypes[i].IsValueType)
                            gen.Emit(OpCodes.Unbox_Any, baseParamTypes[i]);
                        else
                            gen.Emit(OpCodes.Castclass, baseParamTypes[i]);
                    }

                    gen.Emit(OpCodes.Call, superCtor);

                    if (stateFB != null)
                    {
                        gen.EmitLoadArg(0);                     // gen.Emit(OpCodes.Ldarg_0);
                        gen.Emit(OpCodes.Ldloc, locInitVal);
                        gen.EmitInt(1);                         // gen.Emit(OpCodes.Ldc_I4_1);
                        gen.EmitCall(Method_RT_nth);            // gen.Emit(OpCodes.Call, Method_RT_nth);
                        gen.Emit(OpCodes.Castclass, typeof(object));
                        gen.EmitFieldSet(stateFB);              // gen.Emit(OpCodes.Stfld, stateFB);
                    }

                    gen.Emit(OpCodes.Br_S, endLabel);

                    // No init found
                    gen.MarkLabel(noInitLabel);

                    gen.Emit(OpCodes.Pop);
                    EmitUnsupported(gen, initName);

                    gen.MarkLabel(endLabel);
                }
//.........这里部分代码省略.........
开发者ID:ragnard,项目名称:clojure-clr,代码行数:101,代码来源:GenClass.cs

示例5: EmitOp

        public static void EmitOp(MethodInfo method, ILGen ilg)
        {
            OpCode[] opcodes = _ops[method];

            // special case the shift methods because we didn't create a way to embed arguments to the opcodes.
            // the long second-arg bit-shifts need to mask to a value <= 63
            // the int second-arg bit-shifts need to maks to a value <= 31
            switch (method.Name)
            {
                case "shiftLeft":
                case "shiftRight":
                case "unsignedShiftRight":
                    ilg.Emit(OpCodes.Conv_I4);
                    ilg.EmitInt(0x3f);
                    ilg.Emit(OpCodes.And);
                    break;

                case "shiftLeftInt":
                case "shiftRightInt":
                case "unsignedShiftRightInt":
                    ilg.EmitInt(0x1f);
                    ilg.Emit(OpCodes.And);
                    break;
            }

            foreach ( OpCode opcode in opcodes )
                ilg.Emit(opcode);
        }
开发者ID:telefunkenvf14,项目名称:clojure-clr,代码行数:28,代码来源:Intrinsics.cs

示例6: CompileExpr

 internal void CompileExpr(ILGen il, LocalAccess locals, Stack<Type> st, object lval)
 {
     if (lval == null)
     {
         il.EmitNull();
         st.Push(typeof(System.Object));
     }
     else if (Lisp.IsNode(lval))
     {
         if (lval == Lisp.NIL || lval == Lisp.T)
         {
             if (lval == Lisp.NIL)
                 il.EmitNull();
             else
                 il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
             st.Push(typeof(System.Object));
         }
         else if (lval == Lisp.INST)
         {
             il.Emit(OpCodes.Ldarg_0);
             il.EmitPropertyGet(typeof(CompiledLambda), "Engine");
             st.Push(typeof(Executive));
         }
         else if (lval == Lisp.ARGV)
         {
             il.Emit(OpCodes.Ldarg_2);
             st.Push(typeof(object[]));
         }
         else if (lval == Lisp.MPOOL)
         {
             il.Emit(OpCodes.Ldarg_3);
             st.Push(typeof(MemoryPool));
         }
         else
         {
             LocalBuilder localVar = locals.GetLocal(lval);
             if (localVar != null)
             {
                 il.Emit(OpCodes.Ldloc, localVar);
                 st.Push(localVar.LocalType);
             }
             else
             {
                 Type type = lval.GetType();
                 if (type == typeof(Integer))
                 {
                     il.EmitDecimal((Decimal)((Integer)lval));
                     il.EmitNew(typeof(Integer).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null,
                         new Type[] { typeof(Decimal) }, null));
                 }
                 else if (!il.TryEmitConstant(lval, type))
                 {
                     il.Emit(OpCodes.Ldarg_1);
                     il.EmitInt(locals.DefineConstant(lval));
                     il.Emit(OpCodes.Ldelem_Ref);
                     if (type.IsValueType)
                         il.EmitUnbox(type);
                 }
                 st.Push(type);
             }
         }
     }
     else if (Lisp.IsFunctor(lval))
     {
         object head = Lisp.Car(lval);
         object[] args = Lisp.ToArray(Lisp.Cdr(lval));
         ControlFormBase control;
         if (m_control.TryGetValue(head, out control))
             control.Compile(this, lval, il, locals, st, args);
         else
         {
             foreach (object a in args)
                 CompileExpr(il, locals, st, a);
             Type[] parameterTypes = new Type[args.Length];
             for (int k = args.Length - 1; k >= 0; k--)
                 parameterTypes[k] = st.Pop();
             FuncName name = new FuncName(head, parameterTypes);
             FuncBase body = GetFunc(name, false);
             if (body == null)
             {
                 bool successed = false;
                 if (parameterTypes.Length == 2)
                 {
                     Type castType = ValueProxy.GetType(parameterTypes[0], parameterTypes[1]);
                     ValueConverter converter1 = FindConverter(parameterTypes[0], castType);
                     ValueConverter converter2 = FindConverter(parameterTypes[1], castType);
                     body = GetFunc(new FuncName(name.ID, new Type[] { castType, castType }), false);
                     if (body != null && converter1 != null && converter2 != null)
                     {
                         LocalBuilder localVar = il.DeclareLocal(parameterTypes[1]);
                         il.Emit(OpCodes.Stloc, localVar);
                         converter1.Compile(this, il, locals, parameterTypes[0]);
                         il.Emit(OpCodes.Ldloc, localVar);
                         il.FreeLocal(localVar);
                         converter2.Compile(this, il, locals, parameterTypes[1]);
                         successed = true;
                     }
                 }
                 if (!successed)
                 {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例7: WriteEpilog

 private void WriteEpilog(ILGen il, Parameter[] parameters, LocalAccess locals)
 {
     if (locals.HasLocals || parameters.Length > 0)
     {
         Label label = il.DefineLabel();
         if (parameters.Length > 0)
         {
             for (int k = 0; k < parameters.Length; k++)
             {
                 il.Emit(OpCodes.Ldarg_2);
                 il.EmitInt(k);
                 il.Emit(OpCodes.Ldelem_Ref);
                 if (parameters[k].Type.IsValueType)
                 {
                     il.Emit(OpCodes.Isinst, parameters[k].Type);
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse, label);
                     if (locals.IsParameterBinded(parameters[k].ID))
                     {
                         LocalBuilder local = locals.GetLocal(parameters[k].ID);
                         il.EmitUnbox(local.LocalType);
                         il.Emit(OpCodes.Stloc, local);
                     }
                     else
                         il.Emit(OpCodes.Pop);
                 }
                 else
                 {
                     Label label2 = il.DefineLabel();
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse_S, label2);
                     il.Emit(OpCodes.Isinst, parameters[k].Type);
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse, label);
                     il.MarkLabel(label2);
                     if (locals.IsParameterBinded(parameters[k].ID))
                     {                                                                
                         LocalBuilder local = locals.GetLocal(parameters[k].ID);
                         il.Emit(OpCodes.Stloc, local);
                     }
                     else
                         il.Emit(OpCodes.Pop);
                 }
             }
         }
         if (locals.HasLocals)
         {
             il.Emit(OpCodes.Ldarg_0);
             il.EmitPropertyGet(typeof(CompiledLambda), "Values");
             LocalBuilder values = il.DeclareLocal(typeof(SymbolLink[]));
             il.Emit(OpCodes.Stloc, values);
             int k = 0;
             foreach (LocalAccess.LocalBinding b in locals)
             {
                 il.Emit(OpCodes.Ldarg_3);                        
                 il.Emit(OpCodes.Ldloc, values);
                 il.EmitInt(k++);
                 il.Emit(OpCodes.Ldelem_Ref);
                 il.EmitCall(m_memoryPoolGetData);
                 if (b.Local.LocalType.IsValueType)
                 {
                     il.Emit(OpCodes.Isinst, b.Local.LocalType);
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse, label);
                     il.EmitUnbox(b.Local.LocalType);
                     il.Emit(OpCodes.Stloc, b.Local);
                 }
                 else
                 {
                     Label label2 = il.DefineLabel();
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse_S, label2);
                     il.Emit(OpCodes.Isinst, b.Local.LocalType);
                     il.Emit(OpCodes.Dup);
                     il.Emit(OpCodes.Brfalse, label);
                     il.MarkLabel(label2);
                     il.Emit(OpCodes.Stloc, b.Local);
                 }
             }
             il.FreeLocal(values);
         }
         Label end = il.DefineLabel();
         il.Emit(OpCodes.Br_S, end);
         il.MarkLabel(label);
         il.Emit(OpCodes.Pop); // Isinst
         il.EmitPropertyGet(typeof(Undefined), "Value");
         il.Emit(OpCodes.Ret);
         il.MarkLabel(end);                
     }
 }
开发者ID:,项目名称:,代码行数:90,代码来源:

示例8: DefineDelegateFieldAndOverride

        static void DefineDelegateFieldAndOverride(TypeBuilder tb, int numArgs)
        {
            Type fieldType = FuncTypeHelpers.GetFFuncType(numArgs);
            string fieldName = "_fn" + numArgs;
            FieldBuilder fb = tb.DefineField(fieldName, fieldType, FieldAttributes.Public);

            MethodBuilder mb = tb.DefineMethod("invoke", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual, typeof(object), CreateObjectTypeArray(numArgs));

            ILGen gen = new ILGen(mb.GetILGenerator());

            Label eqLabel = gen.DefineLabel();

            //  this._fni == null ?
            gen.EmitLoadArg(0);                                 // gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldfld, fb);
            gen.EmitNull();                                     // gen.Emit(OpCodes.Ldnull);
            gen.Emit(OpCodes.Beq, eqLabel);
            //Not equal to Null, invoke it.
            gen.EmitLoadArg(0);                                 //  gen.Emit(OpCodes.Ldarg_0);
            gen.Emit(OpCodes.Ldfld, fb);
            for (int i = 0; i < numArgs; i++)
                gen.EmitLoadArg(i + 1);                         // gen.Emit(OpCodes.Ldarg, i + 1);
            gen.EmitCall(fb.FieldType.GetMethod("Invoke"));     // gen.Emit(OpCodes.Call, fb.FieldType.GetMethod("Invoke"));
            gen.Emit(OpCodes.Ret);

            gen.MarkLabel(eqLabel);
            // Equal to Null: throw WrongArityException
            gen.EmitLoadArg(0);                                 // gen.Emit(OpCodes.Ldarg_0);
            gen.EmitInt(numArgs);
            gen.EmitCall(Method_AFn_WrongArityException);       // gen.Emit(OpCodes.Call, Method_AFn_WrongArityException);
            gen.Emit(OpCodes.Throw);
        }
开发者ID:christianblunden,项目名称:clojure-clr,代码行数:32,代码来源:AFnImplGenerator.cs

示例9: GenerateHasArityMethod

        protected static MethodBuilder GenerateHasArityMethod(TypeBuilder tb, IList<int> arities, bool isVariadic, int reqArity)
        {
            MethodBuilder mb = tb.DefineMethod(
                "HasArity",
                MethodAttributes.ReuseSlot | MethodAttributes.Public | MethodAttributes.Virtual,
                typeof(bool),
                new Type[] { typeof(int) });

            ILGen gen = new ILGen(mb.GetILGenerator());

            Label falseLabel = gen.DefineLabel();
            Label trueLabel = gen.DefineLabel();

            if (isVariadic)
            {
                gen.EmitLoadArg(1);
                gen.EmitInt(reqArity);
                gen.Emit(OpCodes.Bge,trueLabel);
            }

            if (arities != null)
            {
                foreach (int i in arities)
                {
                    gen.EmitLoadArg(1);
                    gen.EmitInt(i);
                    gen.Emit(OpCodes.Beq, trueLabel);
                }
            }

            gen.MarkLabel(falseLabel);
            gen.EmitBoolean(false);
            gen.Emit(OpCodes.Ret);

            gen.MarkLabel(trueLabel);
            gen.EmitBoolean(true);
            gen.Emit(OpCodes.Ret);

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


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