aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-04-27 13:38:38 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-04-28 11:00:39 +0200
commit57670a38ca55cc04c9d765bdf04584cad5581d41 (patch)
tree0ebfbf8c55749bd27cb97f1f536647c6f63b015a /src/dotty/tools
parentd04984596c6abfa27b217b12a42caca26f0c269f (diff)
downloaddotty-57670a38ca55cc04c9d765bdf04584cad5581d41.tar.gz
dotty-57670a38ca55cc04c9d765bdf04584cad5581d41.tar.bz2
dotty-57670a38ca55cc04c9d765bdf04584cad5581d41.zip
Stop interpreter from interpreting twice on enter
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/repl/AmmoniteReader.scala4
-rw-r--r--src/dotty/tools/dotc/repl/CompilingInterpreter.scala25
-rw-r--r--src/dotty/tools/dotc/repl/Interpreter.scala6
-rw-r--r--src/dotty/tools/dotc/repl/InterpreterLoop.scala9
4 files changed, 39 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/repl/AmmoniteReader.scala b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
index a3b2a1c56..0a49b8ea3 100644
--- a/src/dotty/tools/dotc/repl/AmmoniteReader.scala
+++ b/src/dotty/tools/dotc/repl/AmmoniteReader.scala
@@ -15,9 +15,9 @@ class AmmoniteReader(val interpreter: Interpreter)(implicit ctx: Context) extend
val interactive = true
def incompleteInput(str: String): Boolean =
- interpreter.beQuietDuring(interpreter.interpret(str)) match {
+ interpreter.delayOutputDuring(interpreter.interpret(str)) match {
case Interpreter.Incomplete => true
- case _ => false // TODO: should perhaps save output here?
+ case _ => false
}
val reader = new java.io.InputStreamReader(System.in)
diff --git a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
index cfcce106e..d322aa404 100644
--- a/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
+++ b/src/dotty/tools/dotc/repl/CompilingInterpreter.scala
@@ -78,6 +78,27 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
/** whether to print out result lines */
private var printResults: Boolean = true
+ private var delayOutput: Boolean = false
+
+ var previousOutput: String = null
+
+ override def lastOutput() =
+ if (previousOutput == null) None
+ else {
+ val ret = Some(previousOutput)
+ previousOutput = null
+ ret
+ }
+
+ override def delayOutputDuring[T](operation: => T): T = {
+ val old = delayOutput
+ try {
+ delayOutput = true
+ operation
+ } finally {
+ delayOutput = old
+ }
+ }
/** Temporarily be quiet */
override def beQuietDuring[T](operation: => T): T = {
@@ -188,7 +209,9 @@ class CompilingInterpreter(out: PrintWriter, ictx: Context) extends Compiler wit
Interpreter.Error // an error happened during compilation, e.g. a type error
else {
val (interpreterResultString, succeeded) = req.loadAndRun()
- if (printResults || !succeeded)
+ if (delayOutput)
+ previousOutput = clean(interpreterResultString)
+ else if (printResults || !succeeded)
out.print(clean(interpreterResultString))
if (succeeded) {
prevRequests += req
diff --git a/src/dotty/tools/dotc/repl/Interpreter.scala b/src/dotty/tools/dotc/repl/Interpreter.scala
index ea587a097..590baae0d 100644
--- a/src/dotty/tools/dotc/repl/Interpreter.scala
+++ b/src/dotty/tools/dotc/repl/Interpreter.scala
@@ -33,4 +33,10 @@ trait Interpreter {
/** Suppress output during evaluation of `operation`. */
def beQuietDuring[T](operation: => T): T
+
+ /** Suppresses output and saves it for `lastOutput` to collect */
+ def delayOutputDuring[T](operation: => T): T
+
+ /** Gets the last output not printed immediately */
+ def lastOutput(): Option[String]
}
diff --git a/src/dotty/tools/dotc/repl/InterpreterLoop.scala b/src/dotty/tools/dotc/repl/InterpreterLoop.scala
index 64414fec3..53fd09c07 100644
--- a/src/dotty/tools/dotc/repl/InterpreterLoop.scala
+++ b/src/dotty/tools/dotc/repl/InterpreterLoop.scala
@@ -18,7 +18,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
* After instantiation, clients should call the `run` method.
*
* @author Moez A. Abdel-Gawad
- * @author Lex Spoon
+ * @author Lex Spoon
* @author Martin Odersky
*/
class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Context) {
@@ -167,7 +167,12 @@ class InterpreterLoop(compiler: Compiler, config: REPL.Config)(implicit ctx: Con
else if (line startsWith ":")
output.println("Unknown command. Type :help for help.")
else
- shouldReplay = interpretStartingWith(line)
+ shouldReplay = interpreter.lastOutput() match { // don't interpret twice
+ case Some(oldRes) =>
+ output.print(oldRes)
+ Some(line)
+ case _ => interpretStartingWith(line)
+ }
(true, shouldReplay)
}