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


C# ObjExpr.EmitConstants方法代码示例

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


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

示例1: Compile

        public static object Compile(GenContext context,TextReader rdr, string sourceDirectory, string sourceName, string relativePath)
        {
            object eofVal = new object();
            object form;

            string sourcePath = relativePath;

            // generate loader class
            ObjExpr objx = new ObjExpr(null);
            var internalName = sourcePath.Replace(Path.PathSeparator, '/').Substring(0, sourcePath.LastIndexOf('.'));
            objx.InternalName = internalName + "__init";

            TypeBuilder initTB = context.AssemblyGen.DefinePublicType(InitClassName(internalName), typeof(object), true);
            context = context.WithTypeBuilder(initTB);

            // static load method
            MethodBuilder initMB = initTB.DefineMethod("Initialize", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Type.EmptyTypes);
            CljILGen ilg = new CljILGen(initMB.GetILGenerator());

            LineNumberingTextReader lntr = rdr as LineNumberingTextReader ?? new LineNumberingTextReader(rdr);

            Var.pushThreadBindings(RT.mapUniqueKeys(
                SourcePathVar, sourcePath,
                SourceVar, sourceName,
                MethodVar, null,
                LocalEnvVar, null,
                LoopLocalsVar, null,
                NextLocalNumVar, 0,
                RT.ReadEvalVar, true /* RT.T */,
                RT.CurrentNSVar, RT.CurrentNSVar.deref(),
                ConstantsVar, PersistentVector.EMPTY,
                ConstantIdsVar, new IdentityHashMap(),
                KeywordsVar, PersistentHashMap.EMPTY,
                VarsVar, PersistentHashMap.EMPTY,
                RT.UncheckedMathVar, RT.UncheckedMathVar.deref(),
                RT.WarnOnReflectionVar, RT.WarnOnReflectionVar.deref(),
                RT.DataReadersVar, RT.DataReadersVar.deref(),
                CompilerContextVar, context,
                CompilerActiveVar, true
                ));

            try
            {
                Object readerOpts = ReaderOpts(sourceName);

                while ((form = LispReader.read(lntr, false, eofVal, false, readerOpts)) != eofVal)
                {
                    Compile1(initTB, ilg, objx, form);
                }

                initMB.GetILGenerator().Emit(OpCodes.Ret);

                // static fields for constants
                objx.EmitConstantFieldDefs(initTB);
                MethodBuilder constInitsMB = objx.EmitConstants(initTB);

                // Static init for constants, keywords, vars
                ConstructorBuilder cb = initTB.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
                ILGenerator cbGen = cb.GetILGenerator();

                cbGen.BeginExceptionBlock();

                cbGen.Emit(OpCodes.Call,Method_Compiler_PushNS);
                cbGen.Emit(OpCodes.Call, constInitsMB);

                cbGen.BeginFinallyBlock();
                cbGen.Emit(OpCodes.Call, Method_Var_popThreadBindings);

                cbGen.EndExceptionBlock();
                cbGen.Emit(OpCodes.Ret);

                var descAttrBuilder =
                 new CustomAttributeBuilder(typeof (DescriptionAttribute).GetConstructor(new[] {typeof (String)}),
                                           new [] {String.Format("{{:clojure-namespace {0}}}", CurrentNamespace)});
                initTB.SetCustomAttribute(descAttrBuilder);

                initTB.CreateType();
            }
            catch (LispReader.ReaderException e)
            {
                throw new CompilerException(sourcePath, e.Line,  e.Column, e.InnerException);
            }
            finally
            {
                Var.popThreadBindings();
            }
            return null;
        }
开发者ID:rvedam,项目名称:clojure-clr,代码行数:88,代码来源:Compiler.cs

示例2: Compile

        public static object Compile(TextReader rdr, string sourceDirectory, string sourceName, string relativePath)
        {
            if (CompilePathVar.deref() == null)
                throw new InvalidOperationException("*compile-path* not set");

            object eofVal = new object();
            object form;

            string sourcePath = relativePath;
            GenContext context = GenContext.CreateWithExternalAssembly(sourceName, sourcePath, ".dll", true);

            // generate loader class
            ObjExpr objx = new ObjExpr(null);
            objx.InternalName = sourcePath.Replace(Path.PathSeparator, '/').Substring(0, sourcePath.LastIndexOf('.')) + "__init";

            TypeBuilder initTB = context.AssemblyGen.DefinePublicType("__Init__", typeof(object), true);
            context = context.WithTypeBuilder(initTB);

            // static load method
            MethodBuilder initMB = initTB.DefineMethod("Initialize", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Type.EmptyTypes);
            CljILGen ilg = new CljILGen(initMB.GetILGenerator());

            LineNumberingTextReader lntr = rdr as LineNumberingTextReader ?? new LineNumberingTextReader(rdr);

            Var.pushThreadBindings(RT.map(
                SourcePathVar, sourcePath,
                SourceVar, sourceName,
                MethodVar, null,
                LocalEnvVar, null,
                LoopLocalsVar, null,
                NextLocalNumVar, 0,
                RT.CurrentNSVar, RT.CurrentNSVar.deref(),
                ConstantsVar, PersistentVector.EMPTY,
                ConstantIdsVar, new IdentityHashMap(),
                KeywordsVar, PersistentHashMap.EMPTY,
                VarsVar, PersistentHashMap.EMPTY,
                RT.UncheckedMathVar, RT.UncheckedMathVar.deref(),
                RT.WarnOnReflectionVar, RT.WarnOnReflectionVar.deref(),
                RT.DataReadersVar, RT.DataReadersVar.deref(),
                CompilerContextVar, context,
                CompilerActiveVar, true
                ));

            try
            {
                while ((form = LispReader.read(lntr, false, eofVal, false)) != eofVal)
                {
                    Compile1(initTB, ilg, objx, form);
                }

                initMB.GetILGenerator().Emit(OpCodes.Ret);

                // static fields for constants
                objx.EmitConstantFieldDefs(initTB);
                MethodBuilder constInitsMB = objx.EmitConstants(initTB);

                // Static init for constants, keywords, vars
                ConstructorBuilder cb = initTB.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
                ILGenerator cbGen = cb.GetILGenerator();

                cbGen.BeginExceptionBlock();

                cbGen.Emit(OpCodes.Call,Method_Compiler_PushNS);
                cbGen.Emit(OpCodes.Call, constInitsMB);

                cbGen.BeginFinallyBlock();
                cbGen.Emit(OpCodes.Call, Method_Var_popThreadBindings);

                cbGen.EndExceptionBlock();
                cbGen.Emit(OpCodes.Ret);

                initTB.CreateType();

                context.SaveAssembly();
            }
            catch (LispReader.ReaderException e)
            {
                throw new CompilerException(sourcePath, e.Line, e.InnerException);
            }
            finally
            {
                Var.popThreadBindings();
            }
            return null;
        }
开发者ID:billzhuang,项目名称:clojure-clr,代码行数:85,代码来源:Compiler.cs


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