@@ -21,45 +21,84 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
21
21
test(" Array[Double]()" , newArray0Opcodes(T_DOUBLE ))
22
22
test(" Array[Char]()" , newArray0Opcodes(T_CHAR ))
23
23
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" ), TypeOp (CHECKCAST , " [Lscala/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 , List (TypeOp (CHECKCAST , " [Z" ))))
29
+ test(" IArray[Byte]()" , newArray0Opcodes(T_BYTE , List (TypeOp (CHECKCAST , " [B" ))))
30
+ test(" IArray[Short]()" , newArray0Opcodes(T_SHORT , List (TypeOp (CHECKCAST , " [S" ))))
31
+ test(" IArray[Int]()" , newArray0Opcodes(T_INT , List (TypeOp (CHECKCAST , " [I" ))))
32
+ test(" IArray[Long]()" , newArray0Opcodes(T_LONG , List (TypeOp (CHECKCAST , " [J" ))))
33
+ test(" IArray[Float]()" , newArray0Opcodes(T_FLOAT , List (TypeOp (CHECKCAST , " [F" ))))
34
+ test(" IArray[Double]()" , newArray0Opcodes(T_DOUBLE , List (TypeOp (CHECKCAST , " [D" ))))
35
+ test(" IArray[Char]()" , newArray0Opcodes(T_CHAR , List (TypeOp (CHECKCAST , " [C" ))))
36
+ test(" IArray[T]()" , newArray0Opcodes(T_INT , List (TypeOp (CHECKCAST , " [I" ))))
24
37
}
25
38
26
39
@ Test def testArrayGenericApply = {
27
40
def opCodes (tpe : String ) =
28
41
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 ))
29
42
test(""" Array("a", "b")""" , opCodes(" java/lang/String" ))
30
43
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" ))
31
49
}
32
50
33
- @ Test def testArrayApplyBoolean =
51
+ @ Test def testArrayApplyBoolean = {
34
52
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 ), TypeOp (CHECKCAST , " [Z" ))))
54
+ }
35
55
36
- @ Test def testArrayApplyByte =
56
+ @ Test def testArrayApplyByte = {
37
57
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 ), TypeOp (CHECKCAST , " [B" ))))
59
+ }
38
60
39
- @ Test def testArrayApplyShort =
61
+ @ Test def testArrayApplyShort = {
40
62
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 ), TypeOp (CHECKCAST , " [S" ))))
64
+ }
41
65
42
66
@ Test def testArrayApplyInt = {
43
67
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 ), TypeOp (CHECKCAST , " [I" ))))
69
+
44
70
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 ), TypeOp (CHECKCAST , " [I" ))))
45
72
}
46
73
47
- @ Test def testArrayApplyLong =
74
+ @ Test def testArrayApplyLong = {
48
75
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 ), TypeOp (CHECKCAST , " [J" ))))
77
+ }
49
78
50
- @ Test def testArrayApplyFloat =
79
+ @ Test def testArrayApplyFloat = {
51
80
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 ), TypeOp (CHECKCAST , " [F" ))))
82
+ }
52
83
53
- @ Test def testArrayApplyDouble =
84
+ @ Test def testArrayApplyDouble = {
54
85
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 ), TypeOp (CHECKCAST , " [D" ))))
87
+ }
55
88
56
- @ Test def testArrayApplyChar =
89
+ @ Test def testArrayApplyChar = {
57
90
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 ), TypeOp (CHECKCAST , " [C" ))))
92
+ }
58
93
59
- @ Test def testArrayApplyUnit =
94
+ @ Test def testArrayApplyUnit = {
60
95
test(" Array[Unit]((), ())" , List (Op (ICONST_2 ), TypeOp (ANEWARRAY , " scala/runtime/BoxedUnit" ), Op (DUP ),
61
96
Op (ICONST_0 ), Field (GETSTATIC , " scala/runtime/BoxedUnit" , " UNIT" , " Lscala/runtime/BoxedUnit;" ), Op (AASTORE ), Op (DUP ),
62
97
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 ), TypeOp (CHECKCAST , " [Lscala/runtime/BoxedUnit;" ), Op (POP ), Op (RETURN )))
101
+ }
63
102
64
103
@ Test def testArrayInlined = test(
65
104
""" {
@@ -77,6 +116,14 @@ class ArrayApplyOptTest extends DottyBytecodeTest {
77
116
newArray2Opcodes(T_INT , List (Op (DUP ), Op (ICONST_0 ), Op (ICONST_1 ), Op (IASTORE ), Op (DUP ), Op (ICONST_1 ), Op (ICONST_2 ), Op (IASTORE )))
78
117
)
79
118
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
+
80
127
private def newArray0Opcodes (tpe : Int , init : List [Any ] = Nil ): List [Any ] =
81
128
Op (ICONST_0 ) :: IntOp (NEWARRAY , tpe) :: init ::: Op (POP ) :: Op (RETURN ) :: Nil
82
129
0 commit comments