summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala17
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala26
2 files changed, 24 insertions, 19 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index d8507a4e7c..489a0161ba 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -6,6 +6,7 @@
package scala.tools.nsc
+import Predef.{ println => _, _ }
import java.io.{ File, PrintWriter, StringWriter, Writer }
import File.pathSeparator
import java.lang.{ Class, ClassLoader }
@@ -538,10 +539,10 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
compileSources(new BatchSourceFile("<script>", code))
def compileAndSaveRun(label: String, code: String) = {
- if (settings.Yrepldebug.value) {
+ if (isReplDebug) {
parse(code) match {
- case Some(trees) => trees foreach (t => println(compiler.asCompactString(t)))
- case _ => println("Parse error:\n\n" + code)
+ case Some(trees) => trees foreach (t => DBG(compiler.asCompactString(t)))
+ case _ => DBG("Parse error:\n\n" + code)
}
}
val run = new compiler.Run()
@@ -1115,7 +1116,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
*/
def eval[T: Manifest](line: String): Option[T] =
try Some(evalExpr[T](line))
- catch { case InterpreterEvalException(msg) => println(indentString(msg)) ; None }
+ catch { case InterpreterEvalException(msg) => out println indentString(msg) ; None }
def evalExpr[T: Manifest](line: String): T = {
// Nothing means the type could not be inferred.
@@ -1145,7 +1146,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
interpret(code) match {
case IR.Success =>
try prevRequests.last.extractionValue map (_.asInstanceOf[T])
- catch { case e: Exception => println(e) ; None }
+ catch { case e: Exception => out println e ; None }
case _ => None
}
}
@@ -1189,8 +1190,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
// }
// debugging
- private var debuggingOutput = false
- def DBG(s: String) = if (debuggingOutput) out println s else ()
+ def isReplDebug = settings.Yrepldebug.value
+ def DBG(s: String) = if (isReplDebug) out println s else ()
}
/** Utility methods for the Interpreter. */
@@ -1252,7 +1253,7 @@ object Interpreter {
intLoop.interpreter.interpret("""def exit = println("Type :quit to resume program execution.")""")
for (p <- args) {
intLoop.interpreter.bind(p.name, p.typeStr, p.param)
- println("%s: %s".format(p.name, p.typeStr))
+ Console println "%s: %s".format(p.name, p.typeStr)
}
}
intLoop.repl()
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 1ef249735f..9d568418f8 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -6,6 +6,7 @@
package scala.tools.nsc
+import Predef.{ println => _, _ }
import java.io.{ BufferedReader, FileReader, PrintWriter }
import java.io.IOException
@@ -20,7 +21,9 @@ import io.{ File, Process }
// Classes to wrap up interpreter commands and their results
// You can add new commands by adding entries to val commands
// inside InterpreterLoop.
-object InterpreterControl {
+trait InterpreterControl {
+ self: InterpreterLoop =>
+
// the default result means "keep running, and don't record that line"
val defaultResult = Result(true, None)
@@ -29,7 +32,7 @@ object InterpreterControl {
def name: String
def help: String
def error(msg: String) = {
- println(":" + name + " " + msg + ".")
+ out.println(":" + name + " " + msg + ".")
Result(true, None)
}
def usage(): String
@@ -60,7 +63,6 @@ object InterpreterControl {
// the result of a single command
case class Result(keepRunning: Boolean, lineToRecord: Option[String])
}
-import InterpreterControl._
/** The
* <a href="http://scala-lang.org/" target="_top">Scala</a>
@@ -76,7 +78,7 @@ import InterpreterControl._
* @author Lex Spoon
* @version 1.2
*/
-class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
+class InterpreterLoop(in0: Option[BufferedReader], protected val out: PrintWriter) extends InterpreterControl {
def this(in0: BufferedReader, out: PrintWriter) = this(Some(in0), out)
def this() = this(None, new PrintWriter(Console.out))
@@ -140,8 +142,7 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
|Type :help for more information.""" .
stripMargin.format(versionString, javaVmName, javaVersion)
- out println welcomeMsg
- out.flush
+ plushln(welcomeMsg)
}
/** Show the history */
@@ -160,6 +161,11 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
println("%d %s".format(index + offset, line))
}
+ /** Some print conveniences */
+ def println(x: Any) = out println x
+ def plush(x: Any) = { out print x ; out.flush() }
+ def plushln(x: Any) = { out println x ; out.flush() }
+
/** Search the history */
def searchHistory(_cmdline: String) {
val cmdline = _cmdline.toLowerCase
@@ -265,8 +271,7 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
try {
fileIn applyReader { reader =>
in = new SimpleReader(reader, out, false)
- out.println("Loading " + filename + "...")
- out.flush
+ plushln("Loading " + filename + "...")
repl
}
}
@@ -281,8 +286,7 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
closeInterpreter()
createInterpreter()
for (cmd <- replayCommands) {
- out.println("Replaying: " + cmd)
- out.flush() // because maybe cmd will have its own output
+ plushln("Replaying: " + cmd) // flush because maybe cmd will have its own output
command(cmd)
out.println
}
@@ -618,7 +622,7 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
// if they asked for no help and command is valid, we call the real main
neededHelp() match {
case "" => if (command.ok) main(command.settings) // else nothing
- case help => out print help ; out flush
+ case help => plush(help)
}
}
}