diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 25 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/InterpreterLoop.scala | 10 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index e16839956c..43852df28b 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -82,6 +82,17 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) * submitted command unless an exception is thrown. */ def beQuiet = { printResults = false } + /** Temporarily be quiet */ + def beQuietDuring[T](operation: => T): T = { + val wasPrinting = printResults + try { + printResults = false + operation + } finally { + printResults = wasPrinting + } + } + /** directory to save .class files to */ val classfilePath = File.createTempFile("scalaint", "") classfilePath.delete // the file is created as a file; make it a directory @@ -167,7 +178,6 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) private def parse(line: String): Option[List[Tree]] = { var justNeedsMore = false reporter.withIncompleteHandler((pos,msg) => {justNeedsMore = true}) { -//reporter.incompleteInputError = (pos,msg) => {justNeedsMore = true} // simple parse: just parse it, nothing else def simpleParse(code: String): List[Tree] = { val unit = @@ -329,6 +339,19 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) } + /** Make a dry run in order to fill caches. This is useful + * for interactive interpreters so that the interpreter responds + * quickly to the first user-supplied query. + */ + def prime: Unit = beQuietDuring { + interpret("0") + + // the next two lines are cosmetic; they cause + // the line number to go back to what it was + nextLineNo = nextLineNo - 1 + prevRequests.remove(prevRequests.length - 1) + } + /** <p> * This instance is no longer needed, so release any resources * it is using. diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala index 220cdfc8cf..6cc2fd27f3 100644 --- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala +++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala @@ -94,11 +94,16 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) { * <code>command()</code> for each line of input, and stops when * <code>command()</code> returns false. */ - def repl(): Unit = + def repl(): Unit = { + var firstTime = true while(true) { if(interactive) { out.print("\nscala> ") out.flush + if(firstTime) { + interpreter.prime + firstTime = false + } } var line = in.readLine() if (line eq null) @@ -114,6 +119,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) { case None => () } } + } /** interpret all lines from a specified file */ def interpretAllFrom(filename: String): Unit = { @@ -214,7 +220,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) { case IR.Success => Some(code) case IR.Error => None case IR.Incomplete => { - if(interactive && code.endsWith("\n\n\n")) { + if(interactive && code.endsWith("\n\n")) { out.println("Two blank lines seen. Aborting this expression.") None } else { |