File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted .*
2+ import scala .compiletime .*
3+
4+ trait Context
5+ object Scope :
6+ def spawn [A ](f : Context ?=> A ): A = ???
7+
8+ type Contextual [T ] = Context ?=> T
9+
10+ object Macros {
11+ inline def transformContextLambda [T ](inline expr : Context ?=> T ): Context => T =
12+ $ { transformContextLambdaImpl[T ](' expr ) }
13+
14+ def transformContextLambdaImpl [T : Type ](
15+ cexpr : Expr [Context ?=> T ]
16+ )(using Quotes ): Expr [Context => T ] = {
17+ import quotes .reflect .*
18+ val tree = asTerm(cexpr)
19+ val traverse = new TreeMap () {}
20+ println(tree.show)
21+ traverse.transformTree(tree)(tree.symbol)
22+ ' { _ => ??? }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+
2+ transparent inline def inScope [T ](inline expr : Context ?=> T ): T =
3+ val fn = Macros .transformContextLambda[T ](expr)
4+ fn(new Context {})
5+
6+ @ main def Test = {
7+ inScope {
8+ Scope .spawn[Unit ] { () }
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments