Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////
        // Stub
        //////////////////////////////////////////////////////////////////////////

        public static void stub(string podName, DirectoryInfo outDir, bool verbose)
        {
            writeLine("    .NET Stub [" + podName + "]");

            string fanHome = SysProps.getProperty("fan.home");
            string podPath = fanHome + "\\lib\\fan\\" + podName + ".pod";
            string target  = new FileInfo(outDir + "\\" + podName + ".dll").FullName;

            if (verbose)
            {
                writeLine("  <- " + podPath);
                Pod    pod  = Pod.doFind(podName, true, null);
                List   list = pod.types();
                string pre  = "Fan." + FanUtil.upper(podName) + ".";
                for (int i = 0; i < list.sz(); i++)
                {
                    writeLine("  " + pre + (list.get(i) as Type).name());
                }
                writeLine("  -> " + target);
            }

            FStore store = new FStore(new ZipFile(podPath));
            FPod   fpod  = new FPod(podName, store);

            fpod.read();
            FTypeEmit.emitPod(fpod, false, target);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolve an assembly that cannot be found in
        /// the current AppDomain.
        /// </summary>
        public static Assembly resolveAssembly(object sender, ResolveEventArgs args)
        {
            string    asmName = getAssemblyName(args.Name);
            AppDomain domain  = AppDomain.CurrentDomain;

            // check if already loaded
            Assembly[] current = domain.GetAssemblies();
            for (int i = 0; i < current.Length; i++)
            {
                if (asmName == current[i].GetName().Name)
                {
                    return(current[i]);
                }
            }

            // otherwise load it from disk
            string libDir = FileUtil.combine(Sys.m_homeDir, "lib", "dotnet");
            string dll    = FileUtil.combine(libDir, asmName + ".dll");

            FileInfo f = new FileInfo(dll);

            if (!f.Exists)
            {
                // check tmp dir
                string tmpDir = FileUtil.combine(Sys.m_homeDir, "lib", "tmp");
                dll = FileUtil.combine(tmpDir, asmName + ".dll");
                f   = new FileInfo(dll);
            }
            if (!f.Exists)
            {
                // not emitted yet, emit
                Pod pod = Pod.find(asmName, true);
                return(FTypeEmit.emitPod(pod.fpod, true, null));
            }

            // the file may have been generated by another process, so
            // check if we need to emit to flush out things this process
            // will need from FTypeEmit
            if (!asmName.EndsWith("Native_") && !FTypeEmit.isEmitted(asmName))
            {
                Pod pod = Pod.find(asmName, true);
                return(FTypeEmit.emitPod(pod.fpod, true, null));
            }

            BinaryReader fIn = new BinaryReader(f.OpenRead());

            byte[] asm = fIn.ReadBytes((int)f.Length);
            fIn.Close();
            if (asm.Length != f.Length)
            {
                throw new Exception("Could not read " + dll + ": " + asm.Length + " != " + f.Length);
            }

            Assembly result = domain.Load(asm);

            return(result);
        }
Ejemplo n.º 3
0
        public System.Type emit()
        {
            if (m_type == null)
            {
                if (Debug)
                {
                    Console.WriteLine("-- emit:   " + m_qname);
                }

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

                // if sys class, just load it by name
                string podName = m_pod.m_name;
                if (podName == "sys")
                {
                    try
                    {
                        m_dotnetRepr = FanUtil.isDotnetRepresentation(this);
                        m_type       = System.Type.GetType(FanUtil.toDotnetImplTypeName(podName, m_name));
                    }
                    catch (Exception e)
                    {
                        Err.dumpStack(e);
                        throw Err.make("Cannot load precompiled class: " + m_qname, e).val;
                    }
                }

                // otherwise we need to emit it
                else
                {
                    try
                    {
                        System.Type[] types = FTypeEmit.emitAndLoad(m_ftype);
                        this.m_type = types[0];
                        if (types.Length > 1)
                        {
                            this.m_auxType = types[1];
                        }
                    }
                    catch (Exception e)
                    {
                        Err.dumpStack(e);
                        throw Err.make("Cannot emit: " + m_qname, e).val;
                    }
                }

                // we are done with our ftype now, gc it
                this.m_ftype = null;
            }
            return(m_type);
        }