-
Notifications
You must be signed in to change notification settings - Fork 20
/
TransformationContext.scala
59 lines (43 loc) · 1.81 KB
/
TransformationContext.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cps.macros
import scala.quoted.*
import cps.*
case class TransformationContext[F[_]:Type,T,C <: CpsMonadContext[F]](
patternCode: Expr[T], // code, for which we build pattern expression
patternType: Type[T],
monad: Expr[CpsMonad[F]],
monadContext: Expr[C],
runtimeAwait: Option[Expr[CpsRuntimeAwait[F]]],
runtimeAwaitProvider: Option[Expr[CpsRuntimeAwaitProvider[F]]],
flags: AsyncMacroFlags,
nesting: Int,
parent: Option[TransformationContext[_,_,_]],
) {
//def monad(using Quotes): Expr[CpsMonad[F]] =
// import quotes.reflect.*
// Select.unique(monadContext.asTerm, "monad").asExprOf[CpsMonad[F]]
def tryMonad(using Quotes): Expr[CpsTryMonad[F]] =
import quotes.reflect.*
Select.unique(monadContext.asTerm, "monad").asExprOf[CpsTryMonad[F]]
// idea for other branch: let context will provide us tryMonad
//Select.unique(monadContext.asTerm, "tryMonad").asExprOf[CpsTryMonad[F]]
def nestSame(muted: Boolean = flags.muted): TransformationContext[F,T,C] =
copy(flags = flags.copy(muted = muted), nesting=nesting+1, parent=Some(this))
def nest[S](newPatternCode: Expr[S], newPatternType: Type[S],
muted: Boolean = flags.muted): TransformationContext[F,S,C] =
TransformationContext(newPatternCode, newPatternType, monad, monadContext,
runtimeAwait, runtimeAwaitProvider,
flags.copy(muted=muted),
nesting + 1, parent=Some(this) )
def log(message:String): Unit =
if !flags.muted then
print(" "*nesting)
println(message)
}
object TransformationContext {
/*
case class Memoization[F[_]](
kind: CpsMonadMemoization.Kind,
monadMemoization: Expr[CpsMonadMemoization[F]]
)
*/
}