@@ -202,89 +202,65 @@ protected static boolean isNegativeNumber(InteropLibrary lib, Object right) {
202
202
return false ;
203
203
}
204
204
205
- @ Specialization (guards = {"!reverse" , " lib.isBoolean(left)" })
205
+ @ Specialization (guards = {"lib.isBoolean(left)" })
206
206
Object doComparisonBool (Object left , Object right ,
207
207
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
208
208
try {
209
- return op .executeObject (lib .asBoolean (left ), right );
209
+ if (!reverse ) {
210
+ return op .executeObject (lib .asBoolean (left ), right );
211
+ } else {
212
+ return op .executeObject (right , lib .asBoolean (left ));
213
+ }
210
214
} catch (UnsupportedMessageException e ) {
211
215
throw new IllegalStateException ("object does not unpack as it claims to" );
212
216
}
213
217
}
214
218
215
- @ Specialization (guards = {"!reverse" , " lib.fitsInLong(left)" })
219
+ @ Specialization (guards = {"lib.fitsInLong(left)" })
216
220
Object doComparisonLong (Object left , Object right ,
217
221
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
218
222
try {
219
- return op .executeObject (lib .asLong (left ), right );
223
+ if (!reverse ) {
224
+ return op .executeObject (lib .asLong (left ), right );
225
+ } else {
226
+ return op .executeObject (right , lib .asLong (left ));
227
+ }
220
228
} catch (UnsupportedMessageException e ) {
221
229
throw new IllegalStateException ("object does not unpack as it claims to" );
222
230
}
223
231
}
224
232
225
- @ Specialization (guards = {"!reverse" , " lib.fitsInDouble(left)" })
233
+ @ Specialization (guards = {"lib.fitsInDouble(left)" })
226
234
Object doComparisonDouble (Object left , Object right ,
227
235
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
228
236
try {
229
- return op .executeObject (lib .asDouble (left ), right );
237
+ if (!reverse ) {
238
+ return op .executeObject (lib .asDouble (left ), right );
239
+ } else {
240
+ return op .executeObject (right , lib .asDouble (left ));
241
+ }
230
242
} catch (UnsupportedMessageException e ) {
231
243
throw new IllegalStateException ("object does not unpack as it claims to" );
232
244
}
233
245
}
234
246
235
- @ Specialization (guards = {"!reverse" , " lib.isString(left)" })
247
+ @ Specialization (guards = {"lib.isString(left)" })
236
248
Object doComparisonString (Object left , Object right ,
237
249
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
238
250
try {
239
- return op .executeObject (lib .asString (left ), right );
240
- } catch (UnsupportedMessageException e ) {
241
- return PNotImplemented .NOT_IMPLEMENTED ;
242
- }
243
- }
244
- @ Specialization (guards = {"reverse" , "lib.isBoolean(left)" })
245
- Object doComparisonBoolR (Object left , Object right ,
246
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
247
- try {
248
- return op .executeObject (right , lib .asBoolean (left ));
249
- } catch (UnsupportedMessageException e ) {
250
- return PNotImplemented .NOT_IMPLEMENTED ;
251
- }
252
- }
253
-
254
- @ Specialization (guards = {"reverse" , "lib.fitsInLong(left)" })
255
- Object doComparisonLongR (Object left , Object right ,
256
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
257
- try {
258
- return op .executeObject (right , lib .asLong (left ));
259
- } catch (UnsupportedMessageException e ) {
260
- return PNotImplemented .NOT_IMPLEMENTED ;
261
- }
262
- }
263
-
264
- @ Specialization (guards = {"reverse" , "lib.fitsInDouble(left)" })
265
- Object doComparisonDoubleR (Object left , Object right ,
266
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
267
- try {
268
- return op .executeObject (right , lib .asDouble (left ));
269
- } catch (UnsupportedMessageException e ) {
270
- return PNotImplemented .NOT_IMPLEMENTED ;
271
- }
272
- }
273
-
274
- @ Specialization (guards = {"reverse" , "lib.isString(left)" })
275
- Object doComparisonStringR (Object left , Object right ,
276
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
277
- try {
278
- return op .executeObject (right , lib .asString (left ));
251
+ if (!reverse ) {
252
+ return op .executeObject (lib .asString (left ), right );
253
+ } else {
254
+ return op .executeObject (right , lib .asString (left ));
255
+ }
279
256
} catch (UnsupportedMessageException e ) {
280
257
throw new IllegalStateException ("object does not unpack as it claims to" );
281
258
}
282
259
}
283
260
284
261
@ SuppressWarnings ("unused" )
285
- @ Specialization (guards = {"!lib.fitsInDouble(left)" , "!lib.fitsInLong(left)" , "!lib.isBoolean(left)" })
286
- public PNotImplemented doGeneric (Object left , Object right ,
287
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
262
+ @ Fallback
263
+ public PNotImplemented doGeneric (Object left , Object right ) {
288
264
return PNotImplemented .NOT_IMPLEMENTED ;
289
265
}
290
266
}
@@ -335,11 +311,7 @@ abstract static class MulNode extends ForeignBinaryNode {
335
311
super (BinaryArithmetic .Mul .create (), false );
336
312
}
337
313
338
- protected static boolean isPythonLikeSequence (InteropLibrary lib , Object receiver ) {
339
- return lib .hasArrayElements (receiver );
340
- }
341
-
342
- @ Specialization (insertBefore = "doComparisonBool" , guards = {"isPythonLikeSequence(lib, left)" , "lib.fitsInInt(right)" })
314
+ @ Specialization (insertBefore = "doComparisonBool" , guards = {"lib.hasArrayElements(left)" , "lib.fitsInInt(right)" })
343
315
static Object doForeignArray (Object left , Object right ,
344
316
@ Cached PRaiseNode raise ,
345
317
@ Cached PythonObjectFactory factory ,
@@ -369,7 +341,7 @@ static Object doForeignArray(Object left, Object right,
369
341
}
370
342
}
371
343
372
- @ Specialization (insertBefore = "doComparisonBool" , guards = {"isPythonLikeSequence( lib, left)" , "lib.isBoolean(right)" })
344
+ @ Specialization (insertBefore = "doComparisonBool" , guards = {"lib.hasArrayElements( left)" , "lib.isBoolean(right)" })
373
345
static Object doForeignArrayForeignBoolean (Object left , Object right ,
374
346
@ Cached PRaiseNode raise ,
375
347
@ Cached PythonObjectFactory factory ,
@@ -378,26 +350,17 @@ static Object doForeignArrayForeignBoolean(Object left, Object right,
378
350
try {
379
351
return doForeignArray (left , lib .asBoolean (right ) ? 1 : 0 , raise , factory , convert , lib );
380
352
} catch (UnsupportedMessageException e ) {
381
- return PNotImplemented . NOT_IMPLEMENTED ;
353
+ throw new IllegalStateException ( "object does not unpack as it claims to" ) ;
382
354
}
383
355
}
384
356
385
357
@ SuppressWarnings ("unused" )
386
- @ Specialization (insertBefore = "doGeneric" , guards = {"isPythonLikeSequence( lib, left)" , "isNegativeNumber(lib, right)" })
358
+ @ Specialization (insertBefore = "doGeneric" , guards = {"lib.hasArrayElements( left)" , "isNegativeNumber(lib, right)" })
387
359
static Object doForeignArrayNegativeMult (Object left , Object right ,
388
360
@ Cached PythonObjectFactory factory ,
389
361
@ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
390
-
391
362
return factory .createList ();
392
363
}
393
-
394
- @ SuppressWarnings ("unused" )
395
- @ Specialization (insertBefore = "doGeneric" , guards = {"!lib.fitsInDouble(left)" , "!lib.fitsInLong(left)" , "!lib.isBoolean(left)" , "!isPythonLikeSequence(lib, left)" })
396
- PNotImplemented doForeignGeneric (Object left , Object right ,
397
- @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
398
- return PNotImplemented .NOT_IMPLEMENTED ;
399
- }
400
-
401
364
}
402
365
403
366
@ Builtin (name = __RMUL__ , minNumOfPositionalArgs = 2 )
0 commit comments