@@ -52,13 +52,62 @@ object Liftable {
5252 }
5353 }
5454
55- given IArrayIsLiftable [T : Type : Liftable : ClassTag ] as Liftable [IArray [T ]] = new Liftable [IArray [T ]] {
56- def toExpr (iarray : IArray [T ]): given QuoteContext => Expr [IArray [T ]] = ' {
57- val array = new Array [T ]($ {iarray.length.toExpr})(ClassTag ($ {the[ClassTag [T ]].runtimeClass.toExpr}))
58- $ { Expr .block(List .tabulate(iarray.length)(i => ' { array($ {i.toExpr}) = $ {iarray(i).toExpr} }), ' { array.asInstanceOf [IArray [T ]] }) }
59- }
55+ given ArrayOfBooleanIsLiftable as Liftable [Array [Boolean ]] = new Liftable [Array [Boolean ]] {
56+ def toExpr (array : Array [Boolean ]): given QuoteContext => Expr [Array [Boolean ]] =
57+ if (array.length == 0 ) ' { Array .emptyBooleanArray }
58+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
59+ }
60+
61+ given ArrayOfByteIsLiftable as Liftable [Array [Byte ]] = new Liftable [Array [Byte ]] {
62+ def toExpr (array : Array [Byte ]): given QuoteContext => Expr [Array [Byte ]] =
63+ if (array.length == 0 ) ' { Array .emptyByteArray }
64+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
65+ }
66+
67+ given ArrayOfShortIsLiftable as Liftable [Array [Short ]] = new Liftable [Array [Short ]] {
68+ def toExpr (array : Array [Short ]): given QuoteContext => Expr [Array [Short ]] =
69+ if (array.length == 0 ) ' { Array .emptyShortArray }
70+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
71+ }
72+
73+ given ArrayOfCharIsLiftable as Liftable [Array [Char ]] = new Liftable [Array [Char ]] {
74+ def toExpr (array : Array [Char ]): given QuoteContext => Expr [Array [Char ]] =
75+ if (array.length == 0 ) ' { Array .emptyCharArray }
76+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
77+ }
78+
79+ given ArrayOfIntIsLiftable as Liftable [Array [Int ]] = new Liftable [Array [Int ]] {
80+ def toExpr (array : Array [Int ]): given QuoteContext => Expr [Array [Int ]] =
81+ if (array.length == 0 ) ' { Array .emptyIntArray }
82+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
6083 }
6184
85+ given ArrayOfLongIsLiftable as Liftable [Array [Long ]] = new Liftable [Array [Long ]] {
86+ def toExpr (array : Array [Long ]): given QuoteContext => Expr [Array [Long ]] =
87+ if (array.length == 0 ) ' { Array .emptyLongArray }
88+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
89+ }
90+
91+ given ArrayOfFloatIsLiftable as Liftable [Array [Float ]] = new Liftable [Array [Float ]] {
92+ def toExpr (array : Array [Float ]): given QuoteContext => Expr [Array [Float ]] =
93+ if (array.length == 0 ) ' { Array .emptyFloatArray }
94+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
95+ }
96+
97+ given ArrayOfDoubleIsLiftable as Liftable [Array [Double ]] = new Liftable [Array [Double ]] {
98+ def toExpr (array : Array [Double ]): given QuoteContext => Expr [Array [Double ]] =
99+ if (array.length == 0 ) ' { Array .emptyDoubleArray }
100+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
101+ }
102+
103+ given IArrayIsLiftable [T : Type ] as Liftable [IArray [T ]] given (ltArray : Liftable [Array [T ]]) = new Liftable [IArray [T ]] {
104+ def toExpr (iarray : IArray [T ]): given QuoteContext => Expr [IArray [T ]] =
105+ ' { $ {ltArray.toExpr(iarray.asInstanceOf [Array [T ]])}.asInstanceOf [IArray [T ]] }
106+ }
107+
108+ private def asIArrayExpr [T : Type ](arr : Expr [Array [T ]]) given QuoteContext : Expr [IArray [T ]] =
109+ ' { $arr.asInstanceOf [IArray [T ]] }
110+
62111 given [T : Type : Liftable ] as Liftable [Seq [T ]] = new Liftable [Seq [T ]] {
63112 def toExpr (xs : Seq [T ]): given QuoteContext => Expr [Seq [T ]] =
64113 xs.map(the[Liftable [T ]].toExpr).toExprOfSeq
0 commit comments