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


C# ILGen.MarkLabel方法代码示例

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


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

示例1: Compile

 public override Type Compile(Executive engine, ILGen il, LocalAccess locals, Type[] parameterTypes)
 {
     Label l_true = il.DefineLabel();
     Label l_false = il.DefineLabel();
     il.Emit(OpCodes.Brfalse_S, l_true);
     il.EmitNull();
     il.Emit(OpCodes.Br_S, l_false);
     il.MarkLabel(l_true);
     il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
     il.MarkLabel(l_false);
     return typeof(System.Object);
 }
开发者ID:,项目名称:,代码行数:12,代码来源:

示例2: EmitBaseClassCallCheckForProperties

        /// <summary>
        /// Emits code to check if the class has overridden this specific
        /// function.  For example:
        /// 
        /// MyDerivedType.SomeVirtualFunction = ...
        ///     or
        /// 
        /// class MyDerivedType(MyBaseType):
        ///     def SomeVirtualFunction(self, ...):
        /// 
        /// </summary>
        private LocalBuilder EmitBaseClassCallCheckForProperties(ILGen il, MethodInfo baseMethod, string name) {
            Label instanceCall = il.DefineLabel();
            LocalBuilder callTarget = il.DeclareLocal(typeof(object));

            // first lookup under the property name
            il.EmitLoadArg(0);
            EmitSymbolId(il, name);
            il.Emit(OpCodes.Ldloca, callTarget);
            il.EmitCall(typeof(UserTypeOps), "TryGetNonInheritedValueHelper");
            il.Emit(OpCodes.Brtrue, instanceCall);

            // then look up under the method name (get_Foo/set_Foo)
            LocalBuilder methodTarget = EmitNonInheritedMethodLookup(baseMethod.Name, il);
            Label instanceCallMethod = il.DefineLabel();
            il.Emit(OpCodes.Brtrue, instanceCallMethod);

            // method isn't overridden using either form
            EmitBaseMethodDispatch(baseMethod, il);

            // we're calling the get_/set_ method
            il.MarkLabel(instanceCallMethod);
            EmitClrCallStub(il, baseMethod, methodTarget);
            il.Emit(OpCodes.Ret);

            il.MarkLabel(instanceCall);

            // we're accessing a property
            return callTarget;
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:40,代码来源:NewTypeMaker.cs

示例3: EmitVirtualSiteCall

        public void EmitVirtualSiteCall(ILGen il, MethodInfo mi, string name) {
            Label baseCallLabel = il.DefineLabel();

            LocalBuilder resultVar = il.DeclareLocal(typeof(object));
            EmitClrCallStub(il, mi, name);
            il.Emit(OpCodes.Stloc, resultVar);

            il.Emit(OpCodes.Ldloc, resultVar);
            il.Emit(OpCodes.Ldsfld, Fields.ForwardToBase);
            il.Emit(OpCodes.Ceq);
            il.Emit(OpCodes.Brtrue, baseCallLabel);

            if (mi.ReturnType != typeof(void)) {
                il.Emit(OpCodes.Ldloc, resultVar);
                EmitConvertFromObject(il, mi.ReturnType);
            }
            il.Emit(OpCodes.Ret);

            il.MarkLabel(baseCallLabel);
            EmitBaseMethodDispatch(mi, il);
        }
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:21,代码来源:ClsTypeEmitter.cs

示例4: CreateBinaryOperationIC

    public static void CreateBinaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, mdr.ValueTypes i1Type, bool i0TypeCheck, bool i1TypeCheck)
    {
      ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);

      var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
      ilGen.Ldarg_CallFrame();
      ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
      ilGen.Stloc(values);

      ///Try to make a better guess on the unknown types. 
      if (i0Type == mdr.ValueTypes.DValueRef)
      {
        if (i1Type != mdr.ValueTypes.DValueRef)
          i0Type = i1Type;
        else
          i0Type = i1Type = mdr.ValueTypes.Int32; //Just a guess! 
      }
      else if (i1Type == mdr.ValueTypes.DValueRef)
        i1Type = i0Type;

      var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
      //if (i0TypeCheck)
      {
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        ilGen.Call(CodeGen.Types.DValue.GetValueType);
        ilGen.Stloc(t0);
      }

      var t1 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
      //if (i0TypeCheck)
      {
        LoadValue(ilGen, values, resultIndex + 1, mdr.ValueTypes.DValueRef);
        ilGen.Call(CodeGen.Types.DValue.GetValueType);
        ilGen.Stloc(t1);
      }

      var guardFail = ilGen.DefineLabel();
      var done = ilGen.DefineLabel();

      ilGen.Ldloc(t0);
      ilGen.Ldc_I4(8);
      ilGen.Shl();
      ilGen.Ldloc(t1);
      ilGen.Or();
      ilGen.Ldc_I4(((int)i0Type << 8) | (int)i1Type);
      ilGen.Bne_Un(guardFail);

      var operation = CodeGen.Types.Operations.Binary.Get(nodeType);
      var mi = operation.Get(i0Type, i1Type);
      var returnType = operation.ReturnType(i0Type, i1Type);
      if (returnType == mdr.ValueTypes.DValueRef)
      {
        Debug.Assert(mi.GetParameters().Length == 3 && mi.GetParameters()[2].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a third parameter of type 'ref DValue'", mi);
        LoadValue(ilGen, values, resultIndex, i0Type);
        LoadValue(ilGen, values, resultIndex + 1, i1Type);
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        ilGen.Call(mi);
      }
      else
      {
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        LoadValue(ilGen, values, resultIndex, i0Type);
        LoadValue(ilGen, values, resultIndex + 1, i1Type);
        ilGen.Call(mi);
        ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
      }
      ilGen.Br(done);

      ilGen.MarkLabel(guardFail);
      ilGen.Ldarg_CallFrame();
      ilGen.Ldarg_1();
      ilGen.Ldc_I4((int)nodeType);
      ilGen.Ldc_I4(resultIndex);
      ilGen.Ldloc(t0);
      ilGen.Ldloc(t1);
      ilGen.Ldc_I4(i0TypeCheck);
      ilGen.Ldc_I4(i1TypeCheck);
      ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateBinaryOperationIC);
      ilGen.Ret();

      ilGen.MarkLabel(done);
    }
开发者ID:reshadi2,项目名称:mcjs,代码行数:82,代码来源:ICMethods.cs

示例5: CreateUnaryOperationIC

    public static void CreateUnaryOperationIC(ILGen.BaseILGenerator ilGen, IR.NodeType nodeType, int resultIndex, mdr.ValueTypes i0Type, bool i0TypeCheck)
    {
      ilGen.WriteComment("IC method for {0}({1}, {2}) written to {3}", nodeType, i0Type, i0Type, resultIndex);

      var values = ilGen.DeclareLocal(CodeGen.Types.DValue.ArrayOf);
      ilGen.Ldarg_CallFrame();
      ilGen.Ldfld(CodeGen.Types.CallFrame.Values);
      ilGen.Stloc(values);

      var t0 = ilGen.DeclareLocal(CodeGen.Types.ClrSys.Int32);
      //if (i0TypeCheck)
      {
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        ilGen.Call(CodeGen.Types.DValue.GetValueType);
        ilGen.Stloc(t0);
      }

      var guardFail = ilGen.DefineLabel();
      var done = ilGen.DefineLabel();

      var operation = CodeGen.Types.Operations.Unary.Get(nodeType);

      if (i0Type == mdr.ValueTypes.DValueRef) //Just a better guess!
        i0Type = operation.ReturnType(i0Type); //we will need to repeat the lookup again

      ilGen.Ldloc(t0);
      ilGen.Ldc_I4((int)i0Type);
      ilGen.Bne_Un(guardFail);

      var mi = operation.Get(i0Type);
      var returnType = operation.ReturnType(i0Type);

      if (returnType == mdr.ValueTypes.DValueRef)
      {
        Debug.Assert(mi.GetParameters().Length == 2 && mi.GetParameters()[1].ParameterType == CodeGen.Types.TypeOf(mdr.ValueTypes.DValueRef), "Invalid situation, method {0} must get a second parameter of type 'ref DValue'", mi);
        LoadValue(ilGen, values, resultIndex, i0Type);
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        ilGen.Call(mi);
      }
      else
      {
        LoadValue(ilGen, values, resultIndex, mdr.ValueTypes.DValueRef);
        LoadValue(ilGen, values, resultIndex, i0Type);
        ilGen.Call(mi);
        ilGen.Call(CodeGen.Types.DValue.Set.Get(returnType));
      }
      ilGen.Br(done);

      ilGen.MarkLabel(guardFail);
      ilGen.Ldarg_CallFrame();
      ilGen.Ldarg_1();
      ilGen.Ldc_I4((int)nodeType);
      ilGen.Ldc_I4(resultIndex);
      ilGen.Ldloc(t0);
      ilGen.Ldc_I4(i0TypeCheck);
      ilGen.Call(CodeGen.Types.Operations.ICMethods.RunAndUpdateUnaryOperationIC);
      ilGen.Ret();

      ilGen.MarkLabel(done);
    }
开发者ID:reshadi2,项目名称:mcjs,代码行数:60,代码来源:ICMethods.cs

示例6: 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

示例7: EmitGetVar

        static void EmitGetVar(ILGen gen, FieldBuilder fb)
        {
            Label falseLabel = gen.DefineLabel();
            Label endLabel = gen.DefineLabel();

            gen.EmitFieldGet(fb);                       // gen.Emit(OpCodes.Ldsfld,fb);
            gen.Emit(OpCodes.Dup);
            gen.EmitCall(Method_Var_isBound);           // gen.Emit(OpCodes.Call, Method_Var_IsBound);
            gen.Emit(OpCodes.Brfalse_S,falseLabel);
            gen.Emit(OpCodes.Call,Method_Var_get);
            gen.Emit(OpCodes.Br_S,endLabel);
            gen.MarkLabel(falseLabel);
            gen.Emit(OpCodes.Pop);
            gen.EmitNull();                             // gen.Emit(OpCodes.Ldnull);
            gen.MarkLabel(endLabel);
        }
开发者ID:ragnard,项目名称:clojure-clr,代码行数:16,代码来源:GenClass.cs

示例8: 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

示例9: GenerateProxyMethod

        private static void GenerateProxyMethod(
            TypeBuilder proxyTB,
            FieldBuilder mapField,
            MethodInfo m,
            HashSet<MethodBuilder> specialMethods)
        {
            MethodAttributes attribs = m.Attributes;

            bool callBaseMethod;

            if ( (attribs & MethodAttributes.Abstract) == MethodAttributes.Abstract )
            {
                attribs &= ~MethodAttributes.Abstract;
                callBaseMethod = false;
            }
            else
            {
                callBaseMethod = true;

            }

            attribs &= ~MethodAttributes.NewSlot;
            attribs |= MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Public;

            //Console.Write("Generating proxy method {0}(", m.Name);
            //foreach (ParameterInfo p in m.GetParameters())
            //    Console.Write("{0}, ", p.ParameterType.FullName);
            //Console.Write(") ");
            //Console.WriteLine(attribs.ToString());

            MethodBuilder proxym = proxyTB.DefineMethod(
                m.Name,
                attribs,
                m.CallingConvention,
                m.ReturnType,
                m.GetParameters().Select<ParameterInfo, Type>(p => p.ParameterType).ToArray<Type>());

            if (m.IsSpecialName)
                specialMethods.Add(proxym);

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

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

            //// Print a little message, for debugging purposes
            //gen.Emit(OpCodes.Ldstr, String.Format("Calling {0} / {1}", proxyTB.FullName, m.ToString()));
            //gen.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine",
            //    new Type[] { typeof(string) }));
            //gen.Emit(OpCodes.Call, typeof(Console).GetMethod("get_Out"));
            //gen.Emit(OpCodes.Call, typeof(System.IO.TextWriter).GetMethod("Flush"));

            // Lookup method name in map
            gen.EmitLoadArg(0);                             // gen.Emit(OpCodes.Ldarg_0);
            gen.EmitFieldGet(mapField);                     // gen.Emit(OpCodes.Ldfld, mapField);
            gen.EmitString(m.Name);                         // gen.Emit(OpCodes.Ldstr, m.Name);
            gen.EmitCall(Method_RT_get);                    // gen.Emit(OpCodes.Call, Method_RT_get);
            gen.Emit(OpCodes.Dup);
            gen.EmitNull();                                 // gen.Emit(OpCodes.Ldnull);
            gen.Emit(OpCodes.Beq_S, elseLabel);

            // map entry found
            ParameterInfo[] pinfos = m.GetParameters();
            gen.Emit(OpCodes.Castclass, typeof(IFn));
            gen.EmitLoadArg(0);                             // gen.Emit(OpCodes.Ldarg_0);  // push implicit 'this' arg.
            for (int i = 0; i < pinfos.Length; i++)
            {
                gen.EmitLoadArg(i + 1);                     // gen.Emit(OpCodes.Ldarg, i + 1);
                if (m.GetParameters()[i].ParameterType.IsValueType)
                    gen.Emit(OpCodes.Box,pinfos[i].ParameterType);
            }

            int parmCount = pinfos.Length;
            gen.EmitCall(GetIFnInvokeMethodInfo(parmCount+1));        // gen.Emit(OpCodes.Call, GetIFnInvokeMethodInfo(parmCount + 1));
            if (m.ReturnType == typeof(void))
                gen.Emit(OpCodes.Pop);
            else
                gen.Emit(OpCodes.Unbox_Any, m.ReturnType);

            gen.Emit(OpCodes.Br_S,endLabel);

            // map entry not found
            gen.MarkLabel(elseLabel);
            gen.Emit(OpCodes.Pop); // get rid of null leftover from the 'get'

            if ( callBaseMethod )
            {
                gen.EmitLoadArg(0);                                     // gen.Emit(OpCodes.Ldarg_0);
                for (int i = 0; i < parmCount; i++)
                    gen.EmitLoadArg(i + 1);                             // gen.Emit(OpCodes.Ldarg, i + 1);
                gen.Emit(OpCodes.Call, m);                              // gen.EmitCall(m) improperly emits a callvirt in some cases
            }
            else
            {
                gen.EmitString(m.Name);                                 // gen.Emit(OpCodes.Ldstr, m.Name);
                gen.EmitNew(CtorInfo_NotImplementedException_1);        // gen.Emit(OpCodes.Newobj, CtorInfo_NotImplementedException_1);
                gen.Emit(OpCodes.Throw);
            }

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

示例10: 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

示例11: EmitConvertFromObject

        /// <summary>
        /// Emit code to convert object to a given type. This code is semantically equivalent
        /// to PythonBinder.EmitConvertFromObject, except this version accepts ILGen whereas
        /// PythonBinder accepts Compiler. The Binder will chagne soon and the two will merge.
        /// </summary>
        public void EmitConvertFromObject(ILGen il, Type toType) {
            if (toType == typeof(object)) return;

            MethodInfo fastConvertMethod = GetFastConvertMethod(toType);
            if (fastConvertMethod != null) {
                il.EmitCall(fastConvertMethod);
            } else if (toType == typeof(void)) {
                il.Emit(OpCodes.Pop);
            } else if (typeof(Delegate).IsAssignableFrom(toType)) {
                il.EmitType(toType);
                il.EmitCall(ConvertToDelegate());
                il.Emit(OpCodes.Castclass, toType);
            } else {
                Label end = il.DefineLabel();
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Isinst, toType);

                il.Emit(OpCodes.Brtrue_S, end);
                il.Emit(OpCodes.Ldtoken, toType);
                il.EmitCall(GetGenericConvertMethod(toType));
                il.MarkLabel(end);

                il.Emit(OpCodes.Unbox_Any, toType); //??? this check may be redundant
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:30,代码来源:ClsTypeEmitter.cs

示例12: EmitBaseClassCallCheckForProperties

        /// <summary>
        /// Emits code to check if the class has overridden this specific
        /// function.  For example:
        /// 
        /// MyDerivedType.SomeVirtualFunction = ...
        ///     or
        /// 
        /// class MyDerivedType(MyBaseType):
        ///     def SomeVirtualFunction(self, ...):
        /// 
        /// </summary>
        internal LocalBuilder EmitBaseClassCallCheckForProperties(ILGen il, MethodInfo baseMethod, string name) {
            Label instanceCall = il.DefineLabel();
            LocalBuilder callTarget = il.DeclareLocal(typeof(object));

            il.EmitLoadArg(0);
            EmitClassObjectFromInstance(il);
            il.EmitLoadArg(0);
            il.Emit(OpCodes.Ldstr, name);
            il.Emit(OpCodes.Ldloca, callTarget);
            il.EmitCall(NonInheritedValueHelper());

            il.Emit(OpCodes.Brtrue, instanceCall);

            EmitBaseMethodDispatch(baseMethod, il);

            il.MarkLabel(instanceCall);

            return callTarget;
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:30,代码来源:ClsTypeEmitter.cs

示例13: EmitConvertFromObject

        /// <summary>
        /// Emit code to convert object to a given type. This code is semantically equivalent
        /// to PythonBinder.EmitConvertFromObject, except this version accepts ILGen whereas
        /// PythonBinder accepts Compiler. The Binder will chagne soon and the two will merge.
        /// </summary>
        private static void EmitConvertFromObject(ILGen il, Type toType) {
            if (toType == typeof(object)) return;
            if (toType.IsGenericParameter) {
                il.EmitCall(typeof(PythonOps).GetMethod("ConvertFromObject").MakeGenericMethod(toType));
                return;
            }

            MethodInfo fastConvertMethod = PythonBinder.GetFastConvertMethod(toType);
            if (fastConvertMethod != null) {
                il.EmitCall(fastConvertMethod);
            } else if (toType == typeof(void)) {
                il.Emit(OpCodes.Pop);
            } else if (typeof(Delegate).IsAssignableFrom(toType)) {
                il.EmitType(toType);
                il.EmitCall(typeof(Converter), "ConvertToDelegate");
                il.Emit(OpCodes.Castclass, toType);
            } else {
                Label end = il.DefineLabel();
                il.Emit(OpCodes.Dup);
                il.Emit(OpCodes.Isinst, toType);

                il.Emit(OpCodes.Brtrue_S, end);
                il.Emit(OpCodes.Ldtoken, toType);
                il.EmitCall(PythonBinder.GetGenericConvertMethod(toType));
                il.MarkLabel(end);

                il.Emit(OpCodes.Unbox_Any, toType); //??? this check may be redundant
            }
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:34,代码来源:NewTypeMaker.cs

示例14: EmitBaseClassCallCheckForEvents

        /// <summary>
        /// Emits code to check if the class has overridden this specific
        /// function.  For example:
        /// 
        /// MyDerivedType.SomeVirtualFunction = ...
        ///     or
        /// 
        /// class MyDerivedType(MyBaseType):
        ///     def SomeVirtualFunction(self, ...):
        /// 
        /// </summary>
        private LocalBuilder EmitBaseClassCallCheckForEvents(ILGen il, MethodInfo baseMethod, string name) {
            Label instanceCall = il.DefineLabel();
            LocalBuilder callTarget = il.DeclareLocal(typeof(object));

            il.EmitLoadArg(0);
            EmitSymbolId(il, name);
            il.Emit(OpCodes.Ldloca, callTarget);
            il.EmitCall(typeof(UserTypeOps), "TryGetNonInheritedValueHelper");

            il.Emit(OpCodes.Brtrue, instanceCall);

            EmitBaseMethodDispatch(baseMethod, il);

            il.MarkLabel(instanceCall);

            return callTarget;
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:28,代码来源:NewTypeMaker.cs

示例15: 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,代码来源:


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