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


C# ILGen.DefineLabel方法代码示例

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


在下文中一共展示了ILGen.DefineLabel方法的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: LabelInfo

        internal LabelInfo(ILGen il, LabelTarget node, bool canReturn) {
            _ilg = il;
            Node = node;
            Label = il.DefineLabel();
            _canReturn = canReturn;
            if (node != null && node.Type != typeof(void)) {
                Value = il.DeclareLocal(node.Type);
            }

            // Until we have more information, default to a leave instruction, which always works
            _opCode = OpCodes.Leave;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:LabelInfo.cs

示例3: GetBranch

 private Branch GetBranch(List<Branch> branches, ILGen il, Type type)
 {
     foreach (Branch b in branches)
         if (b.type == type)
             return b;
     Branch branch = new Branch();
     branch.type = type;
     branch.localVar = il.DeclareLocal(type);
     branch.handler = il.DefineLabel();
     branches.Add(branch);
     return branch;
 }
开发者ID:,项目名称:,代码行数:12,代码来源:

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

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

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

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

示例8: CompileExpr


//.........这里部分代码省略.........
             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)
                 {
                     body = GetFunc(name, true);
                     if (body == null)
                         throw new UnknownFuncCall(name.ToString());
                     else
                     {
                         LocalBuilder[] localVar = new LocalBuilder[parameterTypes.Length];
                         for (int k = localVar.Length - 1; k >= 0; k--)
                         {
                             localVar[k] = il.DeclareLocal(parameterTypes[k]);
                             il.Emit(OpCodes.Stloc, localVar[k]);
                         }
                         Type[] new_parameter_types = new Type[parameterTypes.Length];
                         for (int k = 0; k < localVar.Length; k++)
                         {
                             il.Emit(OpCodes.Ldloc, localVar[k]);
                             if (body.Name.GetParameterType(k) != parameterTypes[k])                                         
                             {
                                 if (parameterTypes[k].IsValueType)
                                     il.EmitBoxing(parameterTypes[k]);
                                 else if (ValueProxy.IsProxyType(parameterTypes[k]))
                                     il.EmitPropertyGet(typeof(ValueProxy), "Value");
                                 new_parameter_types[k] = typeof(System.Object);
                             }
                             else
                                 new_parameter_types[k] = parameterTypes[k];
                             il.FreeLocal(localVar[k]);
                         }
                         parameterTypes = new_parameter_types;
                     }
                 }
             }
             Type resType = body.Compile(this, il, locals, parameterTypes);
             if (resType == typeof(System.Boolean))
             { // Implict boolean convertion
                 Label l_false = il.DefineLabel();
                 Label end = il.DefineLabel();
                 il.Emit(OpCodes.Brfalse_S, l_false);
                 il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
                 il.Emit(OpCodes.Br_S, end);
                 il.MarkLabel(l_false);
                 il.EmitNull();
                 il.MarkLabel(end);
                 st.Push(typeof(System.Object));
             }
             else if (resType == typeof(void))
             { // assume that all procedures returns t
                 il.Emit(OpCodes.Ldsfld, typeof(RuntimeOps).GetField("True"));
                 st.Push(typeof(System.Object));
             }
             else
                 st.Push(resType);
         }
     }
     else
         if (Lisp.IsFunctor(Lisp.Car(lval), Lisp.LAMBDA))
         {
             object form = Lisp.Car(lval);
             object body = Lisp.Car(Lisp.Cddr(form));
             object tail = Lisp.Cdr(lval);
             LambdaExpr lambda = new LambdaExpr(null, CreateParameters(Lisp.Arg1(form)),
                 typeof(System.Object), body);
             List<Type> parameterTypesList = new List<Type>();
             foreach (object a in Lisp.getIterator(tail))
             {
                 CompileExpr(il, locals, st, a);
                 parameterTypesList.Add(st.Pop());
             }
             Type[] parameterTypes = parameterTypesList.ToArray();
             FuncName name = new FuncName(null, parameterTypes);
             if (!lambda.Name.Match(name, true))
                 throw new InvalidOperationException("Lambda parameters does not match");
             st.Push(lambda.Compile(this, il, locals, parameterTypes));
         }
         else
             throw new ArgumentException("Unproperly formated expression");
 }
开发者ID:,项目名称:,代码行数:101,代码来源:

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

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

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

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

示例13: Define

        // Returns true if the label was successfully defined
        // or false if the label is now ambiguous
        internal void Define(ILGen il, LabelBlockInfo block) {
            // Prevent the label from being shadowed, which enforces cleaner
            // trees. Also we depend on this for simplicity (keeping only one
            // active IL Label per LabelInfo)
            for (LabelBlockInfo j = block; j != null; j = j.Parent) {
                if (j.ContainsTarget(Node)) {
                    throw Error.LabelTargetAlreadyDefined(Node.Name);
                }
            }

            Definitions.Add(block);
            block.AddLabelInfo(Node, this);

            // Once defined, validate all jumps
            if (Definitions.Count == 1) {
                foreach (var r in References) {
                    ValidateJump(r);
                }
            } else {
                // Was just redefined, if we had any across block jumps, they're
                // now invalid
                if (_acrossBlockJump) {
                    throw Error.AmbiguousJump(Node.Name);
                }
                // For local jumps, we need a new IL label
                // This is okay because:
                //   1. no across block jumps have been made or will be made
                //   2. we don't allow the label to be shadowed
                Label = il.DefineLabel();
            }
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:33,代码来源:LabelInfo.cs

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

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


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