Skip to content

Commit dded547

Browse files
committed
Add initialCommands and cleanupCommands to REPL
1 parent 845b981 commit dded547

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/dotty/tools/dotc/repl/InterpreterLoop.scala

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
6868

6969
val version = ".next (pre-alpha)"
7070

71-
/** The first interpreted command always takes a couple of seconds
72-
* due to classloading. To bridge the gap, we warm up the interpreter
73-
* by letting it interpret a dummy line while waiting for the first
74-
* line of input to be entered.
75-
*/
76-
def firstLine(): String = {
77-
interpreter.beQuietDuring(
78-
interpreter.interpret("val theAnswerToLifeInTheUniverseAndEverything = 21 * 2"))
79-
in.readLine(prompt)
80-
}
81-
8271
/** The main read-eval-print loop for the interpreter. It calls
8372
* `command()` for each line of input.
8473
*/
@@ -177,6 +166,10 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
177166
(true, shouldReplay)
178167
}
179168

169+
def silentlyRun(cmds: List[String]): Unit = cmds.foreach { cmd =>
170+
interpreter.beQuietDuring(interpreter.interpret(cmd))
171+
}
172+
180173
/** Interpret expressions starting with the first line.
181174
* Read lines until a complete compilation unit is available
182175
* 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
207200
try {
208201
if (!ctx.reporter.hasErrors) { // if there are already errors, no sense to continue
209202
printWelcome()
210-
repl(firstLine())
203+
silentlyRun(config.initialCommands)
204+
repl(in.readLine(prompt))
205+
silentlyRun(config.cleanupCommands)
211206
}
212207
} finally {
213208
closeInterpreter()

src/dotty/tools/dotc/repl/REPL.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ object REPL {
5252

5353
def context(ctx: Context): Context = ctx
5454

55+
/** The first interpreted commands always take a couple of seconds due to
56+
* classloading. To bridge the gap, we warm up the interpreter by letting it
57+
* interpret at least a dummy line while waiting for the first line of input
58+
* to be entered.
59+
*/
60+
val initialCommands: List[String] =
61+
"val theAnswerToLifeInTheUniverseAndEverything = 21 * 2" :: Nil
62+
63+
/** We also allow the use of setting cleanup commands in the same manner.
64+
* This is mainly due to supporting the SBT options to specify these commands
65+
*/
66+
val cleanupCommands: List[String] = Nil
67+
5568
/** The default input reader */
5669
def input(in: Interpreter)(implicit ctx: Context): InteractiveReader = {
5770
val emacsShell = System.getProperty("env.emacs", "") != ""

0 commit comments

Comments
 (0)