paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@6 | 3 | """ |
paul@6 | 4 | Integer objects. |
paul@6 | 5 | |
paul@6 | 6 | Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@6 | 7 | |
paul@6 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@6 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@6 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@6 | 11 | version. |
paul@6 | 12 | |
paul@6 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@6 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@6 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@6 | 16 | details. |
paul@6 | 17 | |
paul@6 | 18 | You should have received a copy of the GNU General Public License along with |
paul@6 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@6 | 20 | """ |
paul@6 | 21 | |
paul@60 | 22 | from __builtins__.operator import _binary_op, _negate |
paul@6 | 23 | import native |
paul@6 | 24 | |
paul@6 | 25 | class int(object): |
paul@6 | 26 | def __init__(self, number_or_string=None): |
paul@6 | 27 | # Note member. |
paul@135 | 28 | self.__data__ = 0 |
paul@6 | 29 | |
paul@6 | 30 | def __iadd__(self, other): |
paul@6 | 31 | "Return a new int for the operation." |
paul@6 | 32 | return _binary_op(self, other, native._int_add) |
paul@6 | 33 | |
paul@6 | 34 | def __isub__(self, other): |
paul@6 | 35 | "Return a new int for the operation." |
paul@6 | 36 | return _binary_op(self, other, native._int_sub) |
paul@6 | 37 | |
paul@6 | 38 | def __imul__(self, other): |
paul@6 | 39 | "Return a new int for the operation." |
paul@6 | 40 | return _binary_op(self, other, native._int_mul) |
paul@6 | 41 | |
paul@6 | 42 | def __idiv__(self, other): |
paul@6 | 43 | "Return a new int for the operation." |
paul@6 | 44 | return _binary_op(self, other, native._int_div) |
paul@6 | 45 | |
paul@6 | 46 | def __imod__(self, other): |
paul@6 | 47 | "Return a new int for the operation." |
paul@6 | 48 | return _binary_op(self, other, native._int_mod) |
paul@6 | 49 | |
paul@6 | 50 | def __ipow__(self, other): |
paul@6 | 51 | "Return a new int for the operation." |
paul@6 | 52 | return _binary_op(self, other, native._int_pow) |
paul@6 | 53 | |
paul@6 | 54 | def __iand__(self, other): |
paul@6 | 55 | "Return a new int for the operation." |
paul@6 | 56 | return _binary_op(self, other, native._int_and) |
paul@6 | 57 | |
paul@6 | 58 | def __ior__(self, other): |
paul@6 | 59 | "Return a new int for the operation." |
paul@6 | 60 | return _binary_op(self, other, native._int_or) |
paul@6 | 61 | |
paul@6 | 62 | def __ixor__(self, other): |
paul@6 | 63 | "Return a new int for the operation." |
paul@6 | 64 | return _binary_op(self, other, native._int_xor) |
paul@6 | 65 | |
paul@6 | 66 | __add__ = __radd__ = __iadd__ |
paul@6 | 67 | __sub__ = __isub__ |
paul@6 | 68 | |
paul@6 | 69 | def __rsub__(self, other): |
paul@6 | 70 | "Return a new int for the operation." |
paul@6 | 71 | return _binary_op(self, other, native._int_rsub) |
paul@6 | 72 | |
paul@6 | 73 | __mul__ = __rmul__ = __imul__ |
paul@6 | 74 | __div__ = __idiv__ |
paul@6 | 75 | |
paul@6 | 76 | def __rdiv__(self, other): |
paul@6 | 77 | "Return a new int for the operation." |
paul@6 | 78 | return _binary_op(self, other, native._int_rdiv) |
paul@6 | 79 | |
paul@6 | 80 | def __floordiv__(self, other): pass |
paul@6 | 81 | def __rfloordiv__(self, other): pass |
paul@6 | 82 | def __ifloordiv__(self, other): pass |
paul@6 | 83 | |
paul@6 | 84 | __mod__ = __imod__ |
paul@6 | 85 | |
paul@6 | 86 | def __rmod__(self, other): |
paul@6 | 87 | "Return a new int for the operation." |
paul@6 | 88 | return _binary_op(self, other, native._int_rmod) |
paul@6 | 89 | |
paul@6 | 90 | __pow__ = __ipow__ |
paul@6 | 91 | |
paul@6 | 92 | def __rpow__(self, other): |
paul@6 | 93 | "Return a new int for the operation." |
paul@6 | 94 | return _binary_op(self, other, native._int_rpow) |
paul@6 | 95 | |
paul@6 | 96 | __and__ = __rand__ = __iand__ |
paul@6 | 97 | __or__ = __ror__ = __ior__ |
paul@6 | 98 | __xor__ = __rxor__ = __ixor__ |
paul@6 | 99 | |
paul@6 | 100 | def __lt__(self, other): |
paul@6 | 101 | "Return a new boolean for the comparison." |
paul@6 | 102 | return _binary_op(self, other, native._int_lt) |
paul@6 | 103 | |
paul@6 | 104 | def __gt__(self, other): |
paul@6 | 105 | "Return a new boolean for the comparison." |
paul@6 | 106 | return _binary_op(self, other, native._int_gt) |
paul@6 | 107 | |
paul@6 | 108 | def __le__(self, other): |
paul@6 | 109 | "Return a new boolean for the comparison." |
paul@6 | 110 | return _negate(self.__gt__(other)) |
paul@6 | 111 | |
paul@6 | 112 | def __ge__(self, other): |
paul@6 | 113 | "Return a new boolean for the comparison." |
paul@6 | 114 | return _negate(self.__lt__(other)) |
paul@6 | 115 | |
paul@6 | 116 | def __eq__(self, other): |
paul@6 | 117 | "Return a new boolean for the comparison." |
paul@6 | 118 | return _binary_op(self, other, native._int_eq) |
paul@6 | 119 | |
paul@6 | 120 | def __ne__(self, other): |
paul@6 | 121 | "Return a new boolean for the comparison." |
paul@6 | 122 | return _negate(self.__eq__(other)) |
paul@6 | 123 | |
paul@6 | 124 | def __invert__(self): pass |
paul@6 | 125 | def __neg__(self): pass |
paul@6 | 126 | def __pos__(self): pass |
paul@6 | 127 | def __str__(self): pass |
paul@6 | 128 | def __lshift__(self): pass |
paul@6 | 129 | def __rlshift__(self): pass |
paul@6 | 130 | def __rshift__(self): pass |
paul@6 | 131 | def __rrshift__(self): pass |
paul@6 | 132 | def __ilshift__(self): pass |
paul@6 | 133 | def __irshift__(self): pass |
paul@6 | 134 | |
paul@6 | 135 | def __bool__(self): |
paul@6 | 136 | "Return whether this int is non-zero." |
paul@6 | 137 | return _negate(native._int_eq(self, 0)) |
paul@6 | 138 | |
paul@6 | 139 | # vim: tabstop=4 expandtab shiftwidth=4 |