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


C# CodeGen.EmitUninitialized方法代码示例

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


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

示例1: EmitCheck

        public virtual void EmitCheck(CodeGen cg, SymbolId name)
        {
            Contract.RequiresNotNull(cg, "cg");

            Label endCheck = cg.DefineLabel();
            cg.Emit(OpCodes.Dup);
            cg.EmitUninitialized();
            cg.Emit(OpCodes.Bne_Un_S, endCheck);
            if (_local) {
                cg.EmitSymbolId(name);
                cg.EmitUnbox(typeof(SymbolId));
                cg.EmitCall(typeof(RuntimeHelpers), "ThrowUnboundLocalError");
            } else {
                cg.Emit(OpCodes.Pop);
                cg.EmitCodeContext();
                cg.EmitSymbolId(name);
                cg.EmitUnbox(typeof(SymbolId));
                cg.EmitCall(typeof(RuntimeHelpers), "LookupName");
            }
            cg.MarkLabel(endCheck);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:21,代码来源:Slot.cs

示例2: EmitSetUninitialized

        // Slots are to be implemented as dictionaries for Python. However,
        // for performance and better integration with the CLI, the engine
        // implements many Slot types as CLI entities, which cannot be
        // deleted once they are created. Hence, to implement "del",
        // an alternate scheme is used. We just assign Uninitialized.instance
        // to represent that the Slot has been deleted.
        // Any access to the Slot first checks if it is holding Uninitialized.instance,
        // which means that it should virtually not exist
        public virtual void EmitSetUninitialized(CodeGen cg)
        {
            Contract.RequiresNotNull(cg, "cg");

            // Emit the following:
            //     <name> = Uninitialized.instance;

            Debug.Assert(Type == typeof(object));

            cg.EmitUninitialized();
            EmitSet(cg);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:20,代码来源:Slot.cs

示例3: OverrideConstructor

        private ConstructorBuilder OverrideConstructor(ConstructorInfo parentConstructor)
        {
            ParameterInfo[] pis = parentConstructor.GetParameters();
            ParameterInfo[] overrideParams = GetOverrideCtorSignature(pis);

            Type[] argTypes = new Type[overrideParams.Length];
            string[] paramNames = new string[overrideParams.Length];
            for (int i = 0; i < overrideParams.Length; i++) {
                argTypes[i] = overrideParams[i].ParameterType;
                paramNames[i] = overrideParams[i].Name;
            }

            ConstructorBuilder cb = tg.myType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, argTypes);

            for (int i = 0; i < overrideParams.Length; i++) {
                ParameterBuilder pb = cb.DefineParameter(i + 1,
                    overrideParams[i].Attributes,
                    overrideParams[i].Name);

                int origIndex = i - (overrideParams.Length - pis.Length);
                if (origIndex >= 0) {
                    if (pis[origIndex].IsDefined(typeof(ParamArrayAttribute), false)) {
                        pb.SetCustomAttribute(new CustomAttributeBuilder(
                            typeof(ParamArrayAttribute).GetConstructor(Type.EmptyTypes), Ops.EMPTY));
                    } else if (pis[origIndex].IsDefined(typeof(ParamDictAttribute), false)) {
                        pb.SetCustomAttribute(new CustomAttributeBuilder(
                            typeof(ParamDictAttribute).GetConstructor(Type.EmptyTypes), Ops.EMPTY));
                    }
                }
            }

            CodeGen cg = new CodeGen(tg, cb, cb.GetILGenerator(), argTypes);

            // <typeField> = <arg0>
            cg.EmitArgGet(0);
            typeField.EmitSet(cg);

            // initialize all slots to Uninitialized.instance
            if (slots != null) {
                for (int i = 0; i < slots.Count; i++) {
                    if (slots[i] != "__weakref__" && slots[i] != "__dict__") {
                        cg.EmitUninitialized();
                    } else {
                        cg.Emit(OpCodes.Ldnull);
                    }
                    slotsSlots[i].EmitSet(cg);
                }
            }

            CallBaseConstructor(parentConstructor, overrideParams.Length - pis.Length, overrideParams, cg);
            return cb;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:52,代码来源:NewTypeMaker.cs

示例4: EmitSetUninitialized

 // Slots are to be implemented as dictionaries for Python. However,
 // for performance and better integration with the CLI, the engine
 // implements many Slot types as CLI entities, which cannot be
 // deleted once they are created. Hence, to implement "del",
 // an alternate scheme is used. We just assign Uninitialized.instance
 // to represent that the Slot has been deleted.
 // Any access to the Slot first checks if it is holding Uninitialized.instance,
 // which means that it should virtually not exist
 public virtual void EmitSetUninitialized(CodeGen cg, SymbolId name)
 {
     // Emit the following:
     //     <name> = Uninitialized.instance;
     cg.EmitUninitialized();
     EmitSet(cg);
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:15,代码来源:Slot.cs

示例5: EmitCheck

 public virtual void EmitCheck(CodeGen cg, SymbolId name)
 {
     if (Options.CheckInitialized) {
         if (local) {
             Label endCheck = cg.DefineLabel();
             cg.Emit(OpCodes.Dup);
             cg.EmitUninitialized();
             cg.Emit(OpCodes.Bne_Un_S, endCheck);
             cg.EmitName(name);
             cg.EmitCall(typeof(Ops), "ThrowUnboundLocalError");
             cg.MarkLabel(endCheck);
         } else {
             cg.EmitCallerContext();
             cg.EmitName(name);
             cg.EmitCall(typeof(Ops), "CheckInitializedOrBuiltin");
         }
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:18,代码来源:Slot.cs

示例6: EmitGet

        public override void EmitGet(CodeGen cg)
        {
            //
            // if ($env.TryGetValue(name, out local) && local != Uninitialized.instance) {
            //     local
            // } else {
            //     global
            // }

            Slot local = cg.GetLocalTmp(typeof(object));
            Label notFound = cg.DefineLabel();
            Label found = cg.DefineLabel();
            environment.EmitGet(cg);
            cg.EmitName(name);
            local.EmitGetAddr(cg);
            cg.EmitCall(typeof(IDictionary<object, object>).GetMethod("TryGetValue"));
            cg.Emit(OpCodes.Brfalse_S, notFound);
            local.EmitGet(cg);
            cg.EmitUninitialized();
            cg.Emit(OpCodes.Beq_S, notFound);
            local.EmitGet(cg);
            cg.Emit(OpCodes.Br_S, found);
            cg.MarkLabel(notFound);
            global.EmitGet(cg);
            cg.MarkLabel(found);
            cg.FreeLocalTmp(local);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:27,代码来源:Slot.cs


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