Inheritance: PrologCompilerModel
        public InteractiveCompiler(string filename)
        {
            PrologCodeProvider provider = new PrologCodeProvider();
            IPrologCompiler compiler = provider.CreateCompiler();
            PrologCompilerParameters parameters = new PrologCompilerParameters();
            PrologCompilerResults results = compiler.CompileAbstractCodeFromFile(parameters, "boot.pro");

            /* Run */
            AbstractMachineState runtime = new AbstractMachineState(new AMFactory());
            //runtime.Init(results.AbstractInstructions, results.ForeignMethods, results.Namespaces, results.AssemblyFiles);
            runtime.Initialize(results.AbstractInstructions);

            runtime.Transition();
        }
Exemple #2
0
        /* Run the Compiler Tool application */
        public void Run()
        {
            if(cmdOptions.NoArgs())
            {
                PrintLogo();
                this.compiler = new InteractiveCompiler();
                return;
            }
            if(cmdOptions.NoOptions())
            {
                PrintLogo();
                this.compiler = new InteractiveCompiler(cmdOptions["source"]);
                return;
            }
            this.compiler = new CLICompiler();
            /* Check command line options */
            if(cmdOptions["help"] != null)
            {
                Help();
                return;
            }
            if(cmdOptions["version"] != null)
            {
                PrintLogo();
                return;
            }
            if(cmdOptions["source"] == null)
            {
                Error("CT1008", null);
            }

            if (cmdOptions["static"] != null)
            {
                staticAssembly = true;
            }

            if(cmdOptions["listing"] != null)
            {
                /* set the listing generator */
                string outputFile = cmdOptions["source"] + ".txt";
                if(cmdOptions["output"] != null)
                {
                    outputFile = cmdOptions["output"];
                }
                //compiler.SetGenerator(new ListingGenerator(outputFile));
            }
            if(cmdOptions["target"] != null)
            {
                switch(cmdOptions["target"])
                {
                    case "exe":

                        string outputFile = cmdOptions["source"];
                        if(cmdOptions["output"] != null)
                        {
                            outputFile = cmdOptions["output"];
                        }
                        PrologCodeProvider provider = new PrologCodeProvider();
                        IPrologCompiler compiler = provider.CreateCompiler();
                        PrintLogo();
                        PrologCompilerParameters parameters = new PrologCompilerParameters();
                        parameters.GenerateExecutable = true;
                        parameters.OutputAssembly = outputFile.Replace(".pro", ".exe");
                        PrologCompilerResults cr = compiler.CompileAssemblyFromFile(parameters, outputFile);

                        if (cr.Errors.Count > 0)
                        {
                            foreach (PrologCompilerError e in cr.Errors)
                            {
                                Console.WriteLine(e);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Successfully compiled " + outputFile);
                        }
                        // check if you need to compile into static EXE
                        if (staticAssembly)
                        {
                            ArrayList inputAssemblies = new ArrayList();
                            // Add Axiom.Runtime.dll
                            inputAssemblies.Add("Axiom.Runtime.dll");

                            // Add remaining library assemblies
                            foreach (string file in Directory.GetFiles("..\\library"))
                            {
                                inputAssemblies.Add(file);
                            }

                            StaticAssemblyCompiler assc = new StaticAssemblyCompiler(parameters.OutputAssembly, parameters.OutputAssembly, inputAssemblies);
                            assc.LinkExecutable();
                        }
                        return;
                    case "dll":
                        string output = cmdOptions["source"];
                        if(cmdOptions["output"] != null)
                        {
                            output = cmdOptions["output"];
                        }
                        //PrologAssemblyCompiler asmc = new PrologAssemblyCompiler();
                        PrologCodeProvider prov = new PrologCodeProvider();
                        IPrologCompiler comp = prov.CreateCompiler();
                        PrintLogo();
                        PrologCompilerParameters par = new PrologCompilerParameters();
                        par.GenerateExecutable = false;
                        par.OutputAssembly = output.Replace(".pro", ".dll");
                        PrologCompilerResults r = comp.CompileAssemblyFromFile(par, output);
                        if (r.Errors.Count > 0)
                        {
                            foreach (PrologCompilerError e in r.Errors)
                            {
                                Console.WriteLine(e);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Successfully compiled " + output);
                        }
                        // check if you need to compile into static DLL
                        if (staticAssembly)
                        {
                            ArrayList inputAssemblies = new ArrayList();

                            // Add Axiom.Runtime.dll
                            inputAssemblies.Add("Axiom.Runtime.dll");

                            // Add remaining library assemblies
                            foreach (string file in Directory.GetFiles("..\\library"))
                            {
                                inputAssemblies.Add(file);
                            }

                            StaticAssemblyCompiler assc = new StaticAssemblyCompiler(par.OutputAssembly, par.OutputAssembly, inputAssemblies);
                            assc.LinkLibrary();
                        }
                        return;
                    case "xml":
                        string outputXml = cmdOptions["source"];
                        if (cmdOptions["output"] != null)
                        {
                            outputXml = cmdOptions["output"];
                        }
                        PrologCodeProvider providerXml = new PrologCodeProvider();
                        IPrologCompiler compilerXml = providerXml.CreateCompiler();
                        PrologCompilerParameters parametersXml = new PrologCompilerParameters();
                        PrologCompilerResults results = compilerXml.CompileAbstractCodeFromFile(parametersXml, outputXml);
                        if (results.Errors.Count > 0)
                        {
                            foreach (PrologCompilerError err in results.Errors)
                            {
                                Console.WriteLine(err);
                            }
                            return;
                        }

                        string plFilename = outputXml;
                        string xmlFilename = plFilename.Replace(".pro", ".xml");

                        GenerateXmlFile(xmlFilename, results.AssemblyFiles, results.AbstractInstructions);
                        return;
                    default:
                        Error("CT1011", null);
                        break;
                }
            }
            /* debug information */
            // deferred to a future release.

            /* treat warnings as errors */
            // deferred to a future release.

            /* silent compilation */
            // deferred to a future release.

            if(cmdOptions["nologo"] == null)
            {
                PrintLogo();
            }

            if(cliErrors.Count != 0)
            {
                Errors();
                return;
            }

            /* Compile */
            //this.compiler.Compile(File.OpenText(cmdOptions["source"]));
        }