@@ -21,45 +21,84 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
2121 test(" Array[Double]()" , newArray0Opcodes(T_DOUBLE ))
2222 test(" Array[Char]()" , newArray0Opcodes(T_CHAR ))
2323 test(" Array[T]()" , newArray0Opcodes(T_INT ))
24+
25+ test(" IArray[String]()" , List (Op (ICONST_0 ), TypeOp (ANEWARRAY , " java/lang/String" ), TypeOp (CHECKCAST , " [Ljava/lang/String;" ), Op (POP ), Op (RETURN )))
26+ test(" IArray[Unit]()" , List (Op (ICONST_0 ), TypeOp (ANEWARRAY , " scala/runtime/BoxedUnit" ), Op (POP ), Op (RETURN )))
27+ test(" IArray[Object]()" , List (Op (ICONST_0 ), TypeOp (ANEWARRAY , " java/lang/Object" ), TypeOp (CHECKCAST , " [Ljava/lang/Object;" ), Op (POP ), Op (RETURN )))
28+ test(" IArray[Boolean]()" , newArray0Opcodes(T_BOOLEAN ))
29+ test(" IArray[Byte]()" , newArray0Opcodes(T_BYTE ))
30+ test(" IArray[Short]()" , newArray0Opcodes(T_SHORT ))
31+ test(" IArray[Int]()" , newArray0Opcodes(T_INT ))
32+ test(" IArray[Long]()" , newArray0Opcodes(T_LONG ))
33+ test(" IArray[Float]()" , newArray0Opcodes(T_FLOAT ))
34+ test(" IArray[Double]()" , newArray0Opcodes(T_DOUBLE ))
35+ test(" IArray[Char]()" , newArray0Opcodes(T_CHAR ))
36+ test(" IArray[T]()" , newArray0Opcodes(T_INT ))
2437 }
2538
2639 @ Test def testArrayGenericApply = {
2740 def opCodes (tpe : String ) =
2841 List (Op (ICONST_2 ), TypeOp (ANEWARRAY , tpe), Op (DUP ), Op (ICONST_0 ), Ldc (LDC , " a" ), Op (AASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , " b" ), Op (AASTORE ), Op (POP ), Op (RETURN ))
2942 test(""" Array("a", "b")""" , opCodes(" java/lang/String" ))
3043 test(""" Array[Object]("a", "b")""" , opCodes(" java/lang/Object" ))
44+
45+ def opCodes2 (tpe : String ) =
46+ List (Op (ICONST_2 ), TypeOp (ANEWARRAY , tpe), Op (DUP ), Op (ICONST_0 ), Ldc (LDC , " a" ), Op (AASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , " b" ), Op (AASTORE ), TypeOp (CHECKCAST , s " [L $tpe; " ), Op (POP ), Op (RETURN ))
47+ test(""" IArray("a", "b")""" , opCodes2(" java/lang/String" ))
48+ test(""" IArray[Object]("a", "b")""" , opCodes2(" java/lang/Object" ))
3149 }
3250
33- @ Test def testArrayApplyBoolean =
51+ @ Test def testArrayApplyBoolean = {
3452 test(" Array(true, false)" , newArray2Opcodes(T_BOOLEAN , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (BASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_0 ), Op (BASTORE ))))
53+ test(" IArray(true, false)" , newArray2Opcodes(T_BOOLEAN , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (BASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_0 ), Op (BASTORE ))))
54+ }
3555
36- @ Test def testArrayApplyByte =
56+ @ Test def testArrayApplyByte = {
3757 test(" Array[Byte](1, 2)" , newArray2Opcodes(T_BYTE , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (BASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (BASTORE ))))
58+ test(" IArray[Byte](1, 2)" , newArray2Opcodes(T_BYTE , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (BASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (BASTORE ))))
59+ }
3860
39- @ Test def testArrayApplyShort =
61+ @ Test def testArrayApplyShort = {
4062 test(" Array[Short](1, 2)" , newArray2Opcodes(T_SHORT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (SASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (SASTORE ))))
63+ test(" IArray[Short](1, 2)" , newArray2Opcodes(T_SHORT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (SASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (SASTORE ))))
64+ }
4165
4266 @ Test def testArrayApplyInt = {
4367 test(" Array(1, 2)" , newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (IASTORE ))))
68+ test(" IArray(1, 2)" , newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (IASTORE ))))
69+
4470 test(""" Array[T](t, t)""" , newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Field (GETSTATIC , " Foo$" , " MODULE$" , " LFoo$;" ), Invoke (INVOKEVIRTUAL , " Foo$" , " t" , " ()I" , false ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Field (GETSTATIC , " Foo$" , " MODULE$" , " LFoo$;" ), Invoke (INVOKEVIRTUAL , " Foo$" , " t" , " ()I" , false ), Op (IASTORE ))))
71+ test(""" IArray[T](t, t)""" , newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Field (GETSTATIC , " Foo$" , " MODULE$" , " LFoo$;" ), Invoke (INVOKEVIRTUAL , " Foo$" , " t" , " ()I" , false ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Field (GETSTATIC , " Foo$" , " MODULE$" , " LFoo$;" ), Invoke (INVOKEVIRTUAL , " Foo$" , " t" , " ()I" , false ), Op (IASTORE ))))
4572 }
4673
47- @ Test def testArrayApplyLong =
74+ @ Test def testArrayApplyLong = {
4875 test(" Array(2L, 3L)" , newArray2Opcodes(T_LONG , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2 ), Op (LASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3 ), Op (LASTORE ))))
76+ test(" IArray(2L, 3L)" , newArray2Opcodes(T_LONG , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2 ), Op (LASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3 ), Op (LASTORE ))))
77+ }
4978
50- @ Test def testArrayApplyFloat =
79+ @ Test def testArrayApplyFloat = {
5180 test(" Array(2.1f, 3.1f)" , newArray2Opcodes(T_FLOAT , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2.1f ), Op (FASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3.1f ), Op (FASTORE ))))
81+ test(" IArray(2.1f, 3.1f)" , newArray2Opcodes(T_FLOAT , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2.1f ), Op (FASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3.1f ), Op (FASTORE ))))
82+ }
5283
53- @ Test def testArrayApplyDouble =
84+ @ Test def testArrayApplyDouble = {
5485 test(" Array(2.2d, 3.2d)" , newArray2Opcodes(T_DOUBLE , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2.2d ), Op (DASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3.2d ), Op (DASTORE ))))
86+ test(" IArray(2.2d, 3.2d)" , newArray2Opcodes(T_DOUBLE , List (Op (DUP ), Op (ICONST_0 ), Ldc (LDC , 2.2d ), Op (DASTORE ), Op (DUP ), Op (ICONST_1 ), Ldc (LDC , 3.2d ), Op (DASTORE ))))
87+ }
5588
56- @ Test def testArrayApplyChar =
89+ @ Test def testArrayApplyChar = {
5790 test(" Array('x', 'y')" , newArray2Opcodes(T_CHAR , List (Op (DUP ), Op (ICONST_0 ), IntOp (BIPUSH , 120 ), Op (CASTORE ), Op (DUP ), Op (ICONST_1 ), IntOp (BIPUSH , 121 ), Op (CASTORE ))))
91+ test(" IArray('x', 'y')" , newArray2Opcodes(T_CHAR , List (Op (DUP ), Op (ICONST_0 ), IntOp (BIPUSH , 120 ), Op (CASTORE ), Op (DUP ), Op (ICONST_1 ), IntOp (BIPUSH , 121 ), Op (CASTORE ))))
92+ }
5893
59- @ Test def testArrayApplyUnit =
94+ @ Test def testArrayApplyUnit = {
6095 test(" Array[Unit]((), ())" , List (Op (ICONST_2 ), TypeOp (ANEWARRAY , " scala/runtime/BoxedUnit" ), Op (DUP ),
6196 Op (ICONST_0 ), Field (GETSTATIC , " scala/runtime/BoxedUnit" , " UNIT" , " Lscala/runtime/BoxedUnit;" ), Op (AASTORE ), Op (DUP ),
6297 Op (ICONST_1 ), Field (GETSTATIC , " scala/runtime/BoxedUnit" , " UNIT" , " Lscala/runtime/BoxedUnit;" ), Op (AASTORE ), Op (POP ), Op (RETURN )))
98+ test(" IArray[Unit]((), ())" , List (Op (ICONST_2 ), TypeOp (ANEWARRAY , " scala/runtime/BoxedUnit" ), Op (DUP ),
99+ Op (ICONST_0 ), Field (GETSTATIC , " scala/runtime/BoxedUnit" , " UNIT" , " Lscala/runtime/BoxedUnit;" ), Op (AASTORE ), Op (DUP ),
100+ Op (ICONST_1 ), Field (GETSTATIC , " scala/runtime/BoxedUnit" , " UNIT" , " Lscala/runtime/BoxedUnit;" ), Op (AASTORE ), Op (POP ), Op (RETURN )))
101+ }
63102
64103 @ Test def testArrayInlined = test(
65104 """ {
@@ -77,6 +116,14 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
77116 newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (IASTORE )))
78117 )
79118
119+ @ Test def testArrayInlined3 = test(
120+ """ {
121+ | inline def array[T](xs: =>T*) given (ct: =>scala.reflect.ClassTag[T]): Array[T] = Array(xs: _*)
122+ | array(1, 2)
123+ |}""" .stripMargin,
124+ newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (IASTORE ), TypeOp (CHECKCAST , " [I" )))
125+ )
126+
80127 private def newArray0Opcodes (tpe : Int , init : List [Any ] = Nil ): List [Any ] =
81128 Op (ICONST_0 ) :: IntOp (NEWARRAY , tpe) :: init ::: Op (POP ) :: Op (RETURN ) :: Nil
82129
0 commit comments