11package scala .quoted
22
3- import scala .quoted .Quoted .FunctionAppliedTo
43import scala .runtime .quoted .Runner
4+ import scala .runtime .quoted .Unpickler .Pickled
55
6- abstract class Expr [T ] extends Quoted {
6+ sealed abstract class Expr [T ] extends Quoted {
77 final def unary_~ : T = throw new Error (" ~ should have been compiled away" )
88 final def run (implicit runner : Runner [T ]): T = runner.run(this )
99 final def show (implicit runner : Runner [T ]): String = runner.show(this )
@@ -14,7 +14,30 @@ object Expr {
1414 ev.toExpr(x)
1515
1616 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)
1818 }
1919
2020}
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