diff options
author | Martin Odersky <odersky@gmail.com> | 2009-05-26 18:18:11 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-05-26 18:18:11 +0000 |
commit | 5b2dec1e9ea1a41112d87a37a16811b71bdaf273 (patch) | |
tree | 6ebecdda4ca6b49d12d106e59d11cf9d0574041c /src/compiler/scala/tools/nsc/interactive/REPL.scala | |
parent | 103c97f7deef02d81d6d87c21f751899c63683b1 (diff) | |
download | scala-5b2dec1e9ea1a41112d87a37a16811b71bdaf273.tar.gz scala-5b2dec1e9ea1a41112d87a37a16811b71bdaf273.tar.bz2 scala-5b2dec1e9ea1a41112d87a37a16811b71bdaf273.zip |
new test repl for interactive mode; bug fixes
Diffstat (limited to 'src/compiler/scala/tools/nsc/interactive/REPL.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/REPL.scala | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala index cd83ddf082..11def170b5 100644 --- a/src/compiler/scala/tools/nsc/interactive/REPL.scala +++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala @@ -1,15 +1,20 @@ package scala.tools.nsc.interactive import scala.concurrent.SyncVar -import scala.tools.nsc.io.AbstractFile -import scala.tools.nsc.util.{SourceFile, Position, WorkScheduler} +import scala.tools.nsc.util._ import scala.tools.nsc.symtab._ import scala.tools.nsc.ast._ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.io._ /** Interface of interactive compiler to a client such as an IDE */ -object REPL /* extends EvalLoop */ { -} +object REPL extends EvalLoop { + + val settings = new Settings() + val comp = new Global(settings, new ConsoleReporter(settings)) + + def prompt = "> " /** Commands: * @@ -17,56 +22,39 @@ object REPL /* extends EvalLoop */ { * typeat file line col * * + */ def run() { + val reloadResult = new SyncVar[Either[Unit, Throwable]] + val typeatResult = new SyncVar[Either[comp.Tree, Throwable]] loop { line => - - + (line split " ").toList match { + case "reload" :: args => + comp.askReload(args map toSourceFile, reloadResult) + show(reloadResult) + case List("typeat", file, line, col1, col2) => + val source = toSourceFile(file) + val linestart = source.lineToOffset(line.toInt) + val pos = comp.rangePos(source, linestart + col1.toInt, linestart + col1.toInt, linestart + col2.toInt) + comp.askTypeAt(pos, typeatResult) + show(typeatResult) + case List("quit") => + System.exit(1) + case _ => + println("unrecongized command") + } } + } - def process(args: Array[String]) { - val settings = new Settings(error) - reporter = new ConsoleReporter(settings) - val command = new CompilerCommand(List.fromArray(args), settings, error, false) - if (command.settings.version.value) - reporter.info(null, versionMsg, true) - else { - if (command.settings.target.value == "msil") { - val libpath = System.getProperty("msil.libpath") - if (libpath != null) - command.settings.assemrefs.value = - command.settings.assemrefs.value + File.pathSeparator + libpath - } - try { - object compiler extends Global(command.settings, reporter) - if (reporter.hasErrors) { - reporter.flush() - return - } + def toSourceFile(name: String) = new BatchSourceFile(new PlainFile(new java.io.File(name))) - if (command.shouldStopWithInfo) { - reporter.info(null, command.getInfoMessage(compiler), true) - } else { - if (command.settings.resident.value) - resident(compiler) - else if (command.files.isEmpty) { - reporter.info(null, command.usageMsg, true) - reporter.info(null, compiler.pluginOptionsHelp, true) - } else { - val run = new compiler.Run() - run compile command.files - reporter.printSummary() - } - } - } catch { - case ex @ FatalError(msg) => - if (true || command.settings.debug.value) // !!! - ex.printStackTrace(); - reporter.error(null, "fatal error: " + msg) - } + def show[T](svar: SyncVar[Either[T, Throwable]]) { + svar.get match { + case Left(result) => println("==> "+result) + case Right(exc/*: Throwable ??*/) => exc.printStackTrace; println("ERROR: "+exc) } } - val comp = new Global - - def - */ + def main(args: Array[String]) { + run() + } +} |