Skip to content

Commit e28832d

Browse files
committedNov 10, 2015
Hooks to customize code generation
1 parent 656748c commit e28832d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed
 

‎src/main/scala/scala/async/internal/AsyncTransform.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ trait AsyncTransform {
5050
}
5151

5252
val tryToUnit = appliedType(definitions.FunctionClass(1), futureSystemOps.tryType[Any], typeOf[Unit])
53-
val template = Template(List(tryToUnit, typeOf[() => Unit]).map(TypeTree(_)), emptyValDef, body)
53+
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body)
5454

5555
val t = ClassDef(NoMods, name.stateMachineT, Nil, template)
5656
typecheckClassDef(t)

‎src/main/scala/scala/async/internal/ExprBuilder.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ trait ExprBuilder {
357357
val caseForLastState: CaseDef = {
358358
val lastState = asyncStates.last
359359
val lastStateBody = c.Expr[T](lastState.body)
360-
val rhs = futureSystemOps.completeProm(
361-
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), futureSystemOps.tryySuccess[T](lastStateBody))
360+
val rhs = futureSystemOps.completeWithSuccess(
361+
c.Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), lastStateBody)
362362
mkHandlerCase(lastState.state, Block(rhs.tree, Return(literalUnit)))
363363
}
364364
asyncStates.toList match {

‎src/main/scala/scala/async/internal/FutureSystem.scala

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ trait FutureSystem {
3333
def promType[A: WeakTypeTag]: Type
3434
def tryType[A: WeakTypeTag]: Type
3535
def execContextType: Type
36+
def stateMachineClassParents: List[Type] = Nil
3637

3738
/** Create an empty promise */
3839
def createProm[A: WeakTypeTag]: Expr[Prom[A]]
@@ -55,6 +56,7 @@ trait FutureSystem {
5556

5657
/** Complete a promise with a value */
5758
def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit]
59+
def completeWithSuccess[A: WeakTypeTag](prom: Expr[Prom[A]], value: Expr[A]): Expr[Unit] = completeProm(prom, tryySuccess(value))
5860

5961
def spawn(tree: Tree, execContext: Tree): Tree =
6062
future(c.Expr[Unit](tree))(c.Expr[ExecContext](execContext)).tree

0 commit comments

Comments
 (0)
Please sign in to comment.