diff options
author | Paul Phillips <paulp@improving.org> | 2011-03-29 02:59:31 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-03-29 02:59:31 +0000 |
commit | 5ebbba7a711105d8b6b19ce6497b3dcef0039c6f (patch) | |
tree | 1e625d215c3c5f4bb7ca0bb375f448cbdff1f880 /src/compiler/scala/tools/nsc/interpreter/Phased.scala | |
parent | ebedbef6d186c4cc98c9c4445967af43225230dc (diff) | |
download | scala-5ebbba7a711105d8b6b19ce6497b3dcef0039c6f.tar.gz scala-5ebbba7a711105d8b6b19ce6497b3dcef0039c6f.tar.bz2 scala-5ebbba7a711105d8b6b19ce6497b3dcef0039c6f.zip |
Polishing the programmatic interface to the rep...
Polishing the programmatic interface to the repl and other bits
of machinery which we'll have to live with for a while. The repl
classloader now works more like you'd expect a classloader to, as seen
here:
% scala -Dscala.repl.power
scala> class Bippus extends Traversable[Int] { def foreach[U](f: Int => U) = () }
defined class Bippus
scala> intp.classLoader.getResourceAsStream("Bippus").bytes()
res0: Array[Byte] = Array(-54, -2, -70, ...
scala> res0.size
res1: Int = 23954
scala> case class Bippy(x: Int)
defined class Bippy
// classBytes is shorter way to say the same thing scala>
intp.classLoader.classBytes("Bippy").size
res2: Int = 2356
scala> intp.classLoader.classBytes("Bippy$").size
res3: Int = 1741
Closes #4399, no review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/Phased.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/Phased.scala | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/Phased.scala b/src/compiler/scala/tools/nsc/interpreter/Phased.scala index 1406d2af39..b3d33325e4 100644 --- a/src/compiler/scala/tools/nsc/interpreter/Phased.scala +++ b/src/compiler/scala/tools/nsc/interpreter/Phased.scala @@ -6,6 +6,9 @@ package scala.tools.nsc package interpreter +import scala.collection.{ mutable, immutable } +import immutable.SortedMap + /** Mix this into an object and use it as a phasing * swiss army knife. */ @@ -63,11 +66,14 @@ trait Phased { try parseInternal(str) catch { case _: Exception => NoPhaseName } - def apply[T](body: => T): T = atPhase(get)(body) + def apply[T](body: => T): SortedMap[PhaseName, T] = + SortedMap[PhaseName, T](atMap(PhaseName.all)(body): _*) + + def atCurrent[T](body: => T): T = atPhase(get)(body) def multi[T](body: => T): Seq[T] = multi map (ph => at(ph)(body)) - def all[T](body: => T): Seq[T] = ats(PhaseName.all)(body) - def allshow[T](body: => T): Seq[T] = { - val pairs = atz(PhaseName.all)(body) + def all[T](body: => T): Seq[T] = atMulti(PhaseName.all)(body) + def show[T](body: => T): Seq[T] = { + val pairs = atMap(PhaseName.all)(body) pairs foreach { case (ph, op) => Console.println("%15s -> %s".format(ph, op.toString take 240)) } pairs map (_._2) } @@ -75,25 +81,27 @@ trait Phased { def at[T](ph: PhaseName)(body: => T): T = { val saved = get set(ph) - try apply(body) + try atCurrent(body) finally set(saved) } - def ats[T](phs: Seq[PhaseName])(body: => T): Seq[T] = { + def atMulti[T](phs: Seq[PhaseName])(body: => T): Seq[T] = { val saved = multi setMulti(phs) try multi(body) finally setMulti(saved) } - def atshow[T](phs: Seq[PhaseName])(body: => T): Unit = - atz[T](phs)(body) foreach { + def showAt[T](phs: Seq[PhaseName])(body: => T): Unit = + atMap[T](phs)(body) foreach { case (ph, op) => Console.println("%15s -> %s".format(ph, op.toString take 240)) } - def atz[T](phs: Seq[PhaseName])(body: => T): Seq[(PhaseName, T)] = - phs zip ats(phs)(body) + def atMap[T](phs: Seq[PhaseName])(body: => T): Seq[(PhaseName, T)] = + phs zip atMulti(phs)(body) object PhaseName { + implicit lazy val phaseNameOrdering: Ordering[PhaseName] = Ordering[Int] on (_.id) + lazy val all = List( Parser, Namer, Packageobjects, Typer, Superaccessors, Pickler, Refchecks, Selectiveanf, Liftcode, Selectivecps, Uncurry, Tailcalls, Specialize, |