Skip to content

Commit c878bd2

Browse files
committed
Added interpretation of repl initial commands
1 parent 7914492 commit c878bd2

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class ReplDriver(settings: Array[String],
135135
val parsed = ParseResult(input)(state.context)
136136
interpret(parsed)
137137
}
138+
139+
// TODO: i3007
140+
final def bind(name:String, value:Any)(implicit state: State): State = state
138141

139142
private def withRedirectedOutput(op: => State): State =
140143
Console.withOut(out) { Console.withErr(out) { op } }

sbt-bridge/src/xsbt/ConsoleInterface.scala

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ class ConsoleInterface {
1919
def run(args: Array[String],
2020
bootClasspathString: String,
2121
classpathString: String,
22-
// TODO: initial commands needs to be run under some form of special
23-
// "silent" mode in the REPL. I.e. the effects should be had without
24-
// any visual output.
25-
//
26-
// To do this we can use the `run` interface to the `ReplDriver` and
27-
// pass it a special instance of `ParseResult` like `Silently(res: ParseResult)`
28-
// and then observe the effects without printing to `ReplDriver#out`
29-
//
30-
// This way, the REPL can offer feedback on invalid commands but
31-
// still function without stringly logic.
32-
//
33-
// This same principle can be applied to `cleanupCommands` and
34-
// `bindValues`
35-
//
36-
// Steps:
37-
//
38-
// 1. Introduce `case class Silent(res: ParseResult) extends ParseResult`
39-
// 2. Perform all steps in `interpret` as usual without printing to `out`
4022
initialCommands: String,
4123
cleanupCommands: String,
4224
loader: ClassLoader,
@@ -51,6 +33,14 @@ class ConsoleInterface {
5133
} ++
5234
Array("-classpath", classpathString)
5335

54-
new ReplDriver(completeArgs, classLoader = Some(loader)).runUntilQuit()
36+
val driver = new ReplDriver(completeArgs, classLoader = Some(loader))
37+
val initState = driver.initState
38+
val s0 = (bindNames, bindValues).zipped.folLeft(initState) {
39+
case (state, (name, value)) => driver.bind(name, value)(state)
40+
}
41+
val s1 = driver.run(initialCommands)(s0)
42+
// handle failure during initialisation
43+
val s2 = driver.runUntilQuit(s1)
44+
driver.run(s1)
5545
}
5646
}

0 commit comments

Comments
 (0)