diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-06-02 15:48:59 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-06-02 16:22:09 +0200 |
commit | dded5473c2fce3e6ad814536b0f604ebacba1e3a (patch) | |
tree | 09f1ac83cc0fcb4f56730ec396e28c7b5b804566 /src | |
parent | 845b98186047f38013e2f6aa35508e974eedafb7 (diff) | |
download | dotty-dded5473c2fce3e6ad814536b0f604ebacba1e3a.tar.gz dotty-dded5473c2fce3e6ad814536b0f604ebacba1e3a.tar.bz2 dotty-dded5473c2fce3e6ad814536b0f604ebacba1e3a.zip |
Add `initialCommands` and `cleanupCommands` to REPL
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/repl/InterpreterLoop.scala | 19 | ||||
-rw-r--r-- | 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", "") != "" |