@@ -8,7 +8,7 @@ import scala.reflect.ClassTag
8
8
trait Liftable [T ] {
9
9
10
10
/** Lift a value into an expression containing the construction of that value */
11
- def toExpr (x : T ): delegate QuoteContext => Expr [T ]
11
+ def toExpr (x : T ): ( given QuoteContext ) => Expr [T ]
12
12
13
13
}
14
14
@@ -31,112 +31,112 @@ object Liftable {
31
31
32
32
private class PrimitiveLiftable [T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String ] extends Liftable [T ] {
33
33
/** Lift a primitive value `n` into `'{ n }` */
34
- def toExpr (x : T ) = delegate qctx => {
34
+ def toExpr (x : T ) = ( given qctx ) => {
35
35
import qctx .tasty ._
36
36
Literal (Constant (x)).seal.asInstanceOf [Expr [T ]]
37
37
}
38
38
}
39
39
40
40
given ClassIsLiftable [T ] as Liftable [Class [T ]] = new Liftable [Class [T ]] {
41
41
/** Lift a `Class[T]` into `'{ classOf[T] }` */
42
- def toExpr (x : Class [T ]) = delegate qctx => {
42
+ def toExpr (x : Class [T ]) = ( given qctx ) => {
43
43
import qctx .tasty ._
44
44
Ref (defn.Predef_classOf ).appliedToType(Type (x)).seal.asInstanceOf [Expr [Class [T ]]]
45
45
}
46
46
}
47
47
48
48
given ClassTagIsLiftable [T : Type ] as Liftable [ClassTag [T ]] = new Liftable [ClassTag [T ]] {
49
- def toExpr (ct : ClassTag [T ]): delegate QuoteContext => Expr [ClassTag [T ]] =
49
+ def toExpr (ct : ClassTag [T ]): ( given QuoteContext ) => Expr [ClassTag [T ]] =
50
50
' { ClassTag [T ]($ {ct.runtimeClass.toExpr}) }
51
51
}
52
52
53
53
given ArrayIsLiftable [T : Type : Liftable : ClassTag ] as Liftable [Array [T ]] = new Liftable [Array [T ]] {
54
- def toExpr (arr : Array [T ]): delegate QuoteContext => Expr [Array [T ]] =
54
+ def toExpr (arr : Array [T ]): ( given QuoteContext ) => Expr [Array [T ]] =
55
55
' { Array [T ]($ {arr.toSeq.toExpr}: _* )($ {summon[ClassTag [T ]].toExpr}) }
56
56
}
57
57
58
58
given ArrayOfBooleanIsLiftable as Liftable [Array [Boolean ]] = new Liftable [Array [Boolean ]] {
59
- def toExpr (array : Array [Boolean ]): delegate QuoteContext => Expr [Array [Boolean ]] =
59
+ def toExpr (array : Array [Boolean ]): ( given QuoteContext ) => Expr [Array [Boolean ]] =
60
60
if (array.length == 0 ) ' { Array .emptyBooleanArray }
61
61
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
62
62
}
63
63
64
64
given ArrayOfByteIsLiftable as Liftable [Array [Byte ]] = new Liftable [Array [Byte ]] {
65
- def toExpr (array : Array [Byte ]): delegate QuoteContext => Expr [Array [Byte ]] =
65
+ def toExpr (array : Array [Byte ]): ( given QuoteContext ) => Expr [Array [Byte ]] =
66
66
if (array.length == 0 ) ' { Array .emptyByteArray }
67
67
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
68
68
}
69
69
70
70
given ArrayOfShortIsLiftable as Liftable [Array [Short ]] = new Liftable [Array [Short ]] {
71
- def toExpr (array : Array [Short ]): delegate QuoteContext => Expr [Array [Short ]] =
71
+ def toExpr (array : Array [Short ]): ( given QuoteContext ) => Expr [Array [Short ]] =
72
72
if (array.length == 0 ) ' { Array .emptyShortArray }
73
73
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
74
74
}
75
75
76
76
given ArrayOfCharIsLiftable as Liftable [Array [Char ]] = new Liftable [Array [Char ]] {
77
- def toExpr (array : Array [Char ]): delegate QuoteContext => Expr [Array [Char ]] =
77
+ def toExpr (array : Array [Char ]): ( given QuoteContext ) => Expr [Array [Char ]] =
78
78
if (array.length == 0 ) ' { Array .emptyCharArray }
79
79
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
80
80
}
81
81
82
82
given ArrayOfIntIsLiftable as Liftable [Array [Int ]] = new Liftable [Array [Int ]] {
83
- def toExpr (array : Array [Int ]): delegate QuoteContext => Expr [Array [Int ]] =
83
+ def toExpr (array : Array [Int ]): ( given QuoteContext ) => Expr [Array [Int ]] =
84
84
if (array.length == 0 ) ' { Array .emptyIntArray }
85
85
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
86
86
}
87
87
88
88
given ArrayOfLongIsLiftable as Liftable [Array [Long ]] = new Liftable [Array [Long ]] {
89
- def toExpr (array : Array [Long ]): delegate QuoteContext => Expr [Array [Long ]] =
89
+ def toExpr (array : Array [Long ]): ( given QuoteContext ) => Expr [Array [Long ]] =
90
90
if (array.length == 0 ) ' { Array .emptyLongArray }
91
91
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
92
92
}
93
93
94
94
given ArrayOfFloatIsLiftable as Liftable [Array [Float ]] = new Liftable [Array [Float ]] {
95
- def toExpr (array : Array [Float ]): delegate QuoteContext => Expr [Array [Float ]] =
95
+ def toExpr (array : Array [Float ]): ( given QuoteContext ) => Expr [Array [Float ]] =
96
96
if (array.length == 0 ) ' { Array .emptyFloatArray }
97
97
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
98
98
}
99
99
100
100
given ArrayOfDoubleIsLiftable as Liftable [Array [Double ]] = new Liftable [Array [Double ]] {
101
- def toExpr (array : Array [Double ]): delegate QuoteContext => Expr [Array [Double ]] =
101
+ def toExpr (array : Array [Double ]): ( given QuoteContext ) => Expr [Array [Double ]] =
102
102
if (array.length == 0 ) ' { Array .emptyDoubleArray }
103
103
else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
104
104
}
105
105
106
106
given IArrayIsLiftable [T : Type ] as Liftable [IArray [T ]] given (ltArray : Liftable [Array [T ]]) = new Liftable [IArray [T ]] {
107
- def toExpr (iarray : IArray [T ]): delegate QuoteContext => Expr [IArray [T ]] =
107
+ def toExpr (iarray : IArray [T ]): ( given QuoteContext ) => Expr [IArray [T ]] =
108
108
' { $ {ltArray.toExpr(iarray.asInstanceOf [Array [T ]])}.asInstanceOf [IArray [T ]] }
109
109
}
110
110
111
111
given [T : Type : Liftable ] as Liftable [Seq [T ]] = new Liftable [Seq [T ]] {
112
- def toExpr (xs : Seq [T ]): delegate QuoteContext => Expr [Seq [T ]] =
112
+ def toExpr (xs : Seq [T ]): ( given QuoteContext ) => Expr [Seq [T ]] =
113
113
xs.map(summon[Liftable [T ]].toExpr).toExprOfSeq
114
114
}
115
115
116
116
given [T : Type : Liftable ] as Liftable [List [T ]] = new Liftable [List [T ]] {
117
- def toExpr (xs : List [T ]): delegate QuoteContext => Expr [List [T ]] =
117
+ def toExpr (xs : List [T ]): ( given QuoteContext ) => Expr [List [T ]] =
118
118
xs.map(summon[Liftable [T ]].toExpr).toExprOfList
119
119
}
120
120
121
121
given [T : Type : Liftable ] as Liftable [Set [T ]] = new Liftable [Set [T ]] {
122
- def toExpr (set : Set [T ]): delegate QuoteContext => Expr [Set [T ]] =
122
+ def toExpr (set : Set [T ]): ( given QuoteContext ) => Expr [Set [T ]] =
123
123
' { Set ($ {set.toSeq.toExpr}: _* ) }
124
124
}
125
125
126
126
given [T : Type : Liftable , U : Type : Liftable ] as Liftable [Map [T , U ]] = new Liftable [Map [T , U ]] {
127
- def toExpr (map : Map [T , U ]): delegate QuoteContext => Expr [Map [T , U ]] =
127
+ def toExpr (map : Map [T , U ]): ( given QuoteContext ) => Expr [Map [T , U ]] =
128
128
' { Map ($ {map.toSeq.toExpr}: _* ) }
129
129
}
130
130
131
131
given [T : Type : Liftable ] as Liftable [Option [T ]] = new Liftable [Option [T ]] {
132
- def toExpr (x : Option [T ]): delegate QuoteContext => Expr [Option [T ]] = x match {
132
+ def toExpr (x : Option [T ]): ( given QuoteContext ) => Expr [Option [T ]] = x match {
133
133
case Some (x) => ' { Some [T ]($ {x.toExpr}) }
134
134
case None => ' { None : Option [T ] }
135
135
}
136
136
}
137
137
138
138
given [L : Type : Liftable , R : Type : Liftable ] as Liftable [Either [L , R ]] = new Liftable [Either [L , R ]] {
139
- def toExpr (x : Either [L , R ]): delegate QuoteContext => Expr [Either [L , R ]] = x match {
139
+ def toExpr (x : Either [L , R ]): ( given QuoteContext ) => Expr [Either [L , R ]] = x match {
140
140
case Left (x) => ' { Left [L , R ]($ {x.toExpr}) }
141
141
case Right (x) => ' { Right [L , R ]($ {x.toExpr}) }
142
142
}
@@ -289,19 +289,19 @@ object Liftable {
289
289
}
290
290
291
291
given [H : Type : Liftable , T <: Tuple : Type : Liftable ] as Liftable [H *: T ] = new {
292
- def toExpr (tup : H *: T ): delegate QuoteContext => Expr [H *: T ] =
292
+ def toExpr (tup : H *: T ): ( given QuoteContext ) => Expr [H *: T ] =
293
293
' { $ {summon[Liftable [H ]].toExpr(tup.head)} *: $ {summon[Liftable [T ]].toExpr(tup.tail)} }
294
294
// '{ ${tup.head.toExpr} *: ${tup.tail.toExpr} } // TODO figure out why this fails during CI documentation
295
295
}
296
296
297
297
given as Liftable [BigInt ] = new Liftable [BigInt ] {
298
- def toExpr (x : BigInt ): delegate QuoteContext => Expr [BigInt ] =
298
+ def toExpr (x : BigInt ): ( given QuoteContext ) => Expr [BigInt ] =
299
299
' { BigInt ($ {x.toByteArray.toExpr}) }
300
300
}
301
301
302
302
/** Lift a BigDecimal using the default MathContext */
303
303
given as Liftable [BigDecimal ] = new Liftable [BigDecimal ] {
304
- def toExpr (x : BigDecimal ): delegate QuoteContext => Expr [BigDecimal ] =
304
+ def toExpr (x : BigDecimal ): ( given QuoteContext ) => Expr [BigDecimal ] =
305
305
' { BigDecimal ($ {x.toString.toExpr}) }
306
306
}
307
307
0 commit comments