Esempio n. 1
0
        //////////////////////////////////////////////////////////////////////////
        // Emit
        //////////////////////////////////////////////////////////////////////////
        public static void emit(Emitter emitter, FPod pod)
        {
            //FPodEmit emit = new FPodEmit(pod);

              TypeAttr tattr = TypeAttr.Public | TypeAttr.Sealed;
              FieldAttr fattr = FieldAttr.Public | FieldAttr.Static;

              emitter.emitClass("System.Object", FanUtil.toDotnetTypeName(pod.m_podName, "$Pod", false),
            new string[0], tattr);

              pod.readLiterals();

              // generate constant fields other types will reference, we don't
              // initialize them, rather we do that later via reflection
              for (int i=0; i<pod.m_literals.m_ints.size(); i++)
            emitter.emitField("I" + i, "System.Int64", fattr);
              for (int i=0; i<pod.m_literals.m_floats.size(); i++)
            emitter.emitField("F" + i, "System.Double", fattr);
              for (int i=0; i<pod.m_literals.m_decimals.size(); i++)
            emitter.emitField("D" + i, "Fan.Sys.BigDecimal", fattr);
              for (int i=0; i<pod.m_literals.m_strs.size(); i++)
            emitter.emitField("S" + i, "System.String", fattr);
              for (int i=0; i<pod.m_literals.m_durations.size(); i++)
            emitter.emitField("Dur" + i, "Fan.Sys.Duration", fattr);
              for (int i=0; i<pod.m_literals.m_uris.size(); i++)
            emitter.emitField("U" + i, "Fan.Sys.Uri", fattr);
        }
Esempio n. 2
0
        internal string selfName; // class name for self if self is true

        #endregion Fields

        #region Constructors

        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructor.
        /// </summary>
        public FMethodEmit(FTypeEmit emit, FMethod method)
        {
            this.emitter    = emit.emitter;
              this.emit       = emit;
              this.method     = method;
              this.code       = method.m_code;
              this.name       = FanUtil.toDotnetMethodName(method.m_name);
              this.paramLen   = method.m_paramCount;
              this.isStatic   = (method.m_flags & FConst.Static) != 0;
              this.isInternal = false; //(method.m_flags & FConst.Internal) != 0;
              this.isPrivate  = (method.m_flags & FConst.Private) != 0;
              this.isAbstract = (method.m_flags & FConst.Abstract) != 0;
              this.isVirtual  = (method.m_flags & FConst.Virtual) != 0;
              this.isOverride = (method.m_flags & FConst.Override) != 0;
              this.isCtor     = (method.m_flags & FConst.Ctor) != 0;
              this.isNative   = (method.m_flags & FConst.Native) != 0;
              this.isHide     = false; // only used for make/make_
              this.ret        = emit.pod.typeRef(method.m_inheritedRet);
              this.selfName   = emit.selfName;
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public FMethodEmit(FTypeEmit emit)
 {
     this.emitter = emit.emitter;
       this.emit = emit;
 }
Esempio n. 4
0
 //////////////////////////////////////////////////////////////////////////
 // Constructor
 //////////////////////////////////////////////////////////////////////////
 public FErrEmit(Emitter emitter, Type parent, FType type)
     : base(emitter, parent, type)
 {
 }
Esempio n. 5
0
 public FCodeEmit(FTypeEmit parent, FBuf fcode, CILInstructions code, Reg[] regs, FTypeRef ret)
 {
     this.pod      = parent.pod;
       this.emitter  = parent.emitter;
       this.parent   = parent;
       this.buf      = fcode.m_buf;
       this.len      = fcode.m_len;
       this.code     = code;
       this.podClass = FanUtil.toDotnetTypeName(pod.m_podName, "$Pod", false);
       this.jumps    = new Jumps(code);
       this.regs     = regs;
       this.ret      = ret;
 }
Esempio n. 6
0
        public static Assembly emitPod(FPod pod, bool load, string path)
        {
            string podName = pod.m_podName;
              Assembly assembly = (Assembly)assemblies[podName];
              if (assembly == null)
              {
            Emitter emitter = new Emitter(podName, path);

            // unzip the native.dll if one exists
            unzipToTemp(pod, podName + "Native_.dll");
            unzipToTemp(pod, podName + "Native_.pdb");

            // emit the pod class itself (which declares all constants)
            //FPodEmit.EmitAndLoad(emitter, pod);
            FPodEmit.emit(emitter, pod);

            // the Emitter needs base types to be defined before
            // descendant types, so make sure everything gets stubbed
            // out in the correct order ahead of time
            for (int i=0; i<pod.m_types.Length; i++)
              emitter.findType(pod.nname(pod.m_types[i].m_self));

            // emit all the rest of the types in this pod
            for (int i=0; i<pod.m_types.Length; i++)
            {
              FType ftype = pod.m_types[i];
              FTypeRef tref = ftype.m_pod.typeRef(ftype.m_self);
              Type parent = Type.find(tref.podName+"::"+tref.typeName, true);

              // make sure we have reflected to setup slots
              parent.reflect();

              // route based on type
              if ((ftype.m_flags & FConst.Mixin) != 0)
              {
            // interface
            FMixinInterfaceEmit iemit = new FMixinInterfaceEmit(emitter, parent, ftype);
            iemit.emit();

            // body class
            FMixinBodyEmit bemit = new FMixinBodyEmit(emitter, parent, ftype);
            bemit.emit();

            ftypes[ftype] = new FTypeEmit[] { iemit, bemit };
              }
              else if (parent.@is(Sys.ErrType))
              {
            // error
            FErrEmit emitErr = new FErrEmit(emitter, parent, ftype);
            emitErr.emit();

            FErrValEmit emitErrVal = new FErrValEmit(emitter, parent, ftype);
            emitErrVal.emit();

            ftypes[ftype] = new FTypeEmit[] { emitErr, emitErrVal };
              }
              else
              {
            // class
            FClassEmit emit = new FClassEmit(emitter, parent, ftype);
            emit.emit();
            ftypes[ftype] = new FTypeEmit[] { emit };
              }
            }

            // commit assembly
            byte[] buf = emitter.commit();
            if (load)
            {
              //long start = System.Environment.TickCount;

              // load assembly
              assembly = (buf == null)
            ? Assembly.LoadFile(emitter.fileName)
            : Assembly.Load(buf);
              assemblies[podName] = assembly;

              //long end = System.Environment.TickCount;
              //System.Console.WriteLine("load " + podName + " in " + (end-start) + " ms");

              // load $Pod type
              FPodEmit.load(assembly, pod);
            }
              }
              return assembly;
        }
Esempio n. 7
0
        private static Hashtable ftypes = new Hashtable(); // ftype[] lookup

        #endregion Fields

        #region Constructors

        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////
        protected FTypeEmit(Emitter emitter, Type parent, FType type)
        {
            this.emitter = emitter;
              this.parent  = parent;
              this.pod     = type.m_pod;
              this.type    = type;
        }
Esempio n. 8
0
 //////////////////////////////////////////////////////////////////////////
 // Constructor
 //////////////////////////////////////////////////////////////////////////
 public FMixinInterfaceEmit(Emitter emitter, Type parent, FType type)
     : base(emitter, parent, type)
 {
 }
Esempio n. 9
0
        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////

        public FMixinInterfaceEmit(Emitter emitter, Type parent, FType type)
            : base(emitter, parent, type)
        {
        }
Esempio n. 10
0
 //////////////////////////////////////////////////////////////////////////
 // Constructor
 //////////////////////////////////////////////////////////////////////////
 public FMixinBodyEmit(Emitter emitter, Type parent, FType type)
     : base(emitter, parent, type)
 {
 }