|
| 1 | +package dotty.tools |
| 2 | +package dotc |
| 3 | + |
| 4 | +import core.Contexts.Context |
| 5 | +import reporting.Reporter |
| 6 | +import java.io.EOFException |
| 7 | +import scala.annotation.tailrec |
| 8 | + |
| 9 | +/** A compiler which stays resident between runs. |
| 10 | + * Usage: |
| 11 | + * |
| 12 | + * > scala dotty.tools.dotc.Resident <options> <initial files> |
| 13 | + * |
| 14 | + * dotc> "more options and files to compile" |
| 15 | + * |
| 16 | + * ... |
| 17 | + * |
| 18 | + * dotc> :reset // reset all options to the ones passed on the command line |
| 19 | + * |
| 20 | + * ... |
| 21 | + * |
| 22 | + * dotc> :q // quit |
| 23 | + */ |
| 24 | +object Resident extends Driver { |
| 25 | + |
| 26 | + object residentCompiler extends Compiler |
| 27 | + |
| 28 | + override def newCompiler(): Compiler = ??? |
| 29 | + |
| 30 | + override def sourcesRequired = false |
| 31 | + |
| 32 | + private val quit = ":q" |
| 33 | + private val reset = ":reset" |
| 34 | + |
| 35 | + private def getLine() = { |
| 36 | + Console.print(prompt) |
| 37 | + try scala.io.StdIn.readLine() catch { case _: EOFException => quit } |
| 38 | + } |
| 39 | + |
| 40 | + final override def process(args: Array[String], rootCtx: Context): Reporter = { |
| 41 | + @tailrec def loop(args: Array[String], prevCtx: Context): Reporter = { |
| 42 | + var (fileNames, ctx) = setup(args, prevCtx) |
| 43 | + doCompile(residentCompiler, fileNames)(ctx) |
| 44 | + var nextCtx = ctx |
| 45 | + var line = getLine() |
| 46 | + while (line == reset) { |
| 47 | + nextCtx = rootCtx |
| 48 | + line = getLine() |
| 49 | + } |
| 50 | + if (line.startsWith(quit)) ctx.typerState.reporter |
| 51 | + else loop(line split "\\s+", nextCtx) |
| 52 | + } |
| 53 | + loop(args, rootCtx) |
| 54 | + } |
| 55 | +} |
0 commit comments