Пример #1
0
        public MethodBuilder EmitConstants(TypeBuilder fnTB)
        {
            try
            {
                Var.pushThreadBindings(RT.map(RT.PrintDupVar, true));

                MethodBuilder mb  = fnTB.DefineMethod(StaticCtorHelperName + "_constants", MethodAttributes.Private | MethodAttributes.Static);
                CljILGen      ilg = new CljILGen(mb.GetILGenerator());

                for (int i = 0; i < Constants.count(); i++)
                {
                    FieldBuilder fb;
                    if (ConstantFields.TryGetValue(i, out fb))
                    {
                        EmitValue(Constants.nth(i), ilg);
                        if (Constants.nth(i).GetType() != ConstantType(i))
                        {
                            ilg.Emit(OpCodes.Castclass, ConstantType(i));
                        }
                        ilg.Emit(OpCodes.Stsfld, fb);
                    }
                }
                ilg.Emit(OpCodes.Ret);

                return(mb);
            }
            finally
            {
                Var.popThreadBindings();
            }
        }
Пример #2
0
 internal void EmitConstant(CljILGen ilg, int id, object val)
 {
     FieldBuilder fb = null;
     if ( ConstantFields != null && ConstantFields.TryGetValue(id, out fb))
     {
         ilg.MaybeEmitVolatileOp(fb);
         ilg.Emit(OpCodes.Ldsfld, fb);
     }
     else
         EmitValue(val, ilg);
 }
Пример #3
0
 internal void EmitConstant(CljILGen ilg, int id, object val)
 {
     if (_fnMode == Ast.FnMode.Light)
     {
         if (val == null)
         {
             ilg.EmitNull();
         }
         if (val.GetType().IsPrimitive)
         {
             EmitPrimitive(ilg, val);
             ilg.Emit(OpCodes.Box, val.GetType());
         }
         else
         {
             ilg.Emit(OpCodes.Ldarg_0); // this
             ilg.Emit(OpCodes.Castclass, typeof(IFnClosure));
             ilg.EmitCall(Compiler.Method_IFnClosure_GetClosure);
             ilg.EmitFieldGet(Compiler.Field_Closure_Constants);
             ilg.EmitInt(id);
             ilg.EmitLoadElement(typeof(Object));
             ilg.Emit(OpCodes.Castclass, ConstantType(id));
         }
     }
     else
     {
         FieldBuilder fb = null;
         if (_fnMode == FnMode.Full && ConstantFields != null && ConstantFields.TryGetValue(id, out fb))
         {
             ilg.Emit(OpCodes.Ldsfld, fb);
         }
         else
         {
             EmitValue(val, ilg);
         }
     }
 }