@@ -88,6 +88,10 @@ public int execute(boolean index, int length) {
88
88
return subNode .execute (index , length , errorMessage );
89
89
}
90
90
91
+ public long executeLong (long index , long length ) {
92
+ return subNode .executeLong (index , length , errorMessage );
93
+ }
94
+
91
95
protected final String getErrorMessage () {
92
96
return errorMessage ;
93
97
}
@@ -154,6 +158,8 @@ public abstract static class NormalizeIndexCustomMessageNode extends Node {
154
158
155
159
public abstract int execute (int index , int length , String errorMessage );
156
160
161
+ public abstract long executeLong (long index , long length , String errorMessage );
162
+
157
163
public static NormalizeIndexCustomMessageNode create () {
158
164
return NormalizeIndexWithBoundsCheckNodeGen .create ();
159
165
}
@@ -234,6 +240,18 @@ int doPIntOvf(PInt index, int length, String errorMessage,
234
240
}
235
241
}
236
242
243
+ @ Specialization
244
+ static long doLongLong (long lIndex , long length , String errorMessage ,
245
+ @ Shared ("negativeIndexProfile" ) @ Cached ConditionProfile negativeIndexProfile ,
246
+ @ Shared ("boundsCheckNode" ) @ Cached BoundsCheckNode boundsCheckNode ) {
247
+ long normalizedIndex = lIndex ;
248
+ if (negativeIndexProfile .profile (normalizedIndex < 0 )) {
249
+ normalizedIndex += length ;
250
+ }
251
+ boundsCheckNode .execute (errorMessage , normalizedIndex , length );
252
+ return normalizedIndex ;
253
+ }
254
+
237
255
}
238
256
239
257
@ GenerateUncached
@@ -289,17 +307,38 @@ static int doPIntOvf(PInt index, int length, String errorMessage,
289
307
throw raiseNode .raiseNumberTooLarge (PythonBuiltinClassType .IndexError , index );
290
308
}
291
309
}
310
+
311
+ @ Specialization
312
+ static long doLongLong (long index , long length , @ SuppressWarnings ("unused" ) String errorMessage ,
313
+ @ Shared ("negativeIndexProfile" ) @ Cached ConditionProfile negativeIndexProfile ) {
314
+ long idx = index ;
315
+ if (negativeIndexProfile .profile (idx < 0 )) {
316
+ idx += length ;
317
+ }
318
+ return idx ;
319
+ }
292
320
}
293
321
294
322
@ GenerateUncached
295
323
public abstract static class BoundsCheckNode extends Node {
296
324
297
325
public abstract void execute (String errorMessage , int idx , int length );
298
326
327
+ public abstract void execute (String errorMessage , long idx , long length );
328
+
299
329
@ Specialization
300
330
static void doBoundsCheck (String errorMessage , int idx , int length ,
301
331
@ Cached ConditionProfile outOfBoundsProfile ,
302
- @ Cached PRaiseNode raiseNode ) {
332
+ @ Shared ("raiseNode" ) @ Cached PRaiseNode raiseNode ) {
333
+ if (outOfBoundsProfile .profile (idx < 0 || idx >= length )) {
334
+ throw raiseNode .raise (PythonBuiltinClassType .IndexError , errorMessage );
335
+ }
336
+ }
337
+
338
+ @ Specialization
339
+ static void doBoundsCheck (String errorMessage , long idx , long length ,
340
+ @ Cached ConditionProfile outOfBoundsProfile ,
341
+ @ Shared ("raiseNode" ) @ Cached PRaiseNode raiseNode ) {
303
342
if (outOfBoundsProfile .profile (idx < 0 || idx >= length )) {
304
343
throw raiseNode .raise (PythonBuiltinClassType .IndexError , errorMessage );
305
344
}
0 commit comments