From 6ecdc8a69db1a808269b1c288284a4a430ce865e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 13 Feb 2016 22:35:57 +0100 Subject: First PoC of REPL Adaptation of REPL by Spoon from ca 2007. Compiles OK, but not yet tested. --- src/dotty/tools/dotc/REPL.scala | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/dotty/tools/dotc/REPL.scala (limited to 'src/dotty/tools/dotc/REPL.scala') 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 + * + * 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 + } +} -- cgit v1.2.3