(special_name, arity, slot)
| 744 | |
| 745 | @special_method |
| 746 | def numeric_operator(special_name, arity, slot): |
| 747 | if arity == 'binary': |
| 748 | argnames = ['left', 'right'] |
| 749 | elif arity == 'ternary': |
| 750 | argnames = ['left', 'right', 'ex'] |
| 751 | else: |
| 752 | error("Invalid arity %s" % arity) |
| 753 | def_args_str = ', '.join("$%s:ident" % name for name in argnames) |
| 754 | impl_args_str = ' '.join("{ $%s : &$crate::PyObject = {} }" % name for name in argnames) |
| 755 | generate_case( |
| 756 | pattern='def %s(%s) -> $res_type:ty { $($body:tt)* }' |
| 757 | % (special_name, def_args_str), |
| 758 | new_impl='$crate::py_class_impl_item! { $class, $py, pub, %s() $res_type; { $($body)* } [ %s ] }' |
| 759 | % (special_name, impl_args_str), |
| 760 | new_slots=[(slot, '$crate::py_class_numeric_slot!(%s $class::%s)' % (arity, special_name))] |
| 761 | ) |
| 762 | error('Invalid signature for %s numeric operator %s' % (arity, special_name))(special_name) |
| 763 | |
| 764 | @special_method |
| 765 | def reflected_numeric_operator(special_name): |
no test coverage detected