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


C# CodeGen.EmitNew方法代码示例

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


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

示例1: Emit

        public override void Emit(CodeGen cg) {
          if (_valueTypeType != null)
          {
            EmitLocation(cg);
            cg.EmitMissingValue(_valueTypeType); // seems ok?
          }
          else
          {
            for (int i = 0; i < _parameterInfos.Length; i++)
            {
              _arguments[i].Emit(cg);
              if (_arguments[i].Type != _parameterInfos[i].ParameterType && _arguments[i].Type.IsValueType && typeof(SymbolId) != _arguments[i].Type)
              {
                cg.EmitBoxing(_arguments[i].Type);
              }

            }
            EmitLocation(cg);
            cg.EmitNew(_constructor);
          }
          if (ScriptDomainManager.Options.LightweightDebugging && Span.IsValid)
          {
            cg.EmitConstant(SpanToLong(Span));
            cg.EmitCall(Debugging.DebugMethods.ExpressionOut);
          }
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:26,代码来源:NewExpression.cs

示例2: EmitArgument

 public static ReturnFixer EmitArgument(CodeGen cg, Slot argSlot)
 {
     argSlot.EmitGet(cg);
     if (argSlot.Type.IsByRef) {
         Type elementType = argSlot.Type.GetElementType();
         Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
         Slot refSlot = cg.GetLocalTmp(concreteType);
         cg.EmitLoadValueIndirect(elementType);
         cg.EmitNew(concreteType, new Type[] { elementType });
         refSlot.EmitSet(cg);
         refSlot.EmitGet(cg);
         return new ReturnFixer(refSlot, argSlot);
     } else {
         cg.EmitBoxing(argSlot.Type);
         return null;
     }
 }
开发者ID:robertlj,项目名称:IronScheme,代码行数:17,代码来源:ReturnFixer.cs

示例3: EmitNewEnvironment

        public override void EmitNewEnvironment(CodeGen cg)
        {
            ConstructorInfo ctor = EnvironmentType.GetConstructor(new Type[] {StorageType});

              // emit: dict.Tuple[.Item000...].Item000 = dict, and then leave dict on the stack

              cg.EmitNew(ctor);
              cg.Emit(OpCodes.Dup);

              Slot tmp = cg.GetLocalTmp(EnvironmentType);
              tmp.EmitSet(cg);

              cg.EmitPropertyGet(EnvironmentType, "Data");

              var fld = StorageType.GetField("$parent$");

              //cg.EmitFieldGet(fld);

              tmp.EmitGet(cg);
              cg.EmitFieldSet(fld);

              cg.FreeLocalTmp(tmp);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:23,代码来源:PropertyEnvironmentFactory.cs

示例4: EmitGeneratorBody

        private void EmitGeneratorBody(CodeGen cg, CodeGen ocg)
        {
            // Create the GenerateNext function
            CodeGen ncg = cg.DefineMethod(name.GetString() + "$g" + counter++, typeof(bool),
                new Type[] { typeof(Generator), typeof(object).MakeByRefType() },
                new String[] { "$gen", "$ret" });
            ncg.Context = cg.Context;

            PromoteLocalsToEnvironment();
            ncg.FuncOrClassName = name.ToString();
            ncg.EmitSetTraceBackUpdateStatus(false);

            // Namespace without er factory - all locals must exist ahead of time
            ncg.Names = new Namespace(null);
            Slot generator = ncg.GetArgumentSlot(0);
            ncg.StaticLinkSlot = new FieldSlot(generator, typeof(Generator).GetField("staticLink"));
            if (HasEnvironment) {
                cg.EnvironmentSlot = CreateEnvironment(cg);
                EnvironmentFactory ef = this.environmentFactory;
                Slot envSlotCast = new CastSlot(
                    new FieldSlot(generator, typeof(Generator).GetField("environment")),
                    ef.EnvironmentType
                    );
                Slot envSlot = ncg.GetLocalTmp(ef.EnvironmentType);
                // setup the environment and static link slots
                ncg.EnvironmentSlot = envSlot;
                ncg.ContextSlot = envSlot;
                // pull the environment into typed local variable
                envSlot.EmitSet(ncg, envSlotCast);
                InheritEnvironment(ncg);
                CreateGeneratorTemps(ef, ncg);
            } else {
                ncg.ContextSlot = ncg.StaticLinkSlot;
            }
            ncg.ModuleSlot = new PropertySlot(ncg.ContextSlot, typeof(ICallerContext).GetProperty("Module"));

            CreateClosureSlots(ncg);
            CreateGlobalSlots(ncg, ocg);

            // Emit the generator body using the typed er
            EmitGenerator(ncg);

            // Initialize the generator
            EmitTupleParams(cg);

            // Create instance of the generator
            cg.EmitStaticLinkOrNull();
            cg.EmitEnvironmentOrNull();
            cg.EmitDelegate(ncg, typeof(Generator.NextTarget), null);
            cg.EmitNew(typeof(Generator), new Type[] { typeof(FunctionEnvironmentDictionary), typeof(FunctionEnvironmentDictionary), typeof(Generator.NextTarget) });
            cg.EmitReturn();
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:52,代码来源:FuncDef.cs

示例5: CreateEnvironment

        internal Slot CreateEnvironment(CodeGen cg)
        {
            // Get the environment size
            int size = CalculateEnvironmentSize();

            // Find the right environment type
            ConstructorInfo ctor;
            EnvironmentFactory esf;
            Type envType = GetEnvironmentType(size, cg, out ctor, out esf);

            // Emit the static link for the environment constructor
            cg.EmitStaticLinkOrNull();
            cg.EmitCallerContext();
            // Emit the names array for the environment constructor
            EmitEnvironmentIDs(cg);
            EmitOuterLocalIDs(cg);
            cg.EmitNew(ctor);

            // Store the environment reference in the local
            Slot environmentSlot = cg.GetFrameSlot(envType);
            environmentSlot.EmitSet(cg);

            // Remember the environment factory for parent access
            environmentFactory = esf;

            // Create environment references
            environment = new Dictionary<SymbolId, EnvironmentReference>();

            foreach (KeyValuePair<SymbolId, Binding> kv in names) {
                if (!kv.Value.IsEnvironment) continue;
                SymbolId name = kv.Key;
                EnvironmentReference er = esf.MakeEnvironmentReference(name);
                Slot slot = er.CreateSlot(environmentSlot);
                Slot current;
                if (cg.Names.Slots.TryGetValue(name, out current)) {
                    slot.EmitSet(cg, current);
                } else {
                    slot.EmitSetUninitialized(cg, name);
                }

                // The full slot goes to the codegen's namespace
                cg.Names.SetSlot(name, slot);
                // Environment reference goes to the environment
                environment[name] = er;
            }

            return environmentSlot;
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:48,代码来源:ScopeStatement.cs

示例6: EmitMissingValue

            private static void EmitMissingValue(CodeGen cg, Type type)
            {
                switch (Type.GetTypeCode(type)) {
                    default:
                    case TypeCode.Object:
                        // struct
                        if (type.IsSealed && type.IsValueType && !type.IsEnum) {
                            Slot s = cg.GetLocalTmp(type);
                            s.EmitGetAddr(cg);
                            cg.Emit(OpCodes.Initobj, type);
                            s.EmitGet(cg);
                        } else if (type == typeof(object)) {
                            // parameter of type object receives the actual Missing value
                            cg.Emit(OpCodes.Ldsfld, typeof(Missing).GetField("Value"));
                        } else if (!type.IsValueType) {
                            cg.Emit(OpCodes.Ldnull);
                        } else {
                            EmitException(cg, "Cannot create default value for type {0}", type);
                        }
                        break;

                    case TypeCode.Empty:
                    case TypeCode.DBNull:
                        cg.Emit(OpCodes.Ldnull);
                        break;

                    case TypeCode.Boolean:
                    case TypeCode.Char:
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                        cg.Emit(OpCodes.Ldc_I4_0); break;

                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        cg.Emit(OpCodes.Ldc_I4_0);
                        cg.Emit(OpCodes.Conv_I8);
                        break;

                    case TypeCode.Single:
                        cg.Emit(OpCodes.Ldc_R4, default(Single));
                        break;
                    case TypeCode.Double:
                        cg.Emit(OpCodes.Ldc_R8, default(Double));
                        break;
                    case TypeCode.Decimal:
                        cg.Emit(OpCodes.Ldc_I4_0);
                        cg.EmitNew(typeof(Decimal).GetConstructor(new Type[] { typeof(int) }));
                        break;
                    case TypeCode.DateTime:
                        Slot dt = cg.GetLocalTmp(typeof(DateTime));
                        dt.EmitGetAddr(cg);
                        cg.Emit(OpCodes.Initobj, typeof(DateTime));
                        dt.EmitGet(cg);
                        break;
                    case TypeCode.String:
                        cg.Emit(OpCodes.Ldnull); break;
                }
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:62,代码来源:MethodBinder.cs

示例7: GenerateCall

            private Type GenerateCall(CodeGen cg)
            {
                MethodInfo mi = method.Method as MethodInfo;

                if (mi != null) {
                    cg.EmitCall(mi);
                    return mi.ReturnType;
                } else {
                    cg.EmitNew((ConstructorInfo)method.Method);
                    return ((ConstructorInfo)method.Method).DeclaringType;
                }
            }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:12,代码来源:MethodBinder.cs

示例8: EmitGeneratorBody

        /// <summary>
        /// Emits the body of the function that creates a Generator object.  Also creates another
        /// CodeGen for the inner method which implements the user code defined in the generator.
        /// </summary>
        private void EmitGeneratorBody(CodeGen _impl)
        {
            CodeGen ncg = CreateMethod(_impl);
            ncg.EmitLineInfo = _impl.EmitLineInfo;

            ncg.Allocator.GlobalAllocator.PrepareForEmit(ncg);

            Slot flowedContext = _impl.ContextSlot;
            // If there are no locals in the generator than we don't need the environment
            if (HasEnvironment) {
                // Environment creation is emitted into outer function that returns the generator
                // function and then flowed into the generator method on each call via the Generator
                // instance.
                _impl.EnvironmentSlot = EmitEnvironmentAllocation(_impl);
                flowedContext = CreateEnvironmentContext(_impl);

                InitializeGeneratorEnvironment(_impl);

                // Promote env storage to local variable
                // envStorage = ((FunctionEnvironment)context.Locals).Tuple
                EnvironmentFactory.EmitGetStorageFromContext(ncg);

                ncg.EnvironmentSlot = EnvironmentFactory.CreateEnvironmentSlot(ncg);
                ncg.EnvironmentSlot.EmitSet(ncg);

                CreateGeneratorTemps(ncg);
            }

            CreateReferenceSlots(ncg);

            // Emit the generator body
            EmitGenerator(ncg);

            flowedContext.EmitGet(_impl);
            _impl.EmitDelegateConstruction(ncg, _next, false);
            _impl.EmitNew(_generator, new Type[] { typeof(CodeContext), _next });
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:41,代码来源:GeneratorCodeBlock.cs

示例9: EmitNestedTupleInit

        private static void EmitNestedTupleInit(CodeGen cg, Type storageType)
        {
            if (Tuple.GetSize(storageType) > Tuple.MaxSize)
              {

            Slot tmp = cg.GetLocalTmp(storageType);
            tmp.EmitSet(cg);

            Type[] nestedTuples = storageType.GetGenericArguments();
            for (int i = 0; i < nestedTuples.Length; i++)
            {
              Type t = nestedTuples[i];
              if (t.IsSubclassOf(typeof(Tuple)))
              {
                tmp.EmitGet(cg);

                cg.EmitNew(t.GetConstructor(ArrayUtils.EmptyTypes));
                cg.EmitPropertySet(storageType, String.Format("Item{0:D3}", i));

                tmp.EmitGet(cg);
                cg.EmitPropertyGet(storageType, String.Format("Item{0:D3}", i));

                EmitNestedTupleInit(cg, t);
              }
            }

            cg.FreeLocalTmp(tmp);
              }
              else
              {
            int capacity = 0;
            foreach (Type t in storageType.GetGenericArguments())
            {
              if (t == typeof(None))
              {
                break;
              }
              capacity++;
            }
            cg.EmitInt(capacity);
            cg.EmitCall(typeof(RuntimeHelpers), "UninitializeEnvironmentTuple");
              }
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:43,代码来源:PropertyEnvironmentFactory.cs

示例10: EmitStorage

 public override void EmitStorage(CodeGen cg)
 {
     cg.EmitNew(StorageType.GetConstructor(ArrayUtils.EmptyTypes));
     //cg.Emit(OpCodes.Dup);
     //EmitNestedTupleInit(cg, StorageType);
 }
开发者ID:robertlj,项目名称:IronScheme,代码行数:6,代码来源:PropertyEnvironmentFactory.cs

示例11: EmitCreation

 public override void EmitCreation(CodeGen cg)
 {
     cg.EmitConstant(new FractionConstant(value.Real));
       cg.EmitConstant(new FractionConstant(value.Imag));
       cg.EmitNew(typeof(ComplexFraction), new Type[] { typeof(Fraction), typeof(Fraction) });
 }
开发者ID:tshaug,项目名称:IronScheme,代码行数:6,代码来源:IronSchemeConstant.cs

示例12: EmitModuleConstruction

        /// <summary>
        /// Emits a call into the PythonModule to register this module, and then
        /// returns the resulting PythonModule 
        /// </summary>
        public static void EmitModuleConstruction(TypeGen tg, CodeGen main, string moduleName, Slot initialize, IList<string> referencedAssemblies)
        {
            // calling PythonModule InitializeModule(CustomDict compiled, string fullName)

            main.EmitNew(tg.DefaultConstructor); // Emit instance for the InitializeModule call (compiled)

            initialize.EmitSet(main);
            initialize.EmitGet(main);

            main.EmitString(moduleName);         // emit module name (fullName)

            // emit the references assemblies
            if (referencedAssemblies != null) {
                for (int i = 0; i < referencedAssemblies.Count; i++) {
                    if (referencedAssemblies[i].ToLower().EndsWith("\\ironpython.dll")) {
                        referencedAssemblies.RemoveAt(i);
                        i--;
                    } else {
                        if (referencedAssemblies[i].IndexOf(Path.DirectorySeparatorChar) != -1) {
                            referencedAssemblies[i] = referencedAssemblies[i].Substring(referencedAssemblies[i].LastIndexOf(Path.DirectorySeparatorChar) + 1);
                        }

                        if (referencedAssemblies[i].ToLower().EndsWith(".dll")) {
                            referencedAssemblies[i] = referencedAssemblies[i].Substring(0, referencedAssemblies[i].Length - 4);
                        }
                    }
                }
                main.EmitStringArray(referencedAssemblies);
            } else main.Emit(OpCodes.Ldnull);

            // Call InitializeModule
            main.EmitCall(typeof(Ops), "InitializeModule");
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:37,代码来源:OutputGenerator.cs


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