@@ -51,7 +51,7 @@ import scala.collection.JavaConverters._
5151case class State (objectIndex : Int ,
5252 valIndex : Int ,
5353 imports : List [untpd.Import ],
54- run : Run )
54+ context : Context )
5555
5656/** Main REPL instance, orchestrating input, compilation and presentation */
5757class ReplDriver (settings : Array [String ],
@@ -72,7 +72,7 @@ class ReplDriver(settings: Array[String],
7272 }
7373
7474 /** the initial, empty state of the REPL session */
75- protected [this ] def initState = State (0 , 0 , Nil , compiler.newRun( rootCtx, 0 ) )
75+ protected [this ] def initState = State (0 , 0 , Nil , rootCtx)
7676
7777 /** Reset state of repl to the initial state
7878 *
@@ -118,7 +118,7 @@ class ReplDriver(settings: Array[String],
118118 val comps = completions(line.cursor, line.line, state)
119119 candidates.addAll(comps.asJava)
120120 }
121- implicit val ctx = state.run.runContext
121+ implicit val ctx = state.context
122122 try {
123123 val line = terminal.readLine(completer)
124124 ParseResult (line)
@@ -140,16 +140,16 @@ class ReplDriver(settings: Array[String],
140140 }
141141
142142 final def run (input : String )(implicit state : State ): State = withRedirectedOutput {
143- val parsed = ParseResult (input)(state.run.runContext )
143+ val parsed = ParseResult (input)(state.context )
144144 interpret(parsed)
145145 }
146146
147147 private def withRedirectedOutput (op : => State ): State =
148148 Console .withOut(out) { Console .withErr(out) { op } }
149149
150150 private def newRun (state : State ) = {
151- val newRun = compiler.newRun(rootCtx.fresh.setReporter(newStoreReporter), state.objectIndex)
152- state.copy(run = newRun )
151+ val run = compiler.newRun(rootCtx.fresh.setReporter(newStoreReporter), state.objectIndex)
152+ state.copy(context = run.runContext )
153153 }
154154
155155 /** Extract possible completions at the index of `cursor` in `expr` */
@@ -173,7 +173,7 @@ class ReplDriver(settings: Array[String],
173173 val file = new SourceFile (" <completions>" , expr)
174174 val unit = new CompilationUnit (file)
175175 unit.tpdTree = tree
176- implicit val ctx = state.run.runContext .fresh.setCompilationUnit(unit)
176+ implicit val ctx = state.context .fresh.setCompilationUnit(unit)
177177 val srcPos = SourcePosition (file, Position (cursor))
178178 val (_, completions) = Interactive .completions(srcPos)
179179 completions.map(makeCandidate)
@@ -224,16 +224,16 @@ class ReplDriver(settings: Array[String],
224224 val newImports = newState.imports ++ extractImports(parsed.trees)
225225 val newStateWithImports = newState.copy(imports = newImports)
226226
227- // display warnings
228- displayErrors(newState.run.runContext.flushBufferedMessages()) (newState)
227+ val warnings = newState.context.reporter.removeBufferedMessages(newState.context)
228+ displayErrors(warnings) (newState) // display warnings
229229 displayDefinitions(unit.tpdTree, newestWrapper)(newStateWithImports)
230230 }
231231 )
232232 }
233233
234234 /** Display definitions from `tree` */
235235 private def displayDefinitions (tree : tpd.Tree , newestWrapper : Name )(implicit state : State ): State = {
236- implicit val ctx = state.run.runContext
236+ implicit val ctx = state.context
237237
238238 def resAndUnit (denot : Denotation ) = {
239239 import scala .util .{Success , Try }
@@ -319,7 +319,7 @@ class ReplDriver(settings: Array[String],
319319 initState
320320
321321 case Imports =>
322- state.imports.foreach(i => out.println(SyntaxHighlighting (i.show(state.run.runContext ))))
322+ state.imports.foreach(i => out.println(SyntaxHighlighting (i.show(state.context ))))
323323 state
324324
325325 case Load (path) =>
@@ -356,7 +356,7 @@ class ReplDriver(settings: Array[String],
356356
357357 /** Output errors to `out` */
358358 private def displayErrors (errs : Seq [MessageContainer ])(implicit state : State ): State = {
359- errs.map(renderMessage(_)(state.run.runContext )).foreach(out.println)
359+ errs.map(renderMessage(_)(state.context )).foreach(out.println)
360360 state
361361 }
362362}
0 commit comments