File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 11package scala .quoted
22
3+ import scala .reflect .ClassTag
4+
35/** A typeclass for types that can be turned to `quoted.Expr[T]`
46 * without going through an explicit `'{...}` operation.
57 */
@@ -43,6 +45,13 @@ object Liftable {
4345 }
4446 }
4547
48+ given [T : Type : Liftable : ClassTag ] as Liftable [IArray [T ]] = new Liftable [IArray [T ]] {
49+ def toExpr (iarray : IArray [T ]): given QuoteContext => Expr [IArray [T ]] = ' { // TODO specialize
50+ val array = new Array [T ]($ {Liftable_Int_delegate .toExpr(iarray.length)})(ClassTag ($ {ClassIsLiftable .toExpr(the[ClassTag [T ]].runtimeClass)}))
51+ $ { Expr .block(List .tabulate(iarray.length)(i => ' { array($ {Liftable_Int_delegate .toExpr(i)}) = $ {the[Liftable [T ]].toExpr(iarray(i))} }), ' { array.asInstanceOf [IArray [T ]] }) }
52+ }
53+ }
54+
4655 given [T : Type : Liftable ] as Liftable [List [T ]] = new Liftable [List [T ]] {
4756 def toExpr (x : List [T ]): given QuoteContext => Expr [List [T ]] = x match {
4857 case x :: xs => ' { ($ {this .toExpr(xs)}).:: [T ]($ {the[Liftable [T ]].toExpr(x)}) }
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ object Test {
3535 list.unrolledFoldLeft[Int ](0 )(' { (acc : Int , x : Int ) => acc + x }).show
3636 list.unrolledForeach(' { (x : Int ) => println(x) }).show
3737
38+ val iarray : IArray [Int ] = IArray (1 , 2 , 3 )
39+ val liftedIArray : Expr [IArray [Int ]] = iarray
40+
3841 println(" quote lib ok" )
3942 }
4043}
@@ -120,11 +123,5 @@ package liftable {
120123 }
121124 }
122125
123- object Arrays {
124- implicit def ArrayIsLiftable [T : Liftable ](implicit t : Type [T ], ct : Expr [ClassTag [T ]]): Liftable [Array [T ]] = new Liftable [Array [T ]] {
125- def toExpr (arr : Array [T ]) = ' { new Array [$t]($ {arr.length})($ct) }
126- }
127- }
128-
129126 }
130127}
You can’t perform that action at this time.
0 commit comments