@@ -13,7 +13,7 @@ use crate::{
1313 ArgByteOrder , ArgIntoBool , OptionalArg , OptionalOption , PyArithmeticValue ,
1414 PyComparisonValue ,
1515 } ,
16- protocol:: { PyNumber , PyNumberMethods } ,
16+ protocol:: PyNumberMethods ,
1717 types:: { AsNumber , Comparable , Constructor , Hashable , PyComparisonOp , Representable } ,
1818 AsObject , Context , Py , PyObject , PyObjectRef , PyPayload , PyRef , PyResult ,
1919 TryFromBorrowedObject , VirtualMachine ,
@@ -743,39 +743,39 @@ impl AsNumber for PyInt {
743743
744744impl PyInt {
745745 pub ( super ) const AS_NUMBER : PyNumberMethods = PyNumberMethods {
746- add : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a + b, vm) ) ,
747- subtract : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a - b, vm) ) ,
748- multiply : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a * b, vm) ) ,
749- remainder : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_mod, vm) ) ,
750- divmod : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_divmod, vm) ) ,
751- power : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_pow, vm) ) ,
746+ add : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a + b, vm) ) ,
747+ subtract : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a - b, vm) ) ,
748+ multiply : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a * b, vm) ) ,
749+ remainder : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_mod, vm) ) ,
750+ divmod : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_divmod, vm) ) ,
751+ power : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_pow, vm) ) ,
752752 negative : Some ( |num, vm| ( & PyInt :: number_downcast ( num) . value ) . neg ( ) . to_pyresult ( vm) ) ,
753753 positive : Some ( |num, vm| Ok ( PyInt :: number_downcast_exact ( num, vm) . into ( ) ) ) ,
754754 absolute : Some ( |num, vm| PyInt :: number_downcast ( num) . value . abs ( ) . to_pyresult ( vm) ) ,
755755 boolean : Some ( |num, _vm| Ok ( PyInt :: number_downcast ( num) . value . is_zero ( ) ) ) ,
756756 invert : Some ( |num, vm| ( & PyInt :: number_downcast ( num) . value ) . not ( ) . to_pyresult ( vm) ) ,
757- lshift : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_lshift, vm) ) ,
758- rshift : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_rshift, vm) ) ,
759- and : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a & b, vm) ) ,
760- xor : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a ^ b, vm) ) ,
761- or : Some ( |num , other , vm| PyInt :: number_op ( num , other , |a, b, _vm| a | b, vm) ) ,
757+ lshift : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_lshift, vm) ) ,
758+ rshift : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_rshift, vm) ) ,
759+ and : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a & b, vm) ) ,
760+ xor : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a ^ b, vm) ) ,
761+ or : Some ( |a , b , vm| PyInt :: number_op ( a , b , |a, b, _vm| a | b, vm) ) ,
762762 int : Some ( |num, vm| Ok ( PyInt :: number_downcast_exact ( num, vm) ) ) ,
763763 float : Some ( |num, vm| {
764764 let zelf = PyInt :: number_downcast ( num) ;
765765 try_to_float ( & zelf. value , vm) . map ( |x| vm. ctx . new_float ( x) )
766766 } ) ,
767- floor_divide : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_floordiv, vm) ) ,
768- true_divide : Some ( |num , other , vm| PyInt :: number_op ( num , other , inner_truediv, vm) ) ,
767+ floor_divide : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_floordiv, vm) ) ,
768+ true_divide : Some ( |a , b , vm| PyInt :: number_op ( a , b , inner_truediv, vm) ) ,
769769 index : Some ( |num, vm| Ok ( PyInt :: number_downcast_exact ( num, vm) ) ) ,
770770 ..PyNumberMethods :: NOT_IMPLEMENTED
771771 } ;
772772
773- fn number_op < F , R > ( number : PyNumber , other : & PyObject , op : F , vm : & VirtualMachine ) -> PyResult
773+ fn number_op < F , R > ( a : & PyObject , b : & PyObject , op : F , vm : & VirtualMachine ) -> PyResult
774774 where
775775 F : FnOnce ( & BigInt , & BigInt , & VirtualMachine ) -> R ,
776776 R : ToPyResult ,
777777 {
778- if let ( Some ( a) , Some ( b) ) = ( number . obj . payload :: < Self > ( ) , other . payload :: < Self > ( ) ) {
778+ if let ( Some ( a) , Some ( b) ) = ( a . payload :: < Self > ( ) , b . payload :: < Self > ( ) ) {
779779 op ( & a. value , & b. value , vm) . to_pyresult ( vm)
780780 } else {
781781 Ok ( vm. ctx . not_implemented ( ) )
0 commit comments