diff options
author | Paul Phillips <paulp@improving.org> | 2011-07-12 21:59:11 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-07-12 21:59:11 +0000 |
commit | 0fac26971e78fbe79b2ba5aaa87bde63816ac028 (patch) | |
tree | 47f877ba76438a53047bd845c2ba9a0c918560ff /src | |
parent | 70da5a627fe2ce15df64741b5784ed97c361a95e (diff) | |
download | scala-0fac26971e78fbe79b2ba5aaa87bde63816ac028.tar.gz scala-0fac26971e78fbe79b2ba5aaa87bde63816ac028.tar.bz2 scala-0fac26971e78fbe79b2ba5aaa87bde63816ac028.zip |
Making power mode startup a little less glacial...
Making power mode startup a little less glacial, no review.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/Power.scala | 15 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ReplVals.scala | 42 |
2 files changed, 19 insertions, 38 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala index 95e2e99dd1..95b42ebf69 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Power.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala @@ -147,18 +147,19 @@ abstract class Power( ) def init = customInit match { - case Some(x) => List(x) - case _ => initImports map ("import " + _) + case Some(x) => x + case _ => initImports.mkString("import ", ", ", "") } /** Starts up power mode and runs whatever is in init. */ def unleash(): Unit = beQuietDuring { - val r = new ReplVals(repl) - intp.bind("$r", r) - r bindWithPrefix intp.pathToTerm("$r") // binds all the vals - - init foreach interpret + // First we create the ReplVals instance and bind it to $r + intp.bind("$r", new ReplVals(repl)) + // Then we import everything from $r. + intp interpret ("import " + intp.pathToTerm("$r") + "._") + // And whatever else there is to do. + init.lines foreach (intp interpret _) } trait LowPriorityInternalInfo { diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala index 80ccd06c70..2f2489b242 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala @@ -6,35 +6,15 @@ package scala.tools.nsc package interpreter -import java.lang.reflect.{ Method => JMethod, Modifier => JModifier } - -final class ReplVals(final val r: ILoop) { - final val vals = this - final val intp = r.intp - final val global = intp.global - final val power = r.power - final val phased = power.phased - final val isettings = intp.isettings - final val completion = r.in.completion - final val history = r.in.history - final val rutil = power.rutil - - /** Reflectively finds the vals defined in this class. */ - private def valMethods = this.getClass.getDeclaredMethods.toList filter { m => - ( - JModifier.isPublic(m.getModifiers()) - && m.getParameterTypes.isEmpty - && !m.getName.contains('$') - ) - } - - /** Binds each val declared here into the repl with explicit singleton types - * based on the given prefix. - */ - def bindWithPrefix(prefix: String) { - valMethods foreach { m => - repldbg("intp.bind " + (m.getName, prefix + "." + m.getName + ".type", m.invoke(this))) - intp.bind(m.getName, prefix + "." + m.getName + ".type", m.invoke(this)) - } - } +final class ReplVals(r: ILoop) { + lazy val repl = r + lazy val intp = r.intp + lazy val power = r.power + lazy val reader = r.in + lazy val vals = this + lazy val global = intp.global + lazy val isettings = intp.isettings + lazy val completion = reader.completion + lazy val history = reader.history + lazy val phased = power.phased } |