diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-11-23 15:58:13 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-11-23 17:28:19 +0100 |
commit | 4c1c9fcf075d6e1e5975a04c5a2ced674716069a (patch) | |
tree | 3b507edc6b3e33bafd9fe69cfbc7dbe3ff7514b9 /src/main/scala | |
parent | 8658394b2cbd70db4fcb9048c347bb6b6c4db628 (diff) | |
download | scala-async-4c1c9fcf075d6e1e5975a04c5a2ced674716069a.tar.gz scala-async-4c1c9fcf075d6e1e5975a04c5a2ced674716069a.tar.bz2 scala-async-4c1c9fcf075d6e1e5975a04c5a2ced674716069a.zip |
Fix #31, Unfinished ANF transform
Prepend {(); ... } before starting the ANF transform.
Add tracing to the anf/inline transform.
Also enables and addresses SIP-18 warnings.
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/scala/async/AnfTransform.scala | 35 | ||||
-rw-r--r-- | src/main/scala/scala/async/Async.scala | 7 |
2 files changed, 33 insertions, 9 deletions
diff --git a/src/main/scala/scala/async/AnfTransform.scala b/src/main/scala/scala/async/AnfTransform.scala index 6bf6e9a..a69fd4e 100644 --- a/src/main/scala/scala/async/AnfTransform.scala +++ b/src/main/scala/scala/async/AnfTransform.scala @@ -3,11 +3,21 @@ package scala.async import scala.reflect.macros.Context +object AnfTranform { + def apply[C <: Context](c: C): AnfTransform[c.type] = new AnfTransform[c.type](c) +} + class AnfTransform[C <: Context](override val c: C) extends TransformUtils(c) { import c.universe._ - def uniqueNames(tree: Tree): Tree = { + def apply(tree: Tree): List[Tree] = { + val unique = uniqueNames(tree) + // Must prepend the () for issue #31. + anf.transformToList(Block(List(c.literalUnit.tree), unique)) + } + + private def uniqueNames(tree: Tree): Tree = { new UniqueNames(tree).transform(tree) } @@ -65,8 +75,25 @@ class AnfTransform[C <: Context](override val c: C) extends TransformUtils(c) { } } + final class Indent { + private var indent = -1 + def indentString = " " * indent + def apply[T](prefix: String, args: Any)(t: => T): T = { + indent += 1 + try { + //println(s"${indentString}$prefix($args)") + val result = t + //println(s"${indentString}= $result") + result + } finally { + indent -= 1 + } + } + } + private val indent = new Indent + object inline { - def transformToList(tree: Tree): List[Tree] = { + def transformToList(tree: Tree): List[Tree] = indent("inline", tree) { val stats :+ expr = anf.transformToList(tree) expr match { case Apply(fun, args) if isAwait(fun) => @@ -133,9 +160,9 @@ class AnfTransform[C <: Context](override val c: C) extends TransformUtils(c) { vd } } - object anf { - def transformToList(tree: Tree): List[Tree] = { + + private[AnfTransform] def transformToList(tree: Tree): List[Tree] = indent("anf", tree) { def containsAwait = tree exists isAwait tree match { case Select(qual, sel) if containsAwait => diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala index 0b77c78..ed79d0b 100644 --- a/src/main/scala/scala/async/Async.scala +++ b/src/main/scala/scala/async/Async.scala @@ -78,12 +78,9 @@ abstract class AsyncBase { // - no await calls in qualifiers or arguments, // - if/match only used in statement position. val anfTree: Block = { - val transform = new AnfTransform[c.type](c) - val unique = transform.uniqueNames(body.tree) - val stats1 :+ expr1 = transform.anf.transformToList(unique) - + val anf = AnfTranform(c) + val stats1 :+ expr1 = anf(body.tree) val block = Block(stats1, expr1) - c.typeCheck(block).asInstanceOf[Block] } |