private void RunInteractiveLoop(ScriptOptions options, string initialScriptCodeOpt, CancellationToken cancellationToken) { var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter); globals.Args.AddRange(_compiler.Arguments.ScriptArguments); ScriptState<object> state = null; if (initialScriptCodeOpt != null) { var script = Script.CreateInitialScript<object>(_scriptCompiler, initialScriptCodeOpt, options, globals.GetType(), assemblyLoaderOpt: null); Compilation compilation; TryBuildAndRun(script, globals, ref state, out compilation, cancellationToken); } while (true) { _console.Out.Write("> "); var input = new StringBuilder(); string line; bool cancelSubmission = false; while (true) { line = _console.In.ReadLine(); if (line == null) { if (input.Length == 0) { return; } cancelSubmission = true; break; } input.AppendLine(line); var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), cancellationToken); if (_scriptCompiler.IsCompleteSubmission(tree)) { break; } _console.Out.Write(". "); } if (cancelSubmission) { continue; } string code = input.ToString(); if (IsHelpCommand(code)) { DisplayHelpText(); continue; } Script<object> newScript; if (state == null) { newScript = Script.CreateInitialScript<object>(_scriptCompiler, code, options, globals.GetType(), assemblyLoaderOpt: null); } else { newScript = state.Script.ContinueWith(code, options); } Compilation newCompilation; if (!TryBuildAndRun(newScript, globals, ref state, out newCompilation, cancellationToken)) { continue; } bool hasValue; ITypeSymbol resultType = newCompilation.GetSubmissionResultType(out hasValue); if (hasValue) { if (resultType != null && resultType.SpecialType == SpecialType.System_Void) { _console.Out.WriteLine(_objectFormatter.VoidDisplayString); } else { globals.Print(state.ReturnValue); } } } }
private void RunInteractiveLoop(ScriptOptions options, CancellationToken cancellationToken) { var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter); globals.Args.AddRange(_compiler.Arguments.ScriptArguments); ScriptState <object> state = null; while (true) { _console.Out.Write("> "); var input = new StringBuilder(); string line; bool cancelSubmission = false; while (true) { line = _console.In.ReadLine(); if (line == null) { if (input.Length == 0) { return; } cancelSubmission = true; break; } input.AppendLine(line); var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), cancellationToken); if (_scriptCompiler.IsCompleteSubmission(tree)) { break; } _console.Out.Write(". "); } if (cancelSubmission) { continue; } string code = input.ToString(); Script<object> newScript; if (state == null) { newScript = Script.CreateInitialScript<object>(_scriptCompiler, code, options, globals.GetType(), assemblyLoaderOpt: null); } else { newScript = state.Script.ContinueWith(code, options); } var newCompilation = newScript.GetCompilation(); try { newScript.Build(cancellationToken); // display warnings: DisplayDiagnostics(newCompilation.GetDiagnostics(cancellationToken).Where(d => d.Severity == DiagnosticSeverity.Warning)); } catch (CompilationErrorException e) { DisplayDiagnostics(e.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error || d.Severity == DiagnosticSeverity.Warning)); continue; } try { var task = (state == null) ? newScript.RunAsync(globals, cancellationToken) : newScript.ContinueAsync(state, cancellationToken); state = task.GetAwaiter().GetResult(); } catch (Exception e) { DisplayException(e); continue; } bool hasValue; ITypeSymbol resultType = newCompilation.GetSubmissionResultType(out hasValue); if (hasValue) { if (resultType != null && resultType.SpecialType == SpecialType.System_Void) { _console.Out.WriteLine(_objectFormatter.VoidDisplayString); } else { globals.Print(state.ReturnValue); } } } }
private void RunInteractiveLoop(ScriptOptions options, string initialScriptCodeOpt, CancellationToken cancellationToken) { var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter); globals.Args.AddRange(_compiler.Arguments.ScriptArguments); ScriptState <object> state = null; if (initialScriptCodeOpt != null) { var script = Script.CreateInitialScript <object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt), options, globals.GetType(), assemblyLoaderOpt: null); BuildAndRun(script, globals, ref state, ref options, displayResult: false, cancellationToken: cancellationToken); } while (true) { _console.Out.Write("> "); var input = new StringBuilder(); string line; bool cancelSubmission = false; while (true) { line = _console.In.ReadLine(); if (line == null) { if (input.Length == 0) { return; } cancelSubmission = true; break; } input.AppendLine(line); var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), options.ParseOptions, cancellationToken); if (_scriptCompiler.IsCompleteSubmission(tree)) { break; } _console.Out.Write(". "); } if (cancelSubmission) { continue; } string code = input.ToString(); if (IsHelpCommand(code)) { DisplayHelpText(); continue; } Script <object> newScript; if (state == null) { newScript = Script.CreateInitialScript <object>(_scriptCompiler, SourceText.From(code ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null); } else { newScript = state.Script.ContinueWith(code, options); } BuildAndRun(newScript, globals, ref state, ref options, displayResult: true, cancellationToken: cancellationToken); } }
private void RunInteractiveLoop(ScriptOptions options, CancellationToken cancellationToken) { var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter); globals.Args.AddRange(_compiler.Arguments.ScriptArguments); ScriptState <object> state = null; while (true) { _console.Out.Write("> "); var input = new StringBuilder(); string line; bool cancelSubmission = false; while (true) { line = _console.In.ReadLine(); if (line == null) { if (input.Length == 0) { return; } cancelSubmission = true; break; } input.AppendLine(line); var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), cancellationToken); if (_scriptCompiler.IsCompleteSubmission(tree)) { break; } _console.Out.Write(". "); } if (cancelSubmission) { continue; } string code = input.ToString(); Script <object> newScript; if (state == null) { newScript = Script.CreateInitialScript <object>(_scriptCompiler, code, options, globals.GetType(), assemblyLoaderOpt: null); } else { newScript = state.Script.ContinueWith(code, options); } var newCompilation = newScript.GetCompilation(); try { newScript.Build(cancellationToken); // display warnings: DisplayDiagnostics(newCompilation.GetDiagnostics(cancellationToken).Where(d => d.Severity == DiagnosticSeverity.Warning)); } catch (CompilationErrorException e) { DisplayDiagnostics(e.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error || d.Severity == DiagnosticSeverity.Warning)); continue; } try { var task = (state == null) ? newScript.RunAsync(globals, cancellationToken) : newScript.ContinueAsync(state, cancellationToken); state = task.GetAwaiter().GetResult(); } catch (Exception e) { DisplayException(e); continue; } bool hasValue; ITypeSymbol resultType = newCompilation.GetSubmissionResultType(out hasValue); if (hasValue) { if (resultType != null && resultType.SpecialType == SpecialType.System_Void) { _console.Out.WriteLine(_objectFormatter.VoidDisplayString); } else { globals.Print(state.ReturnValue); } } } }