@@ -13,7 +13,7 @@ object Expr {
13
13
* To retain semantics the argument `ei` is bound as `val yi = ei` and by-name arguments to `def yi = ei`.
14
14
* Some bindings may be elided as an early optimization.
15
15
*/
16
- def betaReduce [T ](expr : Expr [T ])(using qctx : Quotes ): Expr [T ] =
16
+ def betaReduce [T ](expr : Expr [T ])(using Quotes ): Expr [T ] =
17
17
import qctx .reflect ._
18
18
Term .betaReduce(Term .of(expr)) match
19
19
case Some (expr1) => expr1.asExpr.asInstanceOf [Expr [T ]]
@@ -23,13 +23,14 @@ object Expr {
23
23
* Given list of statements `s1 :: s2 :: ... :: Nil` and an expression `e` the resulting expression
24
24
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
25
25
*/
26
- def block [T ](statements : List [Expr [Any ]], expr : Expr [T ])(using qctx : Quotes ): Expr [T ] = {
26
+ def block [T ](statements : List [Expr [Any ]], expr : Expr [T ])(using Quotes ): Expr [T ] = {
27
27
import qctx .reflect ._
28
28
Block (statements.map(Term .of), Term .of(expr)).asExpr.asInstanceOf [Expr [T ]]
29
29
}
30
30
31
31
/** Lift a value into an expression containing the construction of that value */
32
- def apply [T ](x : T )(using qctx : Quotes , lift : Liftable [T ]): Expr [T ] = lift.toExpr(x)
32
+ def apply [T ](x : T )(using lift : Liftable [T ])(using Quotes ): Expr [T ] =
33
+ lift.toExpr(x)
33
34
34
35
/** Lifts this sequence of expressions into an expression of a sequence
35
36
*
@@ -39,7 +40,8 @@ object Expr {
39
40
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
40
41
* ```
41
42
*/
42
- def ofSeq [T ](xs : Seq [Expr [T ]])(using tp : Type [T ], qctx : Quotes ): Expr [Seq [T ]] = Varargs (xs)
43
+ def ofSeq [T ](xs : Seq [Expr [T ]])(using tp : Type [T ], qctx : Quotes ): Expr [Seq [T ]] =
44
+ Varargs (xs)
43
45
44
46
/** Lifts this list of expressions into an expression of a list
45
47
*
@@ -48,7 +50,7 @@ object Expr {
48
50
* to an expression equivalent to
49
51
* `'{ List($e1, $e2, ...) }` typed as an `Expr[List[T]]`
50
52
*/
51
- def ofList [T ](xs : Seq [Expr [T ]])(using Type [T ], Quotes ): Expr [List [T ]] =
53
+ def ofList [T ](xs : Seq [Expr [T ]])(using Type [T ])( using Quotes ): Expr [List [T ]] =
52
54
if (xs.isEmpty) Expr (Nil ) else ' { List ($ {Varargs (xs)}: _* ) }
53
55
54
56
/** Lifts this sequence of expressions into an expression of a tuple
@@ -58,7 +60,7 @@ object Expr {
58
60
* to an expression equivalent to
59
61
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
60
62
*/
61
- def ofTupleFromSeq (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] = {
63
+ def ofTupleFromSeq (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] = {
62
64
seq.size match {
63
65
case 0 => ' { Tuple () }
64
66
case 1 => ofTupleFromSeq1(seq)
@@ -87,116 +89,116 @@ object Expr {
87
89
}
88
90
}
89
91
90
- private def ofTupleFromSeq1 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
92
+ private def ofTupleFromSeq1 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
91
93
seq match
92
94
case Seq (' { $x1 : t1 }) => ' { Tuple1 ($x1) }
93
95
94
- private def ofTupleFromSeq2 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
96
+ private def ofTupleFromSeq2 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
95
97
seq match
96
98
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }) => ' { Tuple2 ($x1, $x2) }
97
99
98
- private def ofTupleFromSeq3 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
100
+ private def ofTupleFromSeq3 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
99
101
seq match
100
102
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }) => ' { Tuple3 ($x1, $x2, $x3) }
101
103
102
- private def ofTupleFromSeq4 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
104
+ private def ofTupleFromSeq4 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
103
105
seq match
104
106
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }) =>
105
107
' { Tuple4 ($x1, $x2, $x3, $x4) }
106
108
107
- private def ofTupleFromSeq5 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
109
+ private def ofTupleFromSeq5 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
108
110
seq match
109
111
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }) =>
110
112
' { Tuple5 ($x1, $x2, $x3, $x4, $x5) }
111
113
112
- private def ofTupleFromSeq6 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
114
+ private def ofTupleFromSeq6 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
113
115
seq match
114
116
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }) =>
115
117
' { Tuple6 ($x1, $x2, $x3, $x4, $x5, $x6) }
116
118
117
- private def ofTupleFromSeq7 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
119
+ private def ofTupleFromSeq7 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
118
120
seq match
119
121
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }) =>
120
122
' { Tuple7 ($x1, $x2, $x3, $x4, $x5, $x6, $x7) }
121
123
122
- private def ofTupleFromSeq8 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
124
+ private def ofTupleFromSeq8 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
123
125
seq match
124
126
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }) =>
125
127
' { Tuple8 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8) }
126
128
127
- private def ofTupleFromSeq9 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
129
+ private def ofTupleFromSeq9 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
128
130
seq match
129
131
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }) =>
130
132
' { Tuple9 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9) }
131
133
132
- private def ofTupleFromSeq10 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
134
+ private def ofTupleFromSeq10 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
133
135
seq match
134
136
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }) =>
135
137
' { Tuple10 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10) }
136
138
137
- private def ofTupleFromSeq11 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
139
+ private def ofTupleFromSeq11 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
138
140
seq match
139
141
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }) =>
140
142
' { Tuple11 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11) }
141
143
142
- private def ofTupleFromSeq12 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
144
+ private def ofTupleFromSeq12 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
143
145
seq match
144
146
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }) =>
145
147
' { Tuple12 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12) }
146
148
147
- private def ofTupleFromSeq13 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
149
+ private def ofTupleFromSeq13 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
148
150
seq match
149
151
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }) =>
150
152
' { Tuple13 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13) }
151
153
152
- private def ofTupleFromSeq14 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
154
+ private def ofTupleFromSeq14 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
153
155
seq match
154
156
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }) =>
155
157
' { Tuple14 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14) }
156
158
157
- private def ofTupleFromSeq15 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
159
+ private def ofTupleFromSeq15 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
158
160
seq match
159
161
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }) =>
160
162
' { Tuple15 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15) }
161
163
162
- private def ofTupleFromSeq16 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
164
+ private def ofTupleFromSeq16 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
163
165
seq match
164
166
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }) =>
165
167
' { Tuple16 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16) }
166
168
167
- private def ofTupleFromSeq17 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
169
+ private def ofTupleFromSeq17 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
168
170
seq match
169
171
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }) =>
170
172
' { Tuple17 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17) }
171
173
172
- private def ofTupleFromSeq18 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
174
+ private def ofTupleFromSeq18 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
173
175
seq match
174
176
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }) =>
175
177
' { Tuple18 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18) }
176
178
177
- private def ofTupleFromSeq19 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
179
+ private def ofTupleFromSeq19 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
178
180
seq match
179
181
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }, ' { $x19 : t19 }) =>
180
182
' { Tuple19 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19) }
181
183
182
- private def ofTupleFromSeq20 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
184
+ private def ofTupleFromSeq20 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
183
185
seq match
184
186
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }, ' { $x19 : t19 }, ' { $x20 : t20 }) =>
185
187
' { Tuple20 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20) }
186
188
187
- private def ofTupleFromSeq21 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
189
+ private def ofTupleFromSeq21 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
188
190
seq match
189
191
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }, ' { $x19 : t19 }, ' { $x20 : t20 }, ' { $x21 : t21 }) =>
190
192
' { Tuple21 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21) }
191
193
192
- private def ofTupleFromSeq22 (seq : Seq [Expr [Any ]])(using qctx : Quotes ): Expr [Tuple ] =
194
+ private def ofTupleFromSeq22 (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
193
195
seq match
194
196
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }, ' { $x19 : t19 }, ' { $x20 : t20 }, ' { $x21 : t21 }, ' { $x22 : t22 }) =>
195
197
' { Tuple22 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) }
196
198
197
199
198
200
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
199
- def ofTuple [T <: Tuple : Tuple .IsMappedBy [Expr ]: Type ](tup : T )(using qctx : Quotes ): Expr [Tuple .InverseMap [T , Expr ]] = {
201
+ def ofTuple [T <: Tuple : Tuple .IsMappedBy [Expr ]: Type ](tup : T )(using Quotes ): Expr [Tuple .InverseMap [T , Expr ]] = {
200
202
val elems : Seq [Expr [Any ]] = tup.asInstanceOf [Product ].productIterator.toSeq.asInstanceOf [Seq [Expr [Any ]]]
201
203
ofTupleFromSeq(elems).asExprOf[Tuple .InverseMap [T , Expr ]]
202
204
}
@@ -209,7 +211,7 @@ object Expr {
209
211
* @param tpe quoted type of the implicit parameter
210
212
* @param qctx current context
211
213
*/
212
- def summon [T ](using tpe : Type [T ])(using qctx : Quotes ): Option [Expr [T ]] = {
214
+ def summon [T ](using Type [T ])(using Quotes ): Option [Expr [T ]] = {
213
215
import qctx .reflect ._
214
216
Implicits .search(TypeRepr .of[T ]) match {
215
217
case iss : ImplicitSearchSuccess => Some (iss.tree.asExpr.asInstanceOf [Expr [T ]])
0 commit comments