summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util
diff options
context:
space:
mode:
authorRaphael Jolly <rjolly@users.sourceforge.net>2014-01-30 13:29:02 +0100
committerRaphael Jolly <rjolly@users.sourceforge.net>2014-01-31 10:06:36 +0100
commit9dfac45e808017982e04fb20567c70b76dee3ede (patch)
tree4be4bf4202d87973b8f852e7c45a811720ff5923 /src/compiler/scala/tools/nsc/util
parent8f6f4032b5c026fd9301cebe28dde5bb7c8e264c (diff)
downloadscala-9dfac45e808017982e04fb20567c70b76dee3ede.tar.gz
scala-9dfac45e808017982e04fb20567c70b76dee3ede.tar.bz2
scala-9dfac45e808017982e04fb20567c70b76dee3ede.zip
SI-7933 REPL javax.script eval is cached result
The problem is that the repl underneath the script engine evaluates input to val res0..resN, so it is a one shot operation. To allow repetition, compile(script) now returns a CompiledScript object whose eval method can be called any number of times.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util')
-rw-r--r--src/compiler/scala/tools/nsc/util/package.scala13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/util/package.scala b/src/compiler/scala/tools/nsc/util/package.scala
index 4237f36ade..bd95fdbb50 100644
--- a/src/compiler/scala/tools/nsc/util/package.scala
+++ b/src/compiler/scala/tools/nsc/util/package.scala
@@ -7,7 +7,7 @@ package scala
package tools
package nsc
-import java.io.{ OutputStream, PrintStream, ByteArrayOutputStream, PrintWriter, StringWriter }
+import java.io.{ OutputStream, PrintStream, ByteArrayOutputStream, PrintWriter, StringWriter, Reader }
package object util {
// forwarder for old code that builds against 2.9 and 2.10
@@ -46,6 +46,17 @@ package object util {
(result, ts2 filterNot (ts1 contains _))
}
+ def stringFromReader(reader: Reader) = {
+ val writer = new StringWriter()
+ var c = reader.read()
+ while(c != -1) {
+ writer.write(c)
+ c = reader.read()
+ }
+ reader.close()
+ writer.toString()
+ }
+
/** Generate a string using a routine that wants to write on a stream. */
def stringFromWriter(writer: PrintWriter => Unit): String = {
val stringWriter = new StringWriter()