diff options
author | Martin Odersky <odersky@gmail.com> | 2016-02-13 22:35:57 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-02-17 18:38:52 +0100 |
commit | 6ecdc8a69db1a808269b1c288284a4a430ce865e (patch) | |
tree | c641eac92c93ca5d59f1c9c531633ae7eaffc72e /src/dotty/tools/dotc/REPL.scala | |
parent | 5f5eca9ee9367c57da8138f2618759dfc86ffb71 (diff) | |
download | dotty-6ecdc8a69db1a808269b1c288284a4a430ce865e.tar.gz dotty-6ecdc8a69db1a808269b1c288284a4a430ce865e.tar.bz2 dotty-6ecdc8a69db1a808269b1c288284a4a430ce865e.zip |
First PoC of REPL
Adaptation of REPL by Spoon from ca 2007. Compiles OK, but
not yet tested.
Diffstat (limited to 'src/dotty/tools/dotc/REPL.scala')
-rw-r--r-- | src/dotty/tools/dotc/REPL.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/REPL.scala b/src/dotty/tools/dotc/REPL.scala new file mode 100644 index 000000000..a0255efa6 --- /dev/null +++ b/src/dotty/tools/dotc/REPL.scala @@ -0,0 +1,47 @@ +package dotty.tools +package dotc + +import core.Phases +import core.Contexts.Context +import reporting.Reporter +import java.io.EOFException +import scala.annotation.tailrec +import io.VirtualDirectory +import java.io.{BufferedReader, File, FileReader, PrintWriter} +import repl._ + +/** A compiler which stays resident between runs. + * Usage: + * + * > scala dotty.tools.dotc.Resident <options> <initial files> + * + * dotc> "more options and files to compile" + * + * ... + * + * dotc> :reset // reset all options to the ones passed on the command line + * + * ... + * + * dotc> :q // quit + */ +class REPL extends Driver { + + def input(implicit ctx: Context): InteractiveReader = { + val emacsShell = System.getProperty("env.emacs", "") != "" + //println("emacsShell="+emacsShell) //debug + if (ctx.settings.Xnojline.value || emacsShell) new SimpleReader() + else InteractiveReader.createDefault() + } + + def output: PrintWriter = new NewLinePrintWriter(new ConsoleWriter, true) + + override def newCompiler(): Compiler = new repl.Interpreter(output) + + override def sourcesRequired = false + + override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = { + new InterpreterLoop(compiler, input, output).run() + ctx.reporter + } +} |