/// <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()); }
/// <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 (_compiler.Arguments.DisplayVersion) { _compiler.PrintVersion(_console.Out); return(0); } 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.TryReadFileContent(sourceFiles[0], diagnosticsInfos); } } // only emit symbols for non-interactive mode, var emitDebugInformation = !_compiler.Arguments.InteractiveMode; var scriptPathOpt = sourceFiles.IsEmpty ? null : sourceFiles[0].Path; var scriptOptions = GetScriptOptions(_compiler.Arguments, scriptPathOpt, _compiler.MessageProvider, diagnosticsInfos, emitDebugInformation); 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, errorLogger, cancellationToken)); } }