From 901cdc1855e8e80957b18add4991736b9f458d77 Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Mon, 2 Sep 2013 15:51:56 +0200 Subject: refine block and applied/typeapplied splicing/matching semantics 1. blocks now match single term-level expressions to account for automatic block elimination. E.g. val q"{ ..$stats }" = q"foo" will match into stats = List(q"foo"). This is useful to uniformly deal with blocks on term level. 2. blocks in quasiquotes collapse into single expressions 3. Applied and TypeApplied now have constructors too which helps to unify matching and extraction in quasiquote reifier 4. TypeApplied now matches AppliedTypeTree too 5. Add Syntactic prefix to Applied and TypeApplied --- .../plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/continuations/plugin') diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala index 908ffb3713..a2c2ebc3e3 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala @@ -330,8 +330,6 @@ abstract class SelectiveCPSTransform extends PluginComponent with } } - def mkBlock(stms: List[Tree], expr: Tree) = if (stms.nonEmpty) Block(stms, expr) else expr - try { if (specialCaseTrivial) { debuglog("will optimize possible tail call: " + bodyExpr) @@ -350,9 +348,9 @@ abstract class SelectiveCPSTransform extends PluginComponent with val argSym = currentOwner.newValue(vd.symbol.name.toTermName).setInfo(tpe) val argDef = localTyper.typed(ValDef(argSym, Select(ctxRef, ctxRef.tpe.member(cpsNames.getTrivialValue)))) val switchExpr = localTyper.typedPos(vd.symbol.pos) { - val body2 = mkBlock(bodyStms, bodyExpr).duplicate // dup before typing! + val body2 = gen.mkBlock(bodyStms :+ bodyExpr).duplicate // dup before typing! If(Select(ctxRef, ctxSym.tpe.member(cpsNames.isTrivial)), - applyTrivial(argSym, mkBlock(argDef::bodyStms, bodyExpr)), + applyTrivial(argSym, gen.mkBlock((argDef :: bodyStms) :+ bodyExpr)), applyCombinatorFun(ctxRef, body2)) } (List(ctxDef), switchExpr) @@ -360,7 +358,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with // ctx.flatMap { => ... } // or // ctx.map { => ... } - (Nil, applyCombinatorFun(rhs1, mkBlock(bodyStms, bodyExpr))) + (Nil, applyCombinatorFun(rhs1, gen.mkBlock(bodyStms :+ bodyExpr))) } } catch { case ex:TypeError => -- cgit v1.2.3