-
Notifications
You must be signed in to change notification settings - Fork 20
/
AsyncTreeShifter.scala
38 lines (28 loc) · 1.63 KB
/
AsyncTreeShifter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cps.macros.forest
import cps._
import cps.macros._
trait AsyncTreeShifter[F[_], CT, CC<:CpsMonadContext[F]]:
thisTreeTransform: TreeTransformScope[F, CT, CC] =>
import qctx.reflect._
def asyncShift(t:Term, shiftedSymbols:Set[Symbol]):Term =
t match
case Block(stats,last) => Block(stats.map(asyncShiftStatement(_,shiftedSymbols)),
asyncShift(last,shiftedSymbols))
case If(cond, thenp, elsep) => If(asyncShift(cond, shiftedSymbols),
asyncShift(thenp, shiftedSymbols),
asyncShift(elsep, shiftedSymbols))
case Match(scrutinee, cases) => Match(asyncShift(scrutinee, shiftedSymbols),
cases.map(asyncShiftCaseDef(_,shiftedSymbols)) )
case While(cond, body) => While(asyncShift(cond, shiftedSymbols),
asyncShift(body, shiftedSymbols))
case Try(body, cases, finalizer) => Try(asyncShift(body, shiftedSymbols),
cases.map(asyncShiftCaseDef(_, shiftedSymbols) ),
finalizer.map(asyncShift(_,shiftedSymbols)))
case _ =>
???
def asyncShiftStatement(t: Statement, shiftedSymbols: Set[Symbol]):Statement =
t match
case x: Definition => asyncShiftDefinition(x, shiftedSymbols)
case y: Term => asyncShift(y, shiftedSymbols)
def asyncShiftDefinition(t: Definition, shiftedSymbols: Set[Symbol]):Definition = ???
def asyncShiftCaseDef(cd: CaseDef, shiftedSymbols: Set[Symbol]):CaseDef = ???