Skip to content

Commit e1cb013

Browse files
committed
Adapt more tests
1 parent f432dd7 commit e1cb013

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

tests/run-with-compiler/quote-lib.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,40 +60,40 @@ package liftable {
6060

6161
object Lets {
6262
def letVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] =
63-
'{ val letVal: ~t = ~expr; ~body('{letVal}) }
63+
'{ val letVal: $t = $expr; ${ body('{letVal}) } }
6464
def letLazyVal[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] =
65-
'{ lazy val letLazyVal: ~t = ~expr; ~body('{letLazyVal}) }
65+
'{ lazy val letLazyVal: $t = $expr; ${ body('{letLazyVal}) } }
6666
def letDef[T, U: Type](expr: Expr[T])(body: Expr[T] => Expr[U])(implicit t: Type[T]): Expr[U] =
67-
'{ def letDef: ~t = ~expr; ~body('{letDef}) }
67+
'{ def letDef: $t = $expr; ${ body('{letDef}) } }
6868
}
6969

7070
object Loops {
71-
def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit]): Expr[Unit] = '{ while (~cond) ~body }
72-
def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]): Expr[Unit] = '{ do ~body while (~cond) }
71+
def liftedWhile(cond: Expr[Boolean])(body: Expr[Unit]): Expr[Unit] = '{ while ($cond) $body }
72+
def liftedDoWhile(body: Expr[Unit])(cond: Expr[Boolean]): Expr[Unit] = '{ do $body while ($cond) }
7373
}
7474

7575
object Tuples {
7676

7777
implicit def Tuple1IsLiftable[T1: Liftable](implicit t1: Type[T1]): Liftable[Tuple1[T1]] = new Liftable[Tuple1[T1]] {
7878
def toExpr(x: Tuple1[T1]): Expr[Tuple1[T1]] =
79-
'{ Tuple1[~t1](~x._1.toExpr) }
79+
'{ Tuple1[$t1](${ x._1.toExpr}) }
8080
}
8181

8282
implicit def Tuple2IsLiftable[T1: Liftable, T2: Liftable](implicit t1: Type[T1], t2: Type[T2]): Liftable[(T1, T2)] = new Liftable[(T1, T2)] {
8383
def toExpr(x: (T1, T2)): Expr[(T1, T2)] =
84-
'{ Tuple2[~t1, ~t2](~x._1.toExpr, ~x._2.toExpr) }
84+
'{ Tuple2[$t1, $t2](${x._1.toExpr}, ${x._2.toExpr}) }
8585

8686
}
8787

8888
implicit def Tuple3IsLiftable[T1: Liftable, T2: Liftable, T3: Liftable](implicit t1: Type[T1], t2: Type[T2], t3: Type[T3]): Liftable[(T1, T2, T3)] = new Liftable[(T1, T2, T3)] {
8989
def toExpr(x: (T1, T2, T3)): Expr[(T1, T2, T3)] =
90-
'{ Tuple3[${t1, ~t2, ~t3](~x._1.toExpr, ~x._2.toExpr, ~x._3.toExpr}) }
90+
'{ Tuple3[$t1, $t2, $t3](${x._1.toExpr}, ${x._2.toExpr}, ${x._3.toExpr}) }
9191

9292
}
9393

9494
implicit def Tuple4IsLiftable[T1: Liftable, T2: Liftable, T3: Liftable, T4: Liftable](implicit t1: Type[T1], t2: Type[T2], t3: Type[T3], t4: Type[T4]): Liftable[(T1, T2, T3, T4)] = new Liftable[(T1, T2, T3, T4)] {
9595
def toExpr(x: (T1, T2, T3, T4)): Expr[(T1, T2, T3, T4)] =
96-
'{ Tuple4[~t1, ~t2, ~t3, ~t4](~x._1.toExpr, ~x._2.toExpr, ~x._3.toExpr, ~x._4.toExpr) }
96+
'{ Tuple4[$t1, $t2, $t3, $t4](${x._1.toExpr}, ${x._2.toExpr}, ${x._3.toExpr}, ${x._4.toExpr}) }
9797
}
9898

9999
// TODO more tuples
@@ -104,32 +104,32 @@ package liftable {
104104
object Lists {
105105
implicit def ListIsLiftable[T: Liftable](implicit t: Type[T]): Liftable[List[T]] = new Liftable[List[T]] {
106106
def toExpr(x: List[T]): Expr[List[T]] = x match {
107-
case x :: xs => '{ (~xs.toExpr).::[~t](~x.toExpr) }
108-
case Nil => '{ Nil: List[~t] }
107+
case x :: xs => '{ (${xs.toExpr}).::[$t](${x.toExpr}) }
108+
case Nil => '{ Nil: List[$t] }
109109
}
110110
}
111111

112112
implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) {
113113
def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U]): Expr[U] =
114-
'{ (~list).foldLeft[~u](~acc)(~f) }
114+
'{ ($list).foldLeft[$u]($acc)($f) }
115115
def foreach(f: Expr[T => Unit]): Expr[Unit] =
116-
'{ (~list).foreach(~f) }
116+
'{ ($list).foreach($f) }
117117
}
118118

119119
implicit class UnrolledOps[T: Liftable](list: List[T])(implicit t: Type[T]) {
120120
def unrolledFoldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U]): Expr[U] = list match {
121-
case x :: xs => xs.unrolledFoldLeft('{ (~f).apply(~acc, ~x.toExpr) })(f)
121+
case x :: xs => xs.unrolledFoldLeft('{ ($f).apply($acc, ${x.toExpr}) })(f)
122122
case Nil => acc
123123
}
124124
def unrolledForeach(f: Expr[T => Unit]): Expr[Unit] = list match {
125-
case x :: xs => '{ (${f).apply(${x.toExpr}}); ~xs.unrolledForeach(f) }
125+
case x :: xs => '{ ($f).apply(${x.toExpr}); ${ xs.unrolledForeach(f) } }
126126
case Nil => '{}
127127
}
128128
}
129129

130130
object Arrays {
131131
implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], ct: Expr[ClassTag[T]]): Liftable[Array[T]] = new Liftable[Array[T]] {
132-
def toExpr(arr: Array[T]): Expr[Array[T]] = '{ new Array[~t](~arr.length.toExpr)(~ct) }
132+
def toExpr(arr: Array[T]): Expr[Array[T]] = '{ new Array[$t](${arr.length.toExpr})($ct) }
133133
}
134134
}
135135

tests/run-with-compiler/quote-owners-2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object Test {
1313

1414
def f(t: Type[List[Int]]): Expr[Int] = '{
1515
def ff: Int = {
16-
val a: ~t = {
17-
type T = ~t
16+
val a: $t = {
17+
type T = $t
1818
val b: T = 3 :: Nil
1919
b
2020
}
@@ -23,5 +23,5 @@ object Test {
2323
ff
2424
}
2525

26-
def g[T](a: Type[T]): Type[List[T]] = '[List[~a]]
26+
def g[T](a: Type[T]): Type[List[T]] = '[List[$a]]
2727
}

tests/run-with-compiler/quote-run-staged-interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object Test {
1919
case Var(x) => env(x)
2020
case Let(x, e, body) =>
2121
if (keepLets)
22-
'{ val y = ${compileImpl(e, env)}; ${compileImpl(body, env + (x -> '{y})} }
22+
'{ val y = ${compileImpl(e, env)}; ${compileImpl(body, env + (x -> '{y})) } }
2323
else
2424
compileImpl(body, env + (x -> compileImpl(e, env)))
2525
}

tests/run-with-compiler/quote-unrolled-foreach.scala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make
66

77
def main(args: Array[String]): Unit = {
8-
val code1 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('{arr}, '{f}) }
8+
val code1 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('{arr}, '{f}) } }
99
println(code1.show)
1010
println()
1111

@@ -54,80 +54,80 @@ object Test {
5454
}
5555

5656
def foreach1Tpe1[T](arrRef: Expr[Array[T]], f: Expr[T => Unit])(implicit t: Type[T]): Expr[Unit] = '{
57-
val size = (~arrRef).length
57+
val size = ($arrRef).length
5858
var i = 0
5959
while (i < size) {
60-
val element: ~t = (~arrRef)(i)
61-
(~f)(element)
60+
val element: $t = ($arrRef)(i)
61+
($f)(element)
6262
i += 1
6363
}
6464
}
6565

6666
def foreach1Tpe2[T: Type](arrRef: Expr[Array[T]], f: Expr[T => Unit]): Expr[Unit] = '{
67-
val size = (~arrRef).length
67+
val size = ($arrRef).length
6868
var i = 0
6969
while (i < size) {
70-
val element: T = (~arrRef)(i)
71-
(~f)(element)
70+
val element: T = ($arrRef)(i)
71+
($f)(element)
7272
i += 1
7373
}
7474
}
7575

7676
def foreach2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{
77-
val size = (~arrRef).length
77+
val size = ($arrRef).length
7878
var i = 0
7979
while (i < size) {
80-
val element = (~arrRef)(i)
81-
~f('{element}) // Use AppliedFuntion
80+
val element = ($arrRef)(i)
81+
${ f('{element}) } // Use AppliedFuntion
8282
i += 1
8383
}
8484
}
8585

8686
def foreach3(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{
87-
val size = (~arrRef).length
87+
val size = ($arrRef).length
8888
var i = 0
8989
if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation
9090
while (i < size) {
91-
(~f)((~arrRef)(i))
92-
(~f)((~arrRef)(i + 1))
93-
(~f)((~arrRef)(i + 2))
91+
($f)(($arrRef)(i))
92+
($f)(($arrRef)(i + 1))
93+
($f)(($arrRef)(i + 2))
9494
i += 3
9595
}
9696
}
9797

9898
def foreach3_2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{
99-
val size = (~arrRef).length
99+
val size = ($arrRef).length
100100
var i = 0
101101
if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation
102102
while (i < size) {
103-
(~f)((~arrRef)(i))
104-
(~f)((~arrRef)(i + 1))
105-
(~f)((~arrRef)(i + 2))
103+
($f)(($arrRef)(i))
104+
($f)(($arrRef)(i + 1))
105+
($f)(($arrRef)(i + 2))
106106
i += 3
107107
}
108108
}
109109

110110
def foreach4(arrRef: Expr[Array[Int]], f: Expr[Int => Unit], unrollSize: Int): Expr[Unit] = '{
111-
val size = (~arrRef).length
111+
val size = ($arrRef).length
112112
var i = 0
113113
if (size % ${unrollSize.toExpr} != 0) throw new Exception("...") // for simplicity of the implementation
114114
while (i < size) {
115-
~foreachInRange(0, unrollSize)(j => '{ (~f)((~arrRef)(i + ~j.toExpr)) })
115+
${ foreachInRange(0, unrollSize)(j => '{ ($f)(($arrRef)(i + ${j.toExpr})) }) }
116116
i += ${unrollSize.toExpr}
117117
}
118118
}
119119

120120
implicit object ArrayIntIsLiftable extends Liftable[Array[Int]] {
121121
override def toExpr(x: Array[Int]): Expr[Array[Int]] = '{
122122
val array = new Array[Int](${x.length.toExpr})
123-
~foreachInRange(0, x.length)(i => '{ array(~i.toExpr) = ~x(i).toExpr})
123+
${ foreachInRange(0, x.length)(i => '{ array(${i.toExpr}) = ${x(i).toExpr}}) }
124124
array
125125
}
126126
}
127127

128128
def foreachInRange(start: Int, end: Int)(f: Int => Expr[Unit]): Expr[Unit] = {
129129
@tailrec def unroll(i: Int, acc: Expr[Unit]): Expr[Unit] =
130-
if (i < end) unroll(i + 1, '{ ~acc; ~f(i) }) else acc
130+
if (i < end) unroll(i + 1, '{ $acc; ${f(i)} }) else acc
131131
if (start < end) unroll(start + 1, f(start)) else '{}
132132
}
133133

tests/run-with-compiler/reflect-select-copy/assert_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.tasty._
33

44
object scalatest {
55

6-
inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), '(""))
6+
inline def assert(condition: => Boolean): Unit = ${ assertImpl('{condition}, '{""}) }
77

88
def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
99
import refl._
@@ -21,7 +21,7 @@ object scalatest {
2121
val l = left.seal[Any]
2222
val r = right.seal[Any]
2323
val b = result.seal[Boolean]
24-
val code = '{ scala.Predef.assert(~b) }
24+
val code = '{ scala.Predef.assert(${b}) }
2525
code.unseal
2626
}
2727
}
@@ -34,7 +34,7 @@ object scalatest {
3434
val l = left.seal[Any]
3535
val r = right.seal[Any]
3636
val b = result.seal[Boolean]
37-
val code = '{ scala.Predef.assert(~b) }
37+
val code = '{ scala.Predef.assert(${b}) }
3838
code.unseal
3939
}
4040
}

0 commit comments

Comments
 (0)