Skip to content

Commit 7214dd2

Browse files
committed
Move quoted.Liftable to src-2.x and src-3.x
1 parent 9ed471c commit 7214dd2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package scala.quoted
2+
3+
import scala.runtime.quoted.Unpickler.liftedExpr
4+
5+
/** A typeclass for types that can be turned to `quoted.Expr[T]`
6+
* without going through an explicit `'{...}` operation.
7+
*/
8+
abstract class Liftable[T] {
9+
def toExpr(x: T): Expr[T]
10+
}
11+
12+
/** Some liftable base types. To be completed with at least all types
13+
* that are valid Scala literals. The actual implementation of these
14+
* typed could be in terms of `ast.tpd.Literal`; the test `quotable.scala`
15+
* gives an alternative implementation using just the basic staging system.
16+
*/
17+
object Liftable {
18+
19+
implicit def BooleanIsLiftable: Liftable[Boolean] = new Liftable[Boolean] {
20+
def toExpr(x: Boolean): Expr[Boolean] = liftedExpr(x)
21+
}
22+
23+
implicit def ByteIsLiftable: Liftable[Byte] = new Liftable[Byte] {
24+
def toExpr(x: Byte): Expr[Byte] = liftedExpr(x)
25+
}
26+
27+
implicit def CharIsLiftable: Liftable[Char] = new Liftable[Char] {
28+
def toExpr(x: Char): Expr[Char] = liftedExpr(x)
29+
}
30+
31+
implicit def ShortIsLiftable: Liftable[Short] = new Liftable[Short] {
32+
def toExpr(x: Short): Expr[Short] = liftedExpr(x)
33+
}
34+
35+
implicit def IntIsLiftable: Liftable[Int] = new Liftable[Int] {
36+
def toExpr(x: Int): Expr[Int] = liftedExpr(x)
37+
}
38+
39+
implicit def LongIsLiftable: Liftable[Long] = new Liftable[Long] {
40+
def toExpr(x: Long): Expr[Long] = liftedExpr(x)
41+
}
42+
43+
implicit def FloatIsLiftable: Liftable[Float] = new Liftable[Float] {
44+
def toExpr(x: Float): Expr[Float] = liftedExpr(x)
45+
}
46+
47+
implicit def DoubleIsLiftable: Liftable[Double] = new Liftable[Double] {
48+
def toExpr(x: Double): Expr[Double] = liftedExpr(x)
49+
}
50+
51+
implicit def StringIsLiftable: Liftable[String] = new Liftable[String] {
52+
def toExpr(x: String): Expr[String] = liftedExpr(x)
53+
}
54+
55+
implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new Liftable[Class[T]] {
56+
def toExpr(x: Class[T]): Expr[Class[T]] = liftedExpr(x)
57+
}
58+
59+
}

0 commit comments

Comments
 (0)