diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/Power.scala | 15 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ReplVals.scala | 42 | ||||
-rw-r--r-- | test/files/run/repl-power.check | 2 |
3 files changed, 20 insertions, 39 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 } diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check index 1b3883a839..38e7532133 100644 --- a/test/files/run/repl-power.check +++ b/test/files/run/repl-power.check @@ -11,6 +11,6 @@ scala> :power scala> // guarding against "error: reference to global is ambiguous" scala> global.emptyValDef // "it is imported twice in the same scope by ..." -res0: global.emptyValDef.type = private val _ = _ +res0: $r.global.emptyValDef.type = private val _ = _ scala> |