// compile the script public bool compile() { lastCompileError = ""; if (vsaEngine.Compile()) { return(true); } return(false); }
// // Entry point // private static void Main(string [] args) { if (args.Length < 1) { Usage(); Environment.Exit(0); } MainDriver(args); VsaEngine engine = new VsaEngine(); engine.InitVsaEngine("mjs:com.mono-project", new MonoEngineSite()); foreach (string asm in references) { IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm, VsaItemType.Reference, VsaItemFlag.None); item.AssemblyName = asm; } string asm_name = String.Empty; foreach (Assembly assembly in assemblies) { asm_name = assembly.GetName().FullName; IVsaReferenceItem item = (IVsaReferenceItem)engine.Items.CreateItem(asm_name, VsaItemType.Reference, VsaItemFlag.None); item.AssemblyName = asm_name; } foreach (string file in files) { IVsaCodeItem item = (IVsaCodeItem)engine.Items.CreateItem(file, VsaItemType.Code, VsaItemFlag.None); item.SourceText = GetCodeFromFile(file); } engine.SetOption("debug", want_debugging_support); engine.SetOption("link_path", link_paths); engine.SetOption("first_source", first_source); engine.SetOption("assemblies", assemblies); engine.SetOption("out", output_file); if (warning_level != -1) { engine.SetOption("WarningLevel", warning_level); } engine.Compile(); }
internal int Compile(CompilerParameters options, string partialCmdLine, string[] sourceFiles, string outputFile) { // write compiler output to a stream with outputFile as the name StreamWriter output = null; int nativeReturnValue = 0; try { // Compiler output must be UTF-8 encoded output = new StreamWriter(outputFile); output.AutoFlush = true; if (options.IncludeDebugInformation) { Debug.Assert(partialCmdLine != null); this.PrintOptions(output, options); this.debugCommandLine = partialCmdLine; } VsaEngine engine = null; try { engine = this.CreateAndInitEngine(options, sourceFiles, outputFile, output); } catch (CmdLineException e) { output.WriteLine(e.Message); nativeReturnValue = 10; } catch (Exception e) { output.WriteLine("fatal error JS2999: " + e); nativeReturnValue = 10; } catch { output.WriteLine("fatal error JS2999"); nativeReturnValue = 10; } if (engine == null) { return(nativeReturnValue); } if (options.IncludeDebugInformation) { // this.debugCommandLine was completed during CreateAndInitEngine (except for filenames) StringBuilder fullCmdLine = new StringBuilder(this.debugCommandLine); foreach (string sourceFile in sourceFiles) { fullCmdLine.Append(" \""); fullCmdLine.Append(sourceFile); fullCmdLine.Append("\""); } this.debugCommandLine = fullCmdLine.ToString(); // write the full command line to a response file for debugging string responseFileName = options.TempFiles.AddExtension("cmdline"); StreamWriter responseFile = null; try { responseFile = new StreamWriter(responseFileName); responseFile.WriteLine(this.debugCommandLine); responseFile.Flush(); } finally { if (responseFile != null) { responseFile.Close(); } } // show full debug command line in compiler output StringBuilder sb = new StringBuilder(); sb.Append(Environment.NewLine); sb.Append(JScriptException.Localize("CmdLine helper", CultureInfo.CurrentUICulture)); sb.Append(":"); sb.Append(Environment.NewLine); sb.Append(" "); sb.Append(options.TempFiles.TempDir); sb.Append("> jsc.exe @\""); sb.Append(responseFileName); sb.Append("\""); sb.Append(Environment.NewLine); output.WriteLine(sb.ToString()); this.PrintBanner(engine, output); } try { if (!engine.Compile()) { nativeReturnValue = 10; } else { nativeReturnValue = 0; } } catch (VsaException e) { // check for expected errors if (e.ErrorCode == VsaError.AssemblyExpected) { if (e.InnerException != null && e.InnerException is System.BadImageFormatException) { // the reference was not for an assembly CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, e.Message, engine.ErrorCultureInfo); output.WriteLine(cmdLineError.Message); } else if (e.InnerException != null && e.InnerException is System.IO.FileNotFoundException) { // the referenced file not valid CmdLineException cmdLineError = new CmdLineException(CmdLineError.AssemblyNotFound, e.Message, engine.ErrorCultureInfo); output.WriteLine(cmdLineError.Message); } else { CmdLineException cmdLineError = new CmdLineException(CmdLineError.InvalidAssembly, engine.ErrorCultureInfo); output.WriteLine(cmdLineError.Message); } } else if (e.ErrorCode == VsaError.SaveCompiledStateFailed) { CmdLineException cmdLineError = new CmdLineException(CmdLineError.ErrorSavingCompiledState, e.Message, engine.ErrorCultureInfo); output.WriteLine(cmdLineError.Message); } else { output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo)); output.WriteLine(e); } nativeReturnValue = 10; } catch (Exception e) { output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo)); output.WriteLine(e); nativeReturnValue = 10; } catch { output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo)); nativeReturnValue = 10; } } finally { if (output != null) { output.Close(); } } return(nativeReturnValue); }
internal int Compile(CompilerParameters options, string partialCmdLine, string[] sourceFiles, string outputFile) { StreamWriter output = null; int num = 0; try { output = new StreamWriter(outputFile) { AutoFlush = true }; if (options.IncludeDebugInformation) { this.PrintOptions(output, options); this.debugCommandLine = partialCmdLine; } VsaEngine engine = null; try { engine = this.CreateAndInitEngine(options, sourceFiles, outputFile, output); } catch (CmdLineException exception) { output.WriteLine(exception.Message); num = 10; } catch (Exception exception2) { output.WriteLine("fatal error JS2999: " + exception2); num = 10; } if (engine == null) { return(num); } if (options.IncludeDebugInformation) { StringBuilder builder = new StringBuilder(this.debugCommandLine); foreach (string str in sourceFiles) { builder.Append(" \""); builder.Append(str); builder.Append("\""); } this.debugCommandLine = builder.ToString(); string path = options.TempFiles.AddExtension("cmdline"); StreamWriter writer2 = null; try { writer2 = new StreamWriter(path); writer2.WriteLine(this.debugCommandLine); writer2.Flush(); } finally { if (writer2 != null) { writer2.Close(); } } StringBuilder builder2 = new StringBuilder(); builder2.Append(Environment.NewLine); builder2.Append(JScriptException.Localize("CmdLine helper", CultureInfo.CurrentUICulture)); builder2.Append(":"); builder2.Append(Environment.NewLine); builder2.Append(" "); builder2.Append(options.TempFiles.TempDir); builder2.Append("> jsc.exe @\""); builder2.Append(path); builder2.Append("\""); builder2.Append(Environment.NewLine); output.WriteLine(builder2.ToString()); this.PrintBanner(engine, output); } try { if (!engine.Compile()) { return(10); } return(0); } catch (JSVsaException exception3) { if (exception3.ErrorCode == JSVsaError.AssemblyExpected) { if ((exception3.InnerException != null) && (exception3.InnerException is BadImageFormatException)) { CmdLineException exception4 = new CmdLineException(CmdLineError.InvalidAssembly, exception3.Message, engine.ErrorCultureInfo); output.WriteLine(exception4.Message); } else if ((exception3.InnerException != null) && (exception3.InnerException is FileNotFoundException)) { CmdLineException exception5 = new CmdLineException(CmdLineError.AssemblyNotFound, exception3.Message, engine.ErrorCultureInfo); output.WriteLine(exception5.Message); } else { CmdLineException exception6 = new CmdLineException(CmdLineError.InvalidAssembly, engine.ErrorCultureInfo); output.WriteLine(exception6.Message); } } else if (exception3.ErrorCode == JSVsaError.SaveCompiledStateFailed) { CmdLineException exception7 = new CmdLineException(CmdLineError.ErrorSavingCompiledState, exception3.Message, engine.ErrorCultureInfo); output.WriteLine(exception7.Message); } else { output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo)); output.WriteLine(exception3); } num = 10; } catch (Exception exception8) { output.WriteLine(JScriptException.Localize("INTERNAL COMPILER ERROR", engine.ErrorCultureInfo)); output.WriteLine(exception8); num = 10; } } finally { if (output != null) { output.Close(); } } return(num); }