[pypy-commit] pypy default: fix translation (maybe)

fijal noreply at buildbot.pypy.org
Mon Mar 25 22:39:06 CET 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r62757:b1537cfcaaed
Date: 2013-03-25 14:38 -0700
http://bitbucket.org/pypy/pypy/changeset/b1537cfcaaed/

Log:	fix translation (maybe)

diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -22,7 +22,6 @@
     assert not func.can_change_code
     return func.code
 
-
 class Function(W_Root):
     """A function is a code object captured with some environment:
     an object space, a dictionary of globals, default arguments,
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -812,6 +812,8 @@
     d = {}
     exec func_code.compile() in d
     f = d['f']
+    f.__module__ = func.__module__
+    # necessary for unique identifiers for pickling
     f.func_name = func.func_name
     if unwrap_spec is None:
         unwrap_spec = {}
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -1,7 +1,7 @@
 import operator
-from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std import model, newformat
+from pypy.objspace.std.floattype import float_typedef, W_AbstractFloatObject
 from pypy.objspace.std.multimethod import FailedToImplementArgs
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
@@ -19,36 +19,14 @@
 import math
 from pypy.objspace.std.intobject import W_IntObject
 
-class W_AbstractFloatObject(W_Object):
-    __slots__ = ()
-
-    def is_w(self, space, w_other):
-        from rpython.rlib.longlong2float import float2longlong
-        if not isinstance(w_other, W_AbstractFloatObject):
-            return False
-        if self.user_overridden_class or w_other.user_overridden_class:
-            return self is w_other
-        one = float2longlong(space.float_w(self))
-        two = float2longlong(space.float_w(w_other))
-        return one == two
-
-    def immutable_unique_id(self, space):
-        if self.user_overridden_class:
-            return None
-        from rpython.rlib.longlong2float import float2longlong
-        from pypy.objspace.std.model import IDTAG_FLOAT as tag
-        val = float2longlong(space.float_w(self))
-        b = rbigint.fromrarith_int(val)
-        b = b.lshift(3).or_(rbigint.fromint(tag))
-        return space.newlong_from_rbigint(b)
-
 
 class W_FloatObject(W_AbstractFloatObject):
     """This is a implementation of the app-level 'float' type.
     The constructor takes an RPython float as an argument."""
-    from pypy.objspace.std.floattype import float_typedef as typedef
     _immutable_fields_ = ['floatval']
 
+    typedef = float_typedef
+
     def __init__(w_self, floatval):
         w_self.floatval = floatval
 
@@ -59,6 +37,9 @@
         return self.floatval
 
     def int(self, space):
+        if (type(self) is not W_FloatObject and
+            space.is_overloaded(self, space.w_float, '__int__')):
+            return W_Object.int(self, space)
         try:
             value = ovfcheck_float_to_int(self.floatval)
         except OverflowError:
diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -3,13 +3,15 @@
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rlib import rfloat, rarithmetic
 from pypy.interpreter import typedef
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault,\
+     interpindirect2app
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.strutil import ParseStringError
 from pypy.objspace.std.strutil import string_to_float
+from pypy.objspace.std.model import W_Object
+from rpython.rlib.rbigint import rbigint
 
 
 float_as_integer_ratio = SMM("as_integer_ratio", 1)
@@ -270,6 +272,32 @@
 
 # ____________________________________________________________
 
+class W_AbstractFloatObject(W_Object):
+    __slots__ = ()
+
+    def is_w(self, space, w_other):
+        from rpython.rlib.longlong2float import float2longlong
+        if not isinstance(w_other, W_AbstractFloatObject):
+            return False
+        if self.user_overridden_class or w_other.user_overridden_class:
+            return self is w_other
+        one = float2longlong(space.float_w(self))
+        two = float2longlong(space.float_w(w_other))
+        return one == two
+
+    def immutable_unique_id(self, space):
+        if self.user_overridden_class:
+            return None
+        from rpython.rlib.longlong2float import float2longlong
+        from pypy.objspace.std.model import IDTAG_FLOAT as tag
+        val = float2longlong(space.float_w(self))
+        b = rbigint.fromrarith_int(val)
+        b = b.lshift(3).or_(rbigint.fromint(tag))
+        return space.newlong_from_rbigint(b)
+
+    def int(self, space):
+        raise NotImplementedError
+
 float_typedef = StdTypeDef("float",
     __doc__ = '''float(x) -> floating point number
 
@@ -280,5 +308,6 @@
     conjugate = interp2app(descr_conjugate),
     real = typedef.GetSetProperty(descr_get_real),
     imag = typedef.GetSetProperty(descr_get_imag),
+    __int__ = interpindirect2app(W_AbstractFloatObject.int),
 )
 float_typedef.registermethods(globals())


More information about the pypy-commit mailing list