From dded5473c2fce3e6ad814536b0f604ebacba1e3a Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 2 Jun 2016 15:48:59 +0200 Subject: Add `initialCommands` and `cleanupCommands` to REPL --- src/dotty/tools/dotc/repl/InterpreterLoop.scala | 19 +++++++------------ src/dotty/tools/dotc/repl/REPL.scala | 13 +++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/dotty/tools/dotc/repl/InterpreterLoop.scala b/src/dotty/tools/dotc/repl/InterpreterLoop.scala index 14a50fdf1..95197f27f 100644 --- a/src/dotty/tools/dotc/repl/InterpreterLoop.scala +++ b/src/dotty/tools/dotc/repl/InterpreterLoop.scala @@ -68,17 +68,6 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con val version = ".next (pre-alpha)" - /** The first interpreted command always takes a couple of seconds - * due to classloading. To bridge the gap, we warm up the interpreter - * by letting it interpret a dummy line while waiting for the first - * line of input to be entered. - */ - def firstLine(): String = { - interpreter.beQuietDuring( - interpreter.interpret("val theAnswerToLifeInTheUniverseAndEverything = 21 * 2")) - in.readLine(prompt) - } - /** The main read-eval-print loop for the interpreter. It calls * `command()` for each line of input. */ @@ -177,6 +166,10 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con (true, shouldReplay) } + def silentlyRun(cmds: List[String]): Unit = cmds.foreach { cmd => + interpreter.beQuietDuring(interpreter.interpret(cmd)) + } + /** Interpret expressions starting with the first line. * Read lines until a complete compilation unit is available * or until a syntax error has been seen. If a full unit is @@ -207,7 +200,9 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con try { if (!ctx.reporter.hasErrors) { // if there are already errors, no sense to continue printWelcome() - repl(firstLine()) + silentlyRun(config.initialCommands) + repl(in.readLine(prompt)) + silentlyRun(config.cleanupCommands) } } finally { closeInterpreter() diff --git a/src/dotty/tools/dotc/repl/REPL.scala b/src/dotty/tools/dotc/repl/REPL.scala index 977f67719..ae8f0b621 100644 --- a/src/dotty/tools/dotc/repl/REPL.scala +++ b/src/dotty/tools/dotc/repl/REPL.scala @@ -52,6 +52,19 @@ object REPL { def context(ctx: Context): Context = ctx + /** The first interpreted commands always take a couple of seconds due to + * classloading. To bridge the gap, we warm up the interpreter by letting it + * interpret at least a dummy line while waiting for the first line of input + * to be entered. + */ + val initialCommands: List[String] = + "val theAnswerToLifeInTheUniverseAndEverything = 21 * 2" :: Nil + + /** We also allow the use of setting cleanup commands in the same manner. + * This is mainly due to supporting the SBT options to specify these commands + */ + val cleanupCommands: List[String] = Nil + /** The default input reader */ def input(in: Interpreter)(implicit ctx: Context): InteractiveReader = { val emacsShell = System.getProperty("env.emacs", "") != "" -- cgit v1.2.3