@@ -5,8 +5,8 @@ use crate::obj::objstr::PyStringRef;
5
5
use crate :: obj:: objtype:: PyClassRef ;
6
6
use crate :: obj:: { objbool, objiter} ;
7
7
use crate :: pyobject:: {
8
- BorrowValue , Either , IntoPyObject , PyClassImpl , PyIterable , PyObjectRef , PyRef , PyResult ,
9
- PyValue , TryFromObject ,
8
+ BorrowValue , Either , IntoPyObject , PyArithmaticValue , PyClassImpl , PyComparisonValue ,
9
+ PyIterable , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
10
10
} ;
11
11
use crate :: VirtualMachine ;
12
12
@@ -438,94 +438,94 @@ impl PyArray {
438
438
}
439
439
440
440
#[ pymethod( name = "__eq__" ) ]
441
- fn eq ( lhs : PyObjectRef , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
442
- let lhs = class_or_notimplemented ! ( vm, Self , lhs) ;
443
- let rhs = class_or_notimplemented ! ( vm, Self , rhs) ;
444
- let lhs = lhs. borrow_value ( ) ;
441
+ fn eq ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
442
+ let lhs = self . borrow_value ( ) ;
443
+ let rhs = class_or_notimplemented ! ( vm, Self , other) ;
445
444
let rhs = rhs. borrow_value ( ) ;
446
445
if lhs. len ( ) != rhs. len ( ) {
447
- Ok ( vm . ctx . new_bool ( false ) )
446
+ Ok ( PyArithmaticValue :: Implemented ( false ) )
448
447
} else {
449
448
for ( a, b) in lhs. iter ( vm) . zip ( rhs. iter ( vm) ) {
450
449
let ne = objbool:: boolval ( vm, vm. _ne ( a, b) ?) ?;
451
450
if ne {
452
- return Ok ( vm . ctx . new_bool ( false ) ) ;
451
+ return Ok ( PyArithmaticValue :: Implemented ( false ) ) ;
453
452
}
454
453
}
455
- Ok ( vm . ctx . new_bool ( true ) )
454
+ Ok ( PyArithmaticValue :: Implemented ( true ) )
456
455
}
457
456
}
458
457
458
+ #[ pymethod( name = "__ne__" ) ]
459
+ fn ne ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
460
+ Ok ( self . eq ( other, vm) ?. map ( |v| !v) )
461
+ }
462
+
459
463
#[ pymethod( name = "__lt__" ) ]
460
- fn lt ( lhs : PyObjectRef , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
461
- let lhs = class_or_notimplemented ! ( vm, Self , lhs) ;
462
- let rhs = class_or_notimplemented ! ( vm, Self , rhs) ;
463
- let lhs = lhs. borrow_value ( ) ;
464
+ fn lt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
465
+ let lhs = self . borrow_value ( ) ;
466
+ let rhs = class_or_notimplemented ! ( vm, Self , other) ;
464
467
let rhs = rhs. borrow_value ( ) ;
465
468
466
469
for ( a, b) in lhs. iter ( vm) . zip ( rhs. iter ( vm) ) {
467
470
let lt = objbool:: boolval ( vm, vm. _lt ( a, b) ?) ?;
468
471
469
472
if lt {
470
- return Ok ( vm . ctx . new_bool ( true ) ) ;
473
+ return Ok ( PyArithmaticValue :: Implemented ( true ) ) ;
471
474
}
472
475
}
473
476
474
- Ok ( vm . ctx . new_bool ( lhs. len ( ) < rhs. len ( ) ) )
477
+ Ok ( PyArithmaticValue :: Implemented ( lhs. len ( ) < rhs. len ( ) ) )
475
478
}
476
479
477
480
#[ pymethod( name = "__le__" ) ]
478
- fn le ( lhs : PyObjectRef , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
479
- let lhs = class_or_notimplemented ! ( vm, Self , lhs) ;
480
- let rhs = class_or_notimplemented ! ( vm, Self , rhs) ;
481
- let lhs = lhs. borrow_value ( ) ;
481
+ fn le ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
482
+ let lhs = self . borrow_value ( ) ;
483
+ let rhs = class_or_notimplemented ! ( vm, Self , other) ;
482
484
let rhs = rhs. borrow_value ( ) ;
483
485
484
486
for ( a, b) in lhs. iter ( vm) . zip ( rhs. iter ( vm) ) {
485
487
let le = objbool:: boolval ( vm, vm. _le ( a, b) ?) ?;
486
488
487
489
if le {
488
- return Ok ( vm . ctx . new_bool ( true ) ) ;
490
+ return Ok ( PyArithmaticValue :: Implemented ( true ) ) ;
489
491
}
490
492
}
491
493
492
- Ok ( vm . ctx . new_bool ( lhs. len ( ) <= rhs. len ( ) ) )
494
+ Ok ( PyArithmaticValue :: Implemented ( lhs. len ( ) <= rhs. len ( ) ) )
493
495
}
494
496
495
497
#[ pymethod( name = "__gt__" ) ]
496
- fn gt ( lhs : PyObjectRef , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
497
- let lhs = class_or_notimplemented ! ( vm, Self , lhs) ;
498
- let rhs = class_or_notimplemented ! ( vm, Self , rhs) ;
499
- let lhs = lhs. borrow_value ( ) ;
498
+ fn gt ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
499
+ let lhs = self . borrow_value ( ) ;
500
+ let rhs = class_or_notimplemented ! ( vm, Self , other) ;
500
501
let rhs = rhs. borrow_value ( ) ;
501
502
502
503
for ( a, b) in lhs. iter ( vm) . zip ( rhs. iter ( vm) ) {
503
504
let gt = objbool:: boolval ( vm, vm. _gt ( a, b) ?) ?;
504
505
505
506
if gt {
506
- return Ok ( vm . ctx . new_bool ( true ) ) ;
507
+ return Ok ( PyArithmaticValue :: Implemented ( true ) ) ;
507
508
}
508
509
}
509
510
510
- Ok ( vm . ctx . new_bool ( lhs. len ( ) > rhs. len ( ) ) )
511
+ Ok ( PyArithmaticValue :: Implemented ( lhs. len ( ) > rhs. len ( ) ) )
511
512
}
512
513
513
514
#[ pymethod( name = "__ge__" ) ]
514
- fn ge ( lhs : PyObjectRef , rhs : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
515
- let lhs = class_or_notimplemented ! ( vm, Self , lhs) ;
516
- let rhs = class_or_notimplemented ! ( vm, Self , rhs) ;
517
- let lhs = lhs. borrow_value ( ) ;
515
+ fn ge ( & self , other : PyObjectRef , vm : & VirtualMachine ) -> PyResult < PyComparisonValue > {
516
+ let lhs = self . borrow_value ( ) ;
517
+ let rhs = class_or_notimplemented ! ( vm, Self , other) ;
518
518
let rhs = rhs. borrow_value ( ) ;
519
519
520
520
for ( a, b) in lhs. iter ( vm) . zip ( rhs. iter ( vm) ) {
521
521
let ge = objbool:: boolval ( vm, vm. _ge ( a, b) ?) ?;
522
522
523
523
if ge {
524
- return Ok ( vm . ctx . new_bool ( true ) ) ;
524
+ return Ok ( PyArithmaticValue :: Implemented ( true ) ) ;
525
525
}
526
526
}
527
527
528
- Ok ( vm . ctx . new_bool ( lhs. len ( ) >= rhs. len ( ) ) )
528
+ Ok ( PyArithmaticValue :: Implemented ( lhs. len ( ) >= rhs. len ( ) ) )
529
529
}
530
530
531
531
#[ pymethod( name = "__len__" ) ]
0 commit comments