diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-28 22:45:53 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-28 22:45:53 +0000 |
commit | ebedbef6d186c4cc98c9c4445967af43225230dc (patch) | |
tree | 3f52fb0d8ee5be372607679f2af2d8c085e8b556 /src/compiler | |
parent | b3889b68af7aa2bcc31a4d6b9e1e6fba5d4e1757 (diff) | |
download | scala-ebedbef6d186c4cc98c9c4445967af43225230dc.tar.gz scala-ebedbef6d186c4cc98c9c4445967af43225230dc.tar.bz2 scala-ebedbef6d186c4cc98c9c4445967af43225230dc.zip |
Made ScalaRunTime.stringOf more general by sepa...
Made ScalaRunTime.stringOf more general by separating out the part which
formats it for a repl result, and cleaned up some string functions
around the repl. No review.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/IMain.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala | 11 |
2 files changed, 7 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index d74aa5e6df..1a50b87569 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -102,11 +102,8 @@ class IMain(val settings: Settings, protected val out: PrintWriter) { private def _initialize(): Boolean = { val source = """ - |// this is assembled to force the loading of approximately the - |// classes which will be loaded on the first expression anyway. |class $repl_$init { - | val x = "abc".reverse.length + (5 max 5) - | scala.runtime.ScalaRunTime.stringOf(x) + | List(1) map (_ + 1) |} |""".stripMargin @@ -497,7 +494,6 @@ class IMain(val settings: Settings, protected val out: PrintWriter) { def compileString(code: String): Boolean = compileSources(new BatchSourceFile("<script>", code)) - /** Build a request from the user. `trees` is `line` after being parsed. */ private def buildRequest(line: String, trees: List[Tree]): Request = new Request(line, trees) diff --git a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala index 29c31f50d6..f98da3aeac 100644 --- a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala +++ b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala @@ -18,7 +18,11 @@ trait MemberHandlers { import global._ import naming._ - def string2codeQuoted(str: String) = "\"" + string2code(str) + "\"" + def string2codeQuoted(str: String) = + "\"" + string2code(str) + "\"" + + def any2stringOf(x: Any, maxlen: Int) = + "scala.runtime.ScalaRunTime.replStringOf(%s, %s)".format(x, maxlen) /** Convert a string into code that can recreate the string. * This requires replacing all special characters by escape @@ -32,8 +36,6 @@ trait MemberHandlers { } res.toString } - def any2stringOf(x: Any, maxlen: Int) = - "scala.runtime.ScalaRunTime.stringOf(%s, %s)".format(x, maxlen) private def codegenln(leadingPlus: Boolean, xs: String*): String = codegen(leadingPlus, (xs ++ Array("\n")): _*) private def codegenln(xs: String*): String = codegenln(true, xs: _*) @@ -121,7 +123,6 @@ trait MemberHandlers { class ValHandler(member: ValDef) extends MemberDefHandler(member) { val maxStringElements = 1000 // no need to mkString billions of elements - def stringOf(x: Any) = any2stringOf(x, maxStringElements) override def definesValue = true override def resultExtractionCode(req: Request): String = { @@ -131,7 +132,7 @@ trait MemberHandlers { // if this is a lazy val we avoid evaluating it here val resultString = if (mods.isLazy) codegenln(false, "<lazy>") - else stringOf(req fullPath name) + else any2stringOf(req fullPath name, maxStringElements) """ + "%s: %s = " + %s""".format(prettyName, string2code(req typeOf name), resultString) } |