@@ -117,6 +117,10 @@ protected boolean isByteArray(String typeCode) {
117
117
return typeCode .charAt (0 ) == 'b' ;
118
118
}
119
119
120
+ protected boolean isCharArray (String typeCode ) {
121
+ return typeCode .charAt (0 ) == 'B' ;
122
+ }
123
+
120
124
protected boolean isDoubleArray (String typeCode ) {
121
125
return typeCode .charAt (0 ) == 'd' ;
122
126
}
@@ -146,6 +150,31 @@ PArray arrayByteInitializer(VirtualFrame frame, LazyPythonClass cls, @SuppressWa
146
150
return factory ().createArray (cls , byteArray );
147
151
}
148
152
153
+ @ Specialization (guards = "isCharArray(typeCode)" )
154
+ PArray arrayCharInitializer (VirtualFrame frame , LazyPythonClass cls , @ SuppressWarnings ("unused" ) String typeCode , PSequence initializer ,
155
+ @ Cached ("createCast()" ) CastToByteNode castToByteNode ,
156
+ @ Cached ("create()" ) GetIteratorNode getIterator ,
157
+ @ Cached ("create()" ) GetNextNode next ,
158
+ @ Cached ("create()" ) IsBuiltinClassProfile errorProfile ,
159
+ @ Cached ("create()" ) SequenceNodes .LenNode lenNode ) {
160
+ Object iter = getIterator .executeWith (frame , initializer );
161
+ int i = 0 ;
162
+ byte [] byteArray = new byte [lenNode .execute (initializer )];
163
+
164
+ while (true ) {
165
+ Object nextValue ;
166
+ try {
167
+ nextValue = next .execute (frame , iter );
168
+ } catch (PException e ) {
169
+ e .expectStopIteration (errorProfile );
170
+ break ;
171
+ }
172
+ byteArray [i ++] = castToByteNode .execute (nextValue );
173
+ }
174
+
175
+ return factory ().createArray (cls , byteArray );
176
+ }
177
+
149
178
@ Specialization (guards = "isIntArray(typeCode)" )
150
179
PArray arrayIntInitializer (VirtualFrame frame , LazyPythonClass cls , @ SuppressWarnings ("unused" ) String typeCode , PSequence initializer ,
151
180
@ Cached ("create()" ) GetIteratorNode getIterator ,
@@ -238,9 +267,9 @@ PArray arrayDoubleInitializer(VirtualFrame frame, LazyPythonClass cls, @Suppress
238
267
@ Specialization
239
268
@ TruffleBoundary
240
269
PArray arrayWithObjectInitializer (@ SuppressWarnings ("unused" ) LazyPythonClass cls , @ SuppressWarnings ("unused" ) String typeCode , Object initializer ) {
241
- if (!(isIntArray (typeCode ) || isByteArray (typeCode ) || isDoubleArray (typeCode ))) {
270
+ if (!(isIntArray (typeCode ) || isByteArray (typeCode ) || isDoubleArray (typeCode ) || isCharArray ( typeCode ) )) {
242
271
// TODO implement support for typecodes: b, B, u, h, H, i, I, l, L, q, Q, f or d
243
- throw raise (ValueError , "bad typecode (must be i, d, b, or l)" );
272
+ throw raise (ValueError , "bad typecode (must be i, d, b, B, or l)" );
244
273
}
245
274
throw new RuntimeException ("Unsupported initializer " + initializer );
246
275
}
@@ -259,8 +288,9 @@ private PArray makeEmptyArray(LazyPythonClass cls, char type) {
259
288
switch (type ) {
260
289
case 'c' :
261
290
case 'b' :
291
+ return factory ().createArray (cls , new byte [0 ]);
262
292
case 'B' :
263
- return factory ().createArray (cls , new char [0 ]);
293
+ return factory ().createArray (cls , new byte [0 ]);
264
294
case 'i' :
265
295
return factory ().createArray (cls , new int [0 ]);
266
296
case 'd' :
0 commit comments