@@ -763,56 +763,43 @@ macro_rules! atomic_func {
763763}
764764
765765impl AsNumber for PyInt {
766- const AS_NUMBER : PyNumberMethods = PyNumberMethods {
767- add : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a + b, vm) ) ,
768- subtract : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a - b, vm) ) ,
769- multiply : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a * b, vm) ) ,
770- remainder : atomic_func ! ( |num, other, vm| Self :: number_general_op(
771- num, other, inner_mod, vm
772- ) ) ,
773- divmod : atomic_func ! ( |num, other, vm| Self :: number_general_op(
774- num,
775- other,
776- inner_divmod,
777- vm
778- ) ) ,
779- power : atomic_func ! ( |num, other, vm| Self :: number_general_op( num, other, inner_pow, vm) ) ,
780- negative : atomic_func ! ( |num, vm| ( & Self :: number_downcast( num) . value) . neg( ) . to_pyresult( vm) ) ,
781- positive : atomic_func ! ( |num, vm| Ok ( Self :: number_int( num, vm) . into( ) ) ) ,
782- absolute : atomic_func ! ( |num, vm| Self :: number_downcast( num) . value. abs( ) . to_pyresult( vm) ) ,
783- boolean : atomic_func ! ( |num, _vm| Ok ( Self :: number_downcast( num) . value. is_zero( ) ) ) ,
784- invert : atomic_func ! ( |num, vm| ( & Self :: number_downcast( num) . value) . not( ) . to_pyresult( vm) ) ,
785- lshift : atomic_func ! ( |num, other, vm| Self :: number_general_op(
786- num,
787- other,
788- inner_lshift,
789- vm
790- ) ) ,
791- rshift : atomic_func ! ( |num, other, vm| Self :: number_general_op(
792- num,
793- other,
794- inner_rshift,
795- vm
796- ) ) ,
797- and : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a & b, vm) ) ,
798- xor : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a ^ b, vm) ) ,
799- or : atomic_func ! ( |num, other, vm| Self :: number_int_op( num, other, |a, b| a | b, vm) ) ,
800- int : atomic_func ! ( |num, other| Ok ( Self :: number_int( num, other) ) ) ,
801- float : atomic_func ! ( |num, vm| {
802- let zelf = Self :: number_downcast( num) ;
803- try_to_float( & zelf. value, vm) . map( |x| vm. ctx. new_float( x) )
804- } ) ,
805- floor_divide : atomic_func ! ( |num, other, vm| {
806- Self :: number_general_op( num, other, inner_floordiv, vm)
807- } ) ,
808- true_divide : atomic_func ! ( |num, other, vm| {
809- Self :: number_general_op( num, other, inner_truediv, vm)
810- } ) ,
811- index : atomic_func ! ( |num, vm| Ok ( Self :: number_int( num, vm) ) ) ,
812- ..PyNumberMethods :: NOT_IMPLEMENTED
813- } ;
766+ fn as_number ( ) -> & ' static PyNumberMethods {
767+ & AS_NUMBER
768+ }
814769}
815770
771+ static AS_NUMBER : PyNumberMethods = PyNumberMethods {
772+ add : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a + b, vm) ) ,
773+ subtract : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a - b, vm) ) ,
774+ multiply : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a * b, vm) ) ,
775+ remainder : atomic_func ! ( |num, other, vm| PyInt :: number_general_op( num, other, inner_mod, vm) ) ,
776+ divmod : atomic_func ! ( |num, other, vm| PyInt :: number_general_op( num, other, inner_divmod, vm) ) ,
777+ power : atomic_func ! ( |num, other, vm| PyInt :: number_general_op( num, other, inner_pow, vm) ) ,
778+ negative : atomic_func ! ( |num, vm| ( & PyInt :: number_downcast( num) . value) . neg( ) . to_pyresult( vm) ) ,
779+ positive : atomic_func ! ( |num, vm| Ok ( PyInt :: number_int( num, vm) . into( ) ) ) ,
780+ absolute : atomic_func ! ( |num, vm| PyInt :: number_downcast( num) . value. abs( ) . to_pyresult( vm) ) ,
781+ boolean : atomic_func ! ( |num, _vm| Ok ( PyInt :: number_downcast( num) . value. is_zero( ) ) ) ,
782+ invert : atomic_func ! ( |num, vm| ( & PyInt :: number_downcast( num) . value) . not( ) . to_pyresult( vm) ) ,
783+ lshift : atomic_func ! ( |num, other, vm| PyInt :: number_general_op( num, other, inner_lshift, vm) ) ,
784+ rshift : atomic_func ! ( |num, other, vm| PyInt :: number_general_op( num, other, inner_rshift, vm) ) ,
785+ and : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a & b, vm) ) ,
786+ xor : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a ^ b, vm) ) ,
787+ or : atomic_func ! ( |num, other, vm| PyInt :: number_int_op( num, other, |a, b| a | b, vm) ) ,
788+ int : atomic_func ! ( |num, other| Ok ( PyInt :: number_int( num, other) ) ) ,
789+ float : atomic_func ! ( |num, vm| {
790+ let zelf = PyInt :: number_downcast( num) ;
791+ try_to_float( & zelf. value, vm) . map( |x| vm. ctx. new_float( x) )
792+ } ) ,
793+ floor_divide : atomic_func ! ( |num, other, vm| {
794+ PyInt :: number_general_op( num, other, inner_floordiv, vm)
795+ } ) ,
796+ true_divide : atomic_func ! ( |num, other, vm| {
797+ PyInt :: number_general_op( num, other, inner_truediv, vm)
798+ } ) ,
799+ index : atomic_func ! ( |num, vm| Ok ( PyInt :: number_int( num, vm) ) ) ,
800+ ..PyNumberMethods :: NOT_IMPLEMENTED
801+ } ;
802+
816803impl PyInt {
817804 fn number_general_op < F > (
818805 number : & PyNumber ,
0 commit comments