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