clojure.lang.CljCompiler.Ast.ObjExpr.EmitConstantFieldDefs C# (CSharp) Method

EmitConstantFieldDefs() public method

public EmitConstantFieldDefs ( TypeBuilder baseTB ) : void
baseTB System.Reflection.Emit.TypeBuilder
return void
        public void EmitConstantFieldDefs(TypeBuilder baseTB)
        {
            // We have to do this different than the JVM version.
            // The JVM does all these at the end.
            // That works for the usual ObjExpr, but not for the top-level one that becomes __Init__.Initialize in the assembly.
            // That one need the constants defined incrementally.
            // This version accommodates the all-at-end approach for general ObjExprs and the incremental approach in Compiler.Compile1.

            if (ConstantFields == null)
                ConstantFields = new Dictionary<int, FieldBuilder>(Constants.count());

            int nextKey = ConstantFields.Count == 0 ? 0 : ConstantFields.Keys.Max() + 1;

            for (int i = nextKey; i < Constants.count(); i++)
            {
                if (!ConstantFields.ContainsKey(i))
                {
                    string fieldName = ConstantName(i);
                    Type fieldType = ConstantType(i);
                    FieldBuilder fb = baseTB.DefineField(fieldName, fieldType, FieldAttributes.FamORAssem | FieldAttributes.Static);
                    ConstantFields[i] = fb;
                }
            }
        }

Usage Example

示例#1
0
        private static void Compile1(TypeBuilder tb, CljILGen ilg,  ObjExpr objx, object form)
        {
            object line = LineVarDeref();
            if (RT.meta(form) != null && RT.meta(form).containsKey(RT.LineKey))
                line = RT.meta(form).valAt(RT.LineKey);
            object column = ColumnVarDeref();
            if (RT.meta(form) != null && RT.meta(form).containsKey(RT.ColumnKey))
                column = RT.meta(form).valAt(RT.ColumnKey);
            IPersistentMap sourceSpan = (IPersistentMap)SourceSpanVar.deref();
            if (RT.meta(form) != null && RT.meta(form).containsKey(RT.SourceSpanKey))
                sourceSpan = (IPersistentMap)RT.meta(form).valAt(RT.SourceSpanKey);

            ParserContext evPC = new ParserContext(RHC.Eval);

            Var.pushThreadBindings(RT.map(LineVar, line, ColumnVar, column, SourceSpanVar, sourceSpan));

            try
            {
                form = Macroexpand(form);
                if (form is ISeq && Util.Equals(RT.first(form), DoSym))
                {
                    for (ISeq s = RT.next(form); s != null; s = RT.next(s))
                        Compile1(tb, ilg, objx, RT.first(s));
                }
                else
                {
                    Expr expr = Analyze(evPC, form);
                    objx.Keywords = (IPersistentMap)KeywordsVar.deref();
                    objx.Vars = (IPersistentMap)VarsVar.deref();
                    objx.Constants = (PersistentVector)ConstantsVar.deref();
                    objx.EmitConstantFieldDefs(tb);
                    expr.Emit(RHC.Expression,objx,ilg);
                    ilg.Emit(OpCodes.Pop);
                    expr.Eval();
                }
            }
            finally
            {
                Var.popThreadBindings();
            }
        }
All Usage Examples Of clojure.lang.CljCompiler.Ast.ObjExpr::EmitConstantFieldDefs