Commits

Maciej Fijalkowski  committed 514091a

remove int_w, bigint_w and uint_w as multimethods

  • Participants
  • Parent commits 30254a5
  • Branches kill-unary-multimethods

Comments (0)

Files changed (7)

File pypy/interpreter/baseobjspace.py

         raise OperationError(space.w_TypeError,
                              typed_unwrap_error_msg(space, "unicode", self))
 
+    def int_w(self, space):
+        raise OperationError(space.w_TypeError,
+                             typed_unwrap_error_msg(space, "integer", self))
+    uint_w = int_w
+    bigint_w = int_w
 
 
 class Wrappable(W_Root):
     def str_w(self, w_obj):
         return w_obj.str_w(self)
 
+    def int_w(self, w_obj):
+        return w_obj.int_w(self)
+
+    def uint_w(self, w_obj):
+        return w_obj.uint_w(self)
+
+    def bigint_w(self, w_obj):
+        return w_obj.bigint_w(self)
+
     def realstr_w(self, w_obj):
         # Like str_w, but only works if w_obj is really of type 'str'.
         if not self.is_true(self.isinstance(w_obj, self.w_str)):

File pypy/objspace/std/boolobject.py

+from pypy.rlib.rbigint import rbigint
+from pypy.rlib.rarithmetic import r_uint
+from pypy.interpreter.error import OperationError
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.intobject import W_IntObject
 
-
 class W_BoolObject(W_Object):
     from pypy.objspace.std.booltype import bool_typedef as typedef
     _immutable_fields_ = ['boolval']
 
     def unwrap(w_self, space):
         return w_self.boolval
+    int_w = unwrap
+
+    def uint_w(w_self, space):
+        intval = w_self.intval
+        if intval < 0:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("cannot convert negative integer to unsigned"))
+        else:
+            return r_uint(intval)
+
+    def bigint_w(w_self, space):
+        return rbigint.fromint(w_self.intval)
+
 
 registerimplementation(W_BoolObject)
 

File pypy/objspace/std/default.py

 def init__ANY(space, w_obj, __args__):
     pass
 
-def int_w__ANY(space,w_obj):
-    raise OperationError(space.w_TypeError,
-                         typed_unwrap_error_msg(space, "integer", w_obj))
-
 def float_w__ANY(space,w_obj):
     raise OperationError(space.w_TypeError,
                          typed_unwrap_error_msg(space, "float", w_obj))
 
-def uint_w__ANY(space,w_obj):
-    raise OperationError(space.w_TypeError,
-                         typed_unwrap_error_msg(space, "integer", w_obj))
-
-def bigint_w__ANY(space,w_obj):
-    raise OperationError(space.w_TypeError,
-                         typed_unwrap_error_msg(space, "integer", w_obj))
-
 register_all(vars())

File pypy/objspace/std/intobject.py

 
     def unwrap(w_self, space):
         return int(w_self.intval)
+    int_w = unwrap
 
+    def uint_w(w_self, space):
+        intval = w_self.intval
+        if intval < 0:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("cannot convert negative integer to unsigned"))
+        else:
+            return r_uint(intval)
+
+    def bigint_w(w_self, space):
+        return rbigint.fromint(w_self.intval)
 
 registerimplementation(W_IntObject)
 
 # alias and then teach copy_multimethods in smallintobject.py to override
 # it. See int__Int for example.
 
-def int_w__Int(space, w_int1):
-    return int(w_int1.intval)
-
-def uint_w__Int(space, w_int1):
-    intval = w_int1.intval
-    if intval < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("cannot convert negative integer to unsigned"))
-    else:
-        return r_uint(intval)
-
-def bigint_w__Int(space, w_int1):
-    return rbigint.fromint(w_int1.intval)
-
 def repr__Int(space, w_int1):
     a = w_int1.intval
     res = str(a)

File pypy/objspace/std/longobject.py

     fromrarith_int._annspecialcase_ = "specialize:argtype(0)"
     fromrarith_int = staticmethod(fromrarith_int)
 
+    def int_w(w_self, space):
+        try:
+            return w_self.num.toint()
+        except OverflowError:
+            raise OperationError(space.w_OverflowError, space.wrap(
+                "long int too large to convert to int"))
+
+    def uint_w(w_self, space):
+        try:
+            return w_self.num.touint()
+        except ValueError:
+            raise OperationError(space.w_ValueError, space.wrap(
+                "cannot convert negative integer to unsigned int"))
+        except OverflowError:
+            raise OperationError(space.w_OverflowError, space.wrap(
+                "long int too large to convert to unsigned int"))
+
+    def bigint_w(w_self, space):
+        return w_self.num
+
     def __repr__(self):
         return '<W_LongObject(%d)>' % self.num.tolong()
 
         raise OperationError(space.w_OverflowError,
                              space.wrap("long int too large to convert to float"))
 
-def int_w__Long(space, w_value):
-    try:
-        return w_value.num.toint()
-    except OverflowError:
-        raise OperationError(space.w_OverflowError, space.wrap(
-            "long int too large to convert to int"))
-
-
-def uint_w__Long(space, w_value):
-    try:
-        return w_value.num.touint()
-    except ValueError:
-        raise OperationError(space.w_ValueError, space.wrap(
-            "cannot convert negative integer to unsigned int"))
-    except OverflowError:
-        raise OperationError(space.w_OverflowError, space.wrap(
-            "long int too large to convert to unsigned int"))
-
-def bigint_w__Long(space, w_value):
-    return w_value.num
-
 def repr__Long(space, w_long):
     return space.wrap(w_long.num.repr())
 

File pypy/objspace/std/model.py

         mm.dispatch_tree = merge(self.dispatch_tree, other.dispatch_tree)
         return mm
 
+NOT_MULTIMETHODS = []
 
 class MM:
     """StdObjSpace multimethods"""
     init    = StdObjSpaceMultiMethod('__init__', 1, general__args__=True)
     getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
     # special visible multimethods
-    int_w   = StdObjSpaceMultiMethod('int_w', 1, [])     # returns an unwrapped int
     float_w = StdObjSpaceMultiMethod('float_w', 1, [])   # returns an unwrapped float
-    uint_w  = StdObjSpaceMultiMethod('uint_w', 1, [])    # returns an unwrapped unsigned int (r_uint)
-    bigint_w = StdObjSpaceMultiMethod('bigint_w', 1, []) # returns an unwrapped rbigint
     # NOTE: when adding more sometype_w() methods, you need to write a
     # stub in default.py to raise a space.w_TypeError
     marshal_w = StdObjSpaceMultiMethod('marshal_w', 1, [], extra_args=['marshaller'])
 
     # add all regular multimethods here
     for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
-        if _name not in locals():
+        if _name not in locals() or _name in NOT_MULTIMETHODS:
             mm = StdObjSpaceMultiMethod(_symbol, _arity, _specialnames)
             locals()[_name] = mm
             del mm
 
     pow.extras['defaults'] = (None,)
+

File pypy/objspace/std/smalllongobject.py

     def __repr__(w_self):
         return '<W_SmallLongObject(%d)>' % w_self.longlong
 
+    def int_w(w_self, space):
+        a = w_self.longlong
+        b = intmask(a)
+        if b == a:
+            return b
+        else:
+            raise OperationError(space.w_OverflowError, space.wrap(
+                "long int too large to convert to int"))
+
+    def uint_w(w_self, space):
+        a = w_self.longlong
+        if a < 0:
+            raise OperationError(space.w_ValueError, space.wrap(
+                "cannot convert negative integer to unsigned int"))
+        b = r_uint(a)
+        if r_longlong(b) == a:
+            return b
+        else:
+            raise OperationError(space.w_OverflowError, space.wrap(
+                "long int too large to convert to unsigned int"))
+
+    def bigint_w(w_self, space):
+        return w_self.asbigint()
+
 registerimplementation(W_SmallLongObject)
 
 # ____________________________________________________________
 def float__SmallLong(space, w_value):
     return space.newfloat(float(w_value.longlong))
 
-def int_w__SmallLong(space, w_value):
-    a = w_value.longlong
-    b = intmask(a)
-    if b == a:
-        return b
-    else:
-        raise OperationError(space.w_OverflowError, space.wrap(
-            "long int too large to convert to int"))
-
-def uint_w__SmallLong(space, w_value):
-    a = w_value.longlong
-    if a < 0:
-        raise OperationError(space.w_ValueError, space.wrap(
-            "cannot convert negative integer to unsigned int"))
-    b = r_uint(a)
-    if r_longlong(b) == a:
-        return b
-    else:
-        raise OperationError(space.w_OverflowError, space.wrap(
-            "long int too large to convert to unsigned int"))
-
-def bigint_w__SmallLong(space, w_value):
-    return w_value.asbigint()
-
 def lt__SmallLong_SmallLong(space, w_small1, w_small2):
     return space.newbool(w_small1.longlong <  w_small2.longlong)
 def le__SmallLong_SmallLong(space, w_small1, w_small2):