Пример #1
0
        private static void ExportVmBundle(Dictionary <string, string> argLookup)
        {
            using (new PerformanceSection("ExportVmBundle"))
            {
                BuildContext buildContext          = GetBuildContext(argLookup);
                Platform.AbstractPlatform platform = GetPlatformInstance(buildContext);
                if (platform == null)
                {
                    throw new InvalidOperationException("Unrecognized platform. See usage.");
                }

                CompilationBundle compilationResult = CompilationBundle.Compile(buildContext);

                // Need to re-instantiate the libraries. The libraries are instantiated in a platform-context-free
                // for the purpose of compiling the byte code. For the VM bundle, they need to know about the platform.
                Library[] libraries;
                using (new PerformanceSection("Program.ExportVmBundle.CloneLibraries"))
                {
                    libraries = compilationResult.LibrariesUsed
                                .Select(lib => lib.CloneWithNewPlatform(platform))
                                .ToArray();
                }

                ResourceDatabase resourceDatabase = PrepareResources(buildContext, compilationResult.ByteCode);

                string outputDirectory = buildContext.OutputFolder;
                if (!FileUtil.IsAbsolutePath(outputDirectory))
                {
                    outputDirectory = FileUtil.JoinPath(buildContext.ProjectDirectory, outputDirectory);
                }
                outputDirectory = FileUtil.GetCanonicalizeUniversalPath(outputDirectory);
                FileOutputExporter exporter = new FileOutputExporter(outputDirectory);

                VmGenerator vmGenerator = new VmGenerator();
                Dictionary <string, FileOutput> result = vmGenerator.GenerateVmSourceCodeForPlatform(
                    platform,
                    compilationResult,
                    resourceDatabase,
                    libraries,
                    outputDirectory,
                    VmGenerationMode.EXPORT_SELF_CONTAINED_PROJECT_SOURCE);

                exporter.ExportFiles(result);

                if (argLookup.ContainsKey(FlagParser.LIBRARY_DEP_TREE))
                {
                    string libs = LibraryDependencyResolver.GetDependencyTreeLog(compilationResult.LibrariesUsed.ToArray());
                    Console.WriteLine("<LibraryDependencies>");
                    Console.WriteLine(libs.Trim());
                    Console.WriteLine("</LibraryDependencies>");
                }
            }
        }
        public override CrayonWorkerResult DoWorkImpl(CrayonWorkerResult[] args)
        {
            CompilationBundle compilationResult = (CompilationBundle)args[0].Value;

            LibraryMetadata[] libraryMetadata = compilationResult
                                                .UserCodeScope
                                                .Dependencies
                                                .Select(libLocView => libLocView.LibraryScope.Library)
                                                .ToArray();

            string libs = LibraryDependencyResolver.GetDependencyTreeLog(libraryMetadata);

            Console.WriteLine("<LibraryDependencies>");
            Console.WriteLine(libs.Trim());
            Console.WriteLine("</LibraryDependencies>");

            return(new CrayonWorkerResult());
        }
Пример #3
0
        public TopLevelConstruct[] ResolveInterpretedCode()
        {
            this.parser.VerifyNoBadImports();

            Dictionary <string, TopLevelConstruct> definitionsByFullyQualifiedNames = this.CreateFullyQualifiedLookup(this.currentCode);

            Library[] librariesInDependencyOrder = LibraryDependencyResolver.GetLibraryResolutionOrder(this.parser);

            // Populate lookups of executables based on library.
            Dictionary <Library, Dictionary <string, TopLevelConstruct> > definitionsByLibrary = new Dictionary <Library, Dictionary <string, TopLevelConstruct> >();
            Dictionary <string, TopLevelConstruct> nonLibraryCode = new Dictionary <string, TopLevelConstruct>();

            foreach (string exKey in definitionsByFullyQualifiedNames.Keys)
            {
                TopLevelConstruct ex = definitionsByFullyQualifiedNames[exKey];
                if (ex.Library == null)
                {
                    nonLibraryCode[exKey] = ex;
                }
                else
                {
                    Library library = ex.Library;
                    Dictionary <string, TopLevelConstruct> lookup;
                    if (!definitionsByLibrary.TryGetValue(library, out lookup))
                    {
                        lookup = new Dictionary <string, TopLevelConstruct>();
                        definitionsByLibrary[library] = lookup;
                    }
                    lookup[exKey] = ex;
                }
            }

            using (new PerformanceSection("ResolveNames for compilation segments"))
            {
                Dictionary <string, TopLevelConstruct> alreadyResolvedDependencies;
                // Resolve raw names into the actual things they refer to based on namespaces and imports.
                foreach (Library library in librariesInDependencyOrder)
                {
                    // First create a lookup of JUST the libraries that are available to this library.
                    alreadyResolvedDependencies = Util.MergeDictionaries(
                        library.LibraryDependencies.Select(lib => definitionsByLibrary[lib]).ToArray());

                    // Resolve definitions based on what's available.
                    this.ResolveNames(library, alreadyResolvedDependencies, definitionsByLibrary[library]);
                }
                alreadyResolvedDependencies = Util.MergeDictionaries <string, TopLevelConstruct>(
                    this.parser.LibraryManager.LibrariesUsed.Select(lib => definitionsByLibrary[lib]).ToArray());
                nonLibraryCode.Remove("~");
                this.ResolveNames(null, alreadyResolvedDependencies, nonLibraryCode);
            }

            // Determine if the main function uses args.
            FunctionDefinition mainFunction = (FunctionDefinition)definitionsByFullyQualifiedNames["~"];

            this.parser.MainFunctionHasArg = mainFunction.ArgNames.Length == 1;

            this.SimpleFirstPassResolution();

            this.DetermineInlinableLibraryFunctions();

            this.RearrangeClassDefinitions();

            this.AllocateLocalScopeIds();

            return(this.currentCode);
        }