From ffab92802c130c7e881440d360e7cef051b7f3d4 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Fri, 26 Apr 2013 19:02:14 +0200 Subject: Abstract over type of generated state machine Removes method `TransformUtils.applied`. --- src/main/scala/scala/async/Async.scala | 6 +++--- src/main/scala/scala/async/FutureSystem.scala | 3 +++ src/main/scala/scala/async/TransformUtils.scala | 3 --- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala index 1cfae1b..c480b62 100644 --- a/src/main/scala/scala/async/Async.scala +++ b/src/main/scala/scala/async/Async.scala @@ -113,7 +113,7 @@ abstract class AsyncBase { } val resumeFunTree = asyncBlock.resumeFunTree[T] - val stateMachineType = utils.applied("scala.async.StateMachine", List(futureSystemOps.promType[T], futureSystemOps.execContextType)) + val stateMachineType = futureSystemOps.stateMachineType[T] lazy val stateMachine: ClassDef = { val body: List[Tree] = { @@ -135,7 +135,7 @@ abstract class AsyncBase { List(utils.emptyConstructor, stateVar, result, execContext) ++ localVarTrees ++ List(resumeFunTree, applyDefDef, apply0DefDef) } val template = { - Template(List(stateMachineType), emptyValDef, body) + Template(List(TypeTree(stateMachineType)), emptyValDef, body) } ClassDef(NoMods, name.stateMachineT, Nil, template) } @@ -150,7 +150,7 @@ abstract class AsyncBase { else { Block(List[Tree]( stateMachine, - ValDef(NoMods, name.stateMachine, stateMachineType, Apply(Select(New(Ident(name.stateMachineT)), nme.CONSTRUCTOR), Nil)), + ValDef(NoMods, name.stateMachine, TypeTree(stateMachineType), Apply(Select(New(Ident(name.stateMachineT)), nme.CONSTRUCTOR), Nil)), futureSystemOps.spawn(Apply(selectStateMachine(name.apply), Nil)) ), futureSystemOps.promiseToFuture(c.Expr[futureSystem.Prom[T]](selectStateMachine(name.result))).tree) diff --git a/src/main/scala/scala/async/FutureSystem.scala b/src/main/scala/scala/async/FutureSystem.scala index 5dc04a7..f20854b 100644 --- a/src/main/scala/scala/async/FutureSystem.scala +++ b/src/main/scala/scala/async/FutureSystem.scala @@ -37,6 +37,7 @@ trait FutureSystem { def promType[A: WeakTypeTag]: Type def resultType[A: WeakTypeTag]: Type + def stateMachineType[A: WeakTypeTag]: Type def execContextType: Type /** Create an empty promise */ @@ -139,6 +140,7 @@ object ScalaConcurrentFutureSystem extends TryBasedFutureSystem { }) def promType[A: WeakTypeTag]: Type = c.weakTypeOf[Promise[A]] + def stateMachineType[A: WeakTypeTag]: Type = c.weakTypeOf[scala.async.StateMachine[Promise[A], ExecutionContext]] def execContextType: Type = c.weakTypeOf[ExecutionContext] def createProm[A: WeakTypeTag]: Expr[Prom[A]] = reify { @@ -188,6 +190,7 @@ object IdentityFutureSystem extends TryBasedFutureSystem { def execContext: Expr[ExecContext] = c.literalUnit def promType[A: WeakTypeTag]: Type = c.weakTypeOf[Prom[A]] + def stateMachineType[A: WeakTypeTag]: Type = c.weakTypeOf[scala.async.StateMachine[Prom[A], ExecContext]] def execContextType: Type = c.weakTypeOf[Unit] def createProm[A: WeakTypeTag]: Expr[Prom[A]] = reify { diff --git a/src/main/scala/scala/async/TransformUtils.scala b/src/main/scala/scala/async/TransformUtils.scala index 39847dc..24f59cb 100644 --- a/src/main/scala/scala/async/TransformUtils.scala +++ b/src/main/scala/scala/async/TransformUtils.scala @@ -164,9 +164,6 @@ private[async] final case class TransformUtils[C <: Context](c: C) { DefDef(NoMods, nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(emptySuperCall), c.literalUnit.tree)) } - def applied(className: String, types: List[Type]): AppliedTypeTree = - AppliedTypeTree(Ident(c.mirror.staticClass(className)), types.map(TypeTree(_))) - object defn { def mkList_apply[A](args: List[Expr[A]]): Expr[List[A]] = { c.Expr(Apply(Ident(definitions.List_apply), args.map(_.tree))) -- cgit v1.2.3