FTypeEmit translates FType fcode to IL.
Esempio n. 1
0
        internal FMethodVar[] vars; // method variables must be set for loadVar/storeVar

        #endregion Fields

        #region Constructors

        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////
        public FCodeEmit(FTypeEmit parent, FMethod fmethod, CILInstructions code)
            : this(parent, fmethod.m_code, code,
         initRegs(parent.pod,  fmethod.isStatic(), fmethod.m_vars),
         parent.pod.typeRef(fmethod.m_ret))
        {
            this.fmethod    = fmethod;
              this.vars       = fmethod.m_vars;
              this.isStatic   = (fmethod.m_flags & FConst.Static) != 0;
              this.paramCount = fmethod.m_paramCount;
              if (!isStatic) paramCount++;
        }
Esempio n. 2
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. 3
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. 4
0
        //////////////////////////////////////////////////////////////////////////
        // Constructor
        //////////////////////////////////////////////////////////////////////////

        public FCodeEmit(FTypeEmit parent, FMethod fmethod, CILInstructions code)
            : this(parent, fmethod.m_code, code,
                   initRegs(parent.pod, fmethod.isStatic(), fmethod.m_vars),
                   parent.pod.typeRef(fmethod.m_ret))
        {
            this.fmethod    = fmethod;
            this.vars       = fmethod.m_vars;
            this.isStatic   = (fmethod.m_flags & FConst.Static) != 0;
            this.paramCount = fmethod.m_paramCount;
            if (!isStatic)
            {
                paramCount++;
            }
        }
Esempio n. 5
0
        //////////////////////////////////////////////////////////////////////////
        // Factory
        //////////////////////////////////////////////////////////////////////////

        public static System.Type[] emitAndLoad(FType ftype)
        {
            string   className = ftype.m_pod.nname(ftype.m_self);
            Assembly assembly  = emitPod(ftype.m_pod, true, null);

            FTypeEmit[]   emitted = (FTypeEmit[])ftypes[ftype];
            System.Type[] types   = new System.Type[emitted.Length];
            for (int i = 0; i < emitted.Length; i++)
            {
                FTypeEmit e = emitted[i];
                types[i] = assembly.GetType(e.className);
            }

            return(types);
        }
Esempio n. 6
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. 7
0
        //////////////////////////////////////////////////////////////////////////
        // 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. 8
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. 9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public FMethodEmit(FTypeEmit emit)
 {
     this.emitter = emit.emitter;
       this.emit = emit;
 }
Esempio n. 10
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public FMethodEmit(FTypeEmit emit)
 {
     this.emitter = emit.emitter;
     this.emit    = emit;
 }
Esempio n. 11
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;
        }