1
1
package scala .quoted
2
2
3
- import scala .quoted .Quoted .FunctionAppliedTo
4
3
import scala .runtime .quoted .Runner
4
+ import scala .runtime .quoted .Unpickler .Pickled
5
5
6
- abstract class Expr [T ] extends Quoted {
6
+ sealed abstract class Expr [T ] extends Quoted {
7
7
final def unary_~ : T = throw new Error (" ~ should have been compiled away" )
8
8
final def run (implicit runner : Runner [T ]): T = runner.run(this )
9
9
final def show (implicit runner : Runner [T ]): String = runner.show(this )
@@ -14,7 +14,30 @@ object Expr {
14
14
ev.toExpr(x)
15
15
16
16
implicit class AsFunction [T , U ](private val f : Expr [T => U ]) extends AnyVal {
17
- def apply (x : Expr [T ]): Expr [U ] = new FunctionAppliedTo [T , U ](f, x)
17
+ def apply (x : Expr [T ]): Expr [U ] = new Exprs . FunctionAppliedTo [T , U ](f, x)
18
18
}
19
19
20
20
}
21
+
22
+ /** All implementations of Expr[T] */
23
+ object Exprs {
24
+ /** An Expr backed by a pickled TASTY tree */
25
+ final class TastyExpr [T ](val tasty : Pickled , val args : Seq [Any ]) extends Expr [T ] {
26
+ override def toString (): String = s " Expr(<pickled>) "
27
+ }
28
+
29
+ /** An Expr backed by a value */
30
+ final class ConstantExpr [T ](val value : T ) extends Expr [T ] {
31
+ override def toString : String = s " Expr( $value) "
32
+ }
33
+
34
+ /** An Expr backed by a tree */
35
+ final class RawExpr [Tree ](val tree : Tree ) extends quoted.Expr [Any ] {
36
+ override def toString : String = s " Expr(<raw>) "
37
+ }
38
+
39
+ /** An Expr representing `'{(~f).apply(~x)}` but it is beta-reduced when the closure is known */
40
+ final class FunctionAppliedTo [T , U ](val f : Expr [T => U ], val x : Expr [T ]) extends Expr [U ] {
41
+ override def toString : String = s " Expr( $f <applied to> $x) "
42
+ }
43
+ }
0 commit comments