diff options
author | Paul Phillips <paulp@improving.org> | 2011-04-07 07:30:38 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-04-07 07:30:38 +0000 |
commit | 6a204df670a118be6a31676ed26a20a6408e2ab6 (patch) | |
tree | 7e9a4fb57a7277934f7c75d9c0e8bbb78f6c63f7 | |
parent | f36e7acd02134fed6f27a61e82bf454a68684499 (diff) | |
download | scala-6a204df670a118be6a31676ed26a20a6408e2ab6.tar.gz scala-6a204df670a118be6a31676ed26a20a6408e2ab6.tar.bz2 scala-6a204df670a118be6a31676ed26a20a6408e2ab6.zip |
Clamping down on some more breakage which snuck...
Clamping down on some more breakage which snuck into power mode. I
really need some power tests. No review.
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ILoop.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/Power.scala | 45 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ReplVals.scala | 20 |
3 files changed, 44 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala index 75503be3d1..511581b5af 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala @@ -8,7 +8,6 @@ package interpreter import Predef.{ println => _, _ } import java.io.{ BufferedReader, FileReader, PrintWriter } - import scala.sys.process.Process import session._ import scala.tools.nsc.interpreter.{ Results => IR } @@ -361,6 +360,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter) if (line == "") "Cleared wrapper." else "Set wrapper to '" + line + "'" } + private def pathToPhaseWrapper = intp.pathToTerm("$r") + ".phased.atCurrent" private def phaseCommand(name: String): Result = { // This line crashes us in TreeGen: // @@ -391,7 +391,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter) if (what.isEmpty || !phased.set(what)) "'" + name + "' does not appear to represent a valid phase." else { - intp.setExecutionWrapper("phased.atCurrent") + intp.setExecutionWrapper(pathToPhaseWrapper) val activeMessage = if (what.toString.length == name.length) "" + what else "%s (%s)".format(what, name) diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala index d608cccd56..5cbf13c298 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Power.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala @@ -43,19 +43,17 @@ trait SharesGlobal[G <: Global] { object Power { def apply[G <: Global](repl: ILoop, g: G) = - new { final val global: G = g } - with Power[G](repl, repl.intp) // .asInstanceOf[IMain { val global: G }]) + new { final val global: G = g } with Power[G](repl, repl.intp) def apply(intp: IMain) = - new { final val global = intp.global } - with Power[Global](null, intp) + new { final val global = intp.global } with Power[Global](null, intp) } /** A class for methods to be injected into the intp in power mode. */ abstract class Power[G <: Global]( val repl: ILoop, - val intp: IMain // { val global: G } + val intp: IMain ) extends SharesGlobal[G] { import intp.{ beQuietDuring, interpret, parse } import global.{ opt, definitions, stringToTermName, NoSymbol, NoType, analyzer, CompilationUnit } @@ -132,24 +130,25 @@ abstract class Power[G <: Global]( def init = """ |import scala.tools.nsc._ - |import interpreter.Power |import scala.collection.JavaConverters._ - |final val global = repl.power.global - |final val power = repl.power.asInstanceOf[Power[global.type]] - |final val intp = repl.intp |import global._ - |import definitions._ - |import power.Implicits.{ global => _, _ } - |import power.Utilities._ """.stripMargin /** Starts up power mode and runs whatever is in init. */ def unleash(): Unit = beQuietDuring { + val r = new ReplVals(repl) intp.bind[ILoop]("repl", repl) - intp.bind[History]("history", repl.in.history) - intp.bind("completion", repl.in.completion) - intp.bind[ISettings]("isettings", intp.isettings) + intp.bind[ReplVals]("$r", r) + + intp.bind("intp", r.intp) + intp.bind("global", r.global) + intp.bind("power", r.power) + intp.bind("phased", r.phased) + intp.bind("isettings", r.isettings) + intp.bind("completion", r.completion) + intp.bind("history", r.history) + init split '\n' foreach interpret } @@ -218,8 +217,8 @@ abstract class Power[G <: Global]( def prettify(x: Any): List[String] = x match { case x: Name => List(x.decode) case Tuple2(k, v) => List(prettify(k) ++ Seq("->") ++ prettify(v) mkString " ") - case xs: TraversableOnce[_] => (xs.toList flatMap prettify).sorted.distinct - case x => List(Utilities.stringOf(x)) + case xs: TraversableOnce[_] => (xs.toList flatMap prettify).sorted + case x => List(rutil.stringOf(x)) } } } @@ -318,6 +317,7 @@ abstract class Power[G <: Global]( object Implicits extends Implicits2 { val global = Power.this.global } + trait ReplUtilities { def ?[T: Manifest] = InternalInfo[T] def url(s: String) = { @@ -341,12 +341,11 @@ abstract class Power[G <: Global]( } def stringOf(x: Any): String = scala.runtime.ScalaRunTime.stringOf(x) } - object Utilities extends ReplUtilities { - object phased extends Phased with SharesGlobal[G] { - val global: G = Power.this.global - } + + lazy val rutil: ReplUtilities = new ReplUtilities { } + lazy val phased: Phased = new Phased with SharesGlobal[G] { + val global: G = Power.this.global } - lazy val phased = Utilities.phased def context(code: String) = analyzer.rootContext(unit(code)) def source(code: String) = new BatchSourceFile("<console>", code) @@ -360,7 +359,7 @@ abstract class Power[G <: Global]( |Names: %s |Identifiers: %s """.stripMargin.format( - Utilities.phased.get, + phased.get, intp.allDefinedNames mkString " ", intp.unqualifiedIds mkString " " ) diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala new file mode 100644 index 0000000000..2c5f5474af --- /dev/null +++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala @@ -0,0 +1,20 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools.nsc +package interpreter + +import java.lang.reflect.{ Method => JMethod } + +class ReplVals(final val r: ILoop) { + final val intp = r.intp + final val global = r.power.global + final val power = r.power + final val phased = r.power.phased + final val isettings = r.intp.isettings + final val completion = r.in.completion + final val history = r.in.history + final val rutil = r.power.rutil +} |