@@ -37,26 +37,75 @@ object Liftable {
3737 }
3838 }
3939
40- implicit def ClassIsLiftable [T ]: Liftable [Class [T ]] = new Liftable [Class [T ]] {
40+ given ClassIsLiftable [T ] as Liftable [Class [T ]] = new Liftable [Class [T ]] {
4141 /** Lift a `Class[T]` into `'{ classOf[T] }` */
4242 def toExpr (x : Class [T ]) = given qctx => {
4343 import qctx .tasty ._
4444 Ref (definitions.Predef_classOf ).appliedToType(Type (x)).seal.asInstanceOf [Expr [Class [T ]]]
4545 }
4646 }
4747
48+ given ClassTagIsLiftable [T : Type ] as Liftable [ClassTag [T ]] = new Liftable [ClassTag [T ]] {
49+ def toExpr (ct : ClassTag [T ]): given QuoteContext => Expr [ClassTag [T ]] =
50+ ' { ClassTag [T ]($ {ct.runtimeClass.toExpr}) }
51+ }
52+
4853 given ArrayIsLiftable [T : Type : Liftable : ClassTag ] as Liftable [Array [T ]] = new Liftable [Array [T ]] {
49- def toExpr (arr : Array [T ]): given QuoteContext => Expr [Array [T ]] = ' {
50- val array = new Array [T ]($ {arr.length.toExpr})(ClassTag ($ {the[ClassTag [T ]].runtimeClass.toExpr}))
51- $ { Expr .block(List .tabulate(arr.length)(i => ' { array($ {i.toExpr}) = $ {arr(i).toExpr} }), ' { array }) }
52- }
54+ def toExpr (arr : Array [T ]): given QuoteContext => Expr [Array [T ]] =
55+ ' { Array [T ]($ {arr.toSeq.toExpr}: _* )($ {the[ClassTag [T ]].toExpr}) }
5356 }
5457
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- }
58+ given ArrayOfBooleanIsLiftable as Liftable [Array [Boolean ]] = new Liftable [Array [Boolean ]] {
59+ def toExpr (array : Array [Boolean ]): given QuoteContext => Expr [Array [Boolean ]] =
60+ if (array.length == 0 ) ' { Array .emptyBooleanArray }
61+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
62+ }
63+
64+ given ArrayOfByteIsLiftable as Liftable [Array [Byte ]] = new Liftable [Array [Byte ]] {
65+ def toExpr (array : Array [Byte ]): given QuoteContext => Expr [Array [Byte ]] =
66+ if (array.length == 0 ) ' { Array .emptyByteArray }
67+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
68+ }
69+
70+ given ArrayOfShortIsLiftable as Liftable [Array [Short ]] = new Liftable [Array [Short ]] {
71+ def toExpr (array : Array [Short ]): given QuoteContext => Expr [Array [Short ]] =
72+ if (array.length == 0 ) ' { Array .emptyShortArray }
73+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
74+ }
75+
76+ given ArrayOfCharIsLiftable as Liftable [Array [Char ]] = new Liftable [Array [Char ]] {
77+ def toExpr (array : Array [Char ]): given QuoteContext => Expr [Array [Char ]] =
78+ if (array.length == 0 ) ' { Array .emptyCharArray }
79+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
80+ }
81+
82+ given ArrayOfIntIsLiftable as Liftable [Array [Int ]] = new Liftable [Array [Int ]] {
83+ def toExpr (array : Array [Int ]): given QuoteContext => Expr [Array [Int ]] =
84+ if (array.length == 0 ) ' { Array .emptyIntArray }
85+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
86+ }
87+
88+ given ArrayOfLongIsLiftable as Liftable [Array [Long ]] = new Liftable [Array [Long ]] {
89+ def toExpr (array : Array [Long ]): given QuoteContext => Expr [Array [Long ]] =
90+ if (array.length == 0 ) ' { Array .emptyLongArray }
91+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
92+ }
93+
94+ given ArrayOfFloatIsLiftable as Liftable [Array [Float ]] = new Liftable [Array [Float ]] {
95+ def toExpr (array : Array [Float ]): given QuoteContext => Expr [Array [Float ]] =
96+ if (array.length == 0 ) ' { Array .emptyFloatArray }
97+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
98+ }
99+
100+ given ArrayOfDoubleIsLiftable as Liftable [Array [Double ]] = new Liftable [Array [Double ]] {
101+ def toExpr (array : Array [Double ]): given QuoteContext => Expr [Array [Double ]] =
102+ if (array.length == 0 ) ' { Array .emptyDoubleArray }
103+ else ' { Array ($ {array(0 ).toExpr}, $ {array.toSeq.tail.toExpr}: _* ) }
104+ }
105+
106+ given IArrayIsLiftable [T : Type ] as Liftable [IArray [T ]] given (ltArray : Liftable [Array [T ]]) = new Liftable [IArray [T ]] {
107+ def toExpr (iarray : IArray [T ]): given QuoteContext => Expr [IArray [T ]] =
108+ ' { $ {ltArray.toExpr(iarray.asInstanceOf [Array [T ]])}.asInstanceOf [IArray [T ]] }
60109 }
61110
62111 given [T : Type : Liftable ] as Liftable [Seq [T ]] = new Liftable [Seq [T ]] {
0 commit comments