diff options
Diffstat (limited to 'src/continuations')
3 files changed, 41 insertions, 26 deletions
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala index f4481b800e..8bbda5dd05 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala @@ -12,22 +12,37 @@ trait CPSUtils { var cpsEnabled = true val verbose: Boolean = System.getProperty("cpsVerbose", "false") == "true" def vprintln(x: =>Any): Unit = if (verbose) println(x) + + object cpsNames { + val catches = newTermName("$catches") + val ex = newTermName("$ex") + val flatMapCatch = newTermName("flatMapCatch") + val getTrivialValue = newTermName("getTrivialValue") + val isTrivial = newTermName("isTrivial") + val reify = newTermName("reify") + val reifyR = newTermName("reifyR") + val shift = newTermName("shift") + val shiftR = newTermName("shiftR") + val shiftSuffix = newTermName("$shift") + val shiftUnit = newTermName("shiftUnit") + val shiftUnitR = newTermName("shiftUnitR") + } - lazy val MarkerCPSSym = definitions.getClass("scala.util.continuations.cpsSym") - lazy val MarkerCPSTypes = definitions.getClass("scala.util.continuations.cpsParam") - lazy val MarkerCPSSynth = definitions.getClass("scala.util.continuations.cpsSynth") - lazy val MarkerCPSAdaptPlus = definitions.getClass("scala.util.continuations.cpsPlus") - lazy val MarkerCPSAdaptMinus = definitions.getClass("scala.util.continuations.cpsMinus") - - lazy val Context = definitions.getClass("scala.util.continuations.ControlContext") - lazy val ModCPS = definitions.getModule("scala.util.continuations") - - lazy val MethShiftUnit = definitions.getMember(ModCPS, "shiftUnit") - lazy val MethShiftUnitR = definitions.getMember(ModCPS, "shiftUnitR") - lazy val MethShift = definitions.getMember(ModCPS, "shift") - lazy val MethShiftR = definitions.getMember(ModCPS, "shiftR") - lazy val MethReify = definitions.getMember(ModCPS, "reify") - lazy val MethReifyR = definitions.getMember(ModCPS, "reifyR") + lazy val MarkerCPSSym = definitions.getRequiredClass("scala.util.continuations.cpsSym") + lazy val MarkerCPSTypes = definitions.getRequiredClass("scala.util.continuations.cpsParam") + lazy val MarkerCPSSynth = definitions.getRequiredClass("scala.util.continuations.cpsSynth") + lazy val MarkerCPSAdaptPlus = definitions.getRequiredClass("scala.util.continuations.cpsPlus") + lazy val MarkerCPSAdaptMinus = definitions.getRequiredClass("scala.util.continuations.cpsMinus") + + lazy val Context = definitions.getRequiredClass("scala.util.continuations.ControlContext") + lazy val ModCPS = definitions.getRequiredModule("scala.util.continuations") + + lazy val MethShiftUnit = definitions.getMember(ModCPS, cpsNames.shiftUnit) + lazy val MethShiftUnitR = definitions.getMember(ModCPS, cpsNames.shiftUnitR) + lazy val MethShift = definitions.getMember(ModCPS, cpsNames.shift) + lazy val MethShiftR = definitions.getMember(ModCPS, cpsNames.shiftR) + lazy val MethReify = definitions.getMember(ModCPS, cpsNames.reify) + lazy val MethReifyR = definitions.getMember(ModCPS, cpsNames.reifyR) lazy val allCPSAnnotations = List(MarkerCPSSym, MarkerCPSTypes, MarkerCPSSynth, MarkerCPSAdaptPlus, MarkerCPSAdaptMinus) diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala index b383227243..585dc3fbe8 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala @@ -355,7 +355,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with val valueTpe = removeAllCPSAnnotations(expr.tpe) - val sym = currentOwner.newValue(tree.pos, unit.fresh.newName("tmp")) + val sym = currentOwner.newValue(tree.pos, newTermName(unit.fresh.newName("tmp"))) .setInfo(valueTpe) .setFlag(Flags.SYNTHETIC) .setAnnotations(List(AnnotationInfo(MarkerCPSSym.tpe, Nil, Nil))) diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala index f0c389bb11..960b27c52f 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala @@ -192,21 +192,21 @@ abstract class SelectiveCPSTransform extends PluginComponent with // val expr2 = if (catches.nonEmpty) { val pos = catches.head.pos - val argSym = currentOwner.newValueParameter(pos, "$ex").setInfo(ThrowableClass.tpe) + val argSym = currentOwner.newValueParameter(pos, cpsNames.ex).setInfo(ThrowableClass.tpe) val rhs = Match(Ident(argSym), catches1) val fun = Function(List(ValDef(argSym)), rhs) - val funSym = currentOwner.newValueParameter(pos, "$catches").setInfo(appliedType(PartialFunctionClass.tpe, List(ThrowableClass.tpe, targettp))) + val funSym = currentOwner.newValueParameter(pos, cpsNames.catches).setInfo(appliedType(PartialFunctionClass.tpe, List(ThrowableClass.tpe, targettp))) val funDef = localTyper.typed(atPos(pos) { ValDef(funSym, fun) }) - val expr2 = localTyper.typed(atPos(pos) { Apply(Select(expr1, expr1.tpe.member("flatMapCatch")), List(Ident(funSym))) }) + val expr2 = localTyper.typed(atPos(pos) { Apply(Select(expr1, expr1.tpe.member(cpsNames.flatMapCatch)), List(Ident(funSym))) }) argSym.owner = fun.symbol val chown = new ChangeOwnerTraverser(currentOwner, fun.symbol) chown.traverse(rhs) - val exSym = currentOwner.newValueParameter(pos, "$ex").setInfo(ThrowableClass.tpe) + val exSym = currentOwner.newValueParameter(pos, cpsNames.ex).setInfo(ThrowableClass.tpe) val catch2 = { localTyper.typedCases(tree, List( CaseDef(Bind(exSym, Typed(Ident("_"), TypeTree(ThrowableClass.tpe))), - Apply(Select(Ident(funSym), "isDefinedAt"), List(Ident(exSym))), + Apply(Select(Ident(funSym), nme.isDefinedAt), List(Ident(exSym))), Apply(Ident(funSym), List(Ident(exSym)))) ), ThrowableClass.tpe, targettp) } @@ -317,11 +317,11 @@ abstract class SelectiveCPSTransform extends PluginComponent with log("fun.tpe:"+fun.tpe) log("return type of fun:"+body1.tpe) - var methodName = "map" + var methodName = nme.map if (body1.tpe != null) { if (body1.tpe.typeSymbol == Context) - methodName = "flatMap" + methodName = nme.flatMap } else unit.error(rhs.pos, "cannot compute type for CPS-transformed function result") @@ -347,14 +347,14 @@ abstract class SelectiveCPSTransform extends PluginComponent with // val <lhs> = ctx.getTrivialValue; ... <--- TODO: try/catch ??? don't bother for the moment... // else // ctx.flatMap { <lhs> => ... } - val ctxSym = currentOwner.newValue(vd.symbol.name + "$shift").setInfo(rhs1.tpe) + val ctxSym = currentOwner.newValue(vd.symbol.name append cpsNames.shiftSuffix).setInfo(rhs1.tpe) val ctxDef = localTyper.typed(ValDef(ctxSym, rhs1)) def ctxRef = localTyper.typed(Ident(ctxSym)) val argSym = currentOwner.newValue(vd.symbol.name).setInfo(tpe) - val argDef = localTyper.typed(ValDef(argSym, Select(ctxRef, ctxRef.tpe.member("getTrivialValue")))) + val argDef = localTyper.typed(ValDef(argSym, Select(ctxRef, ctxRef.tpe.member(cpsNames.getTrivialValue)))) val switchExpr = localTyper.typed(atPos(vd.symbol.pos) { val body2 = mkBlock(bodyStms, bodyExpr).duplicate // dup before typing! - If(Select(ctxRef, ctxSym.tpe.member("isTrivial")), + If(Select(ctxRef, ctxSym.tpe.member(cpsNames.isTrivial)), applyTrivial(argSym, mkBlock(argDef::bodyStms, bodyExpr)), applyCombinatorFun(ctxRef, body2)) }) |