/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private int RunInteractiveCore(ErrorLogger errorLogger) { Debug.Assert(_compiler.Arguments.IsScriptRunner); var sourceFiles = _compiler.Arguments.SourceFiles; if (sourceFiles.IsEmpty && _compiler.Arguments.DisplayLogo) { _compiler.PrintLogo(_console.Out); if (!_compiler.Arguments.DisplayHelp) { _console.Out.WriteLine(ScriptingResources.HelpPrompt); } } if (_compiler.Arguments.DisplayHelp) { _compiler.PrintHelp(_console.Out); return(0); } SourceText code = null; var diagnosticsInfos = new List <DiagnosticInfo>(); if (!sourceFiles.IsEmpty) { if (sourceFiles.Length > 1 || !sourceFiles[0].IsScript) { diagnosticsInfos.Add(new DiagnosticInfo(_compiler.MessageProvider, _compiler.MessageProvider.ERR_ExpectedSingleScript)); } else { code = _compiler.ReadFileContent(sourceFiles[0], diagnosticsInfos); } } var scriptPathOpt = sourceFiles.IsEmpty ? null : sourceFiles[0].Path; var scriptOptions = GetScriptOptions(_compiler.Arguments, scriptPathOpt, _compiler.MessageProvider, diagnosticsInfos); var errors = _compiler.Arguments.Errors.Concat(diagnosticsInfos.Select(Diagnostic.Create)); if (_compiler.ReportErrors(errors, _console.Error, errorLogger)) { return(CommonCompiler.Failed); } var cancellationToken = new CancellationToken(); if (_compiler.Arguments.InteractiveMode) { RunInteractiveLoop(scriptOptions, code?.ToString(), cancellationToken); return(CommonCompiler.Succeeded); } else { return(RunScript(scriptOptions, code.ToString(), errorLogger, cancellationToken)); } }
/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private int RunInteractiveCore(ErrorLogger errorLogger) { Debug.Assert(_compiler.Arguments.IsInteractive); var sourceFiles = _compiler.Arguments.SourceFiles; if (sourceFiles.IsEmpty && _compiler.Arguments.DisplayLogo) { _compiler.PrintLogo(_console.Out); } if (_compiler.Arguments.DisplayHelp) { _compiler.PrintHelp(_console.Out); return(0); } SourceText code = null; IEnumerable <Diagnostic> errors = _compiler.Arguments.Errors; if (!sourceFiles.IsEmpty) { if (sourceFiles.Length > 1 || !sourceFiles[0].IsScript) { errors = errors.Concat(new[] { Diagnostic.Create(_compiler.MessageProvider, _compiler.MessageProvider.ERR_ExpectedSingleScript) }); } else { var diagnostics = new List <DiagnosticInfo>(); code = _compiler.ReadFileContent(sourceFiles[0], diagnostics); errors = errors.Concat(diagnostics.Select(Diagnostic.Create)); } } if (_compiler.ReportErrors(errors, _console.Out, errorLogger)) { return(CommonCompiler.Failed); } var cancellationToken = new CancellationToken(); var hostObject = new CommandLineHostObject(_console.Out, _objectFormatter, cancellationToken); hostObject.Args = _compiler.Arguments.ScriptArguments.ToArray(); var scriptOptions = GetScriptOptions(_compiler.Arguments); if (sourceFiles.IsEmpty) { RunInteractiveLoop(scriptOptions, hostObject); } else { RunScript(scriptOptions, code.ToString(), sourceFiles[0].Path, hostObject, errorLogger); } return(hostObject.ExitCode); }
/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private static int RunInteractiveCore(CommonCompiler compiler, TextWriter consoleOutput, ErrorLogger errorLogger) { Debug.Assert(compiler.Arguments.IsInteractive); var hasScriptFiles = compiler.Arguments.SourceFiles.Any(file => file.IsScript); if (compiler.Arguments.DisplayLogo && !hasScriptFiles) { compiler.PrintLogo(consoleOutput); } if (compiler.Arguments.DisplayHelp) { compiler.PrintHelp(consoleOutput); return(0); } // TODO (tomat): // When we have command line REPL enabled we'll launch it if there are no input files. IEnumerable <Diagnostic> errors = compiler.Arguments.Errors; if (!hasScriptFiles) { errors = errors.Concat(new[] { Diagnostic.Create(compiler.MessageProvider, compiler.MessageProvider.ERR_NoScriptsSpecified) }); } if (compiler.ReportErrors(errors, consoleOutput, errorLogger)) { return(CommonCompiler.Failed); } // arguments are always available when executing script code: Debug.Assert(compiler.Arguments.ScriptArguments != null); var compilation = compiler.CreateCompilation(consoleOutput, touchedFilesLogger: null, errorLogger: errorLogger); if (compilation == null) { return(CommonCompiler.Failed); } byte[] compiledAssembly; using (MemoryStream output = new MemoryStream()) { EmitResult emitResult = compilation.Emit(output); if (compiler.ReportErrors(emitResult.Diagnostics, consoleOutput, errorLogger)) { return(CommonCompiler.Failed); } compiledAssembly = output.ToArray(); } var assembly = CorLightup.Desktop.LoadAssembly(compiledAssembly); return(Execute(assembly, compilation.GetEntryPoint(default(CancellationToken)), compiler.Arguments.ScriptArguments.ToArray())); }
/// <summary> /// csi.exe and vbi.exe entry point. /// </summary> private static int RunInteractiveCore(CommonCompiler compiler, TextWriter consoleOutput, ErrorLogger errorLogger) { Debug.Assert(compiler.Arguments.IsInteractive); var hasScriptFiles = compiler.Arguments.SourceFiles.Any(file => file.IsScript); if (compiler.Arguments.DisplayLogo && !hasScriptFiles) { compiler.PrintLogo(consoleOutput); } if (compiler.Arguments.DisplayHelp) { compiler.PrintHelp(consoleOutput); return 0; } // TODO (tomat): // When we have command line REPL enabled we'll launch it if there are no input files. IEnumerable<Diagnostic> errors = compiler.Arguments.Errors; if (!hasScriptFiles) { errors = errors.Concat(new[] { Diagnostic.Create(compiler.MessageProvider, compiler.MessageProvider.ERR_NoScriptsSpecified) }); } if (compiler.ReportErrors(errors, consoleOutput, errorLogger)) { return CommonCompiler.Failed; } // arguments are always available when executing script code: Debug.Assert(compiler.Arguments.ScriptArguments != null); var compilation = compiler.CreateCompilation(consoleOutput, touchedFilesLogger: null, errorLogger: errorLogger); if (compilation == null) { return CommonCompiler.Failed; } byte[] compiledAssembly; using (MemoryStream output = new MemoryStream()) { EmitResult emitResult = compilation.Emit(output); if (compiler.ReportErrors(emitResult.Diagnostics, consoleOutput, errorLogger)) { return CommonCompiler.Failed; } compiledAssembly = output.ToArray(); } var assembly = Assembly.Load(compiledAssembly); return Execute(assembly, compiler.Arguments.ScriptArguments.ToArray()); }