Author: Christian Tismer <[email protected]>
Branch: win64-stage1
Changeset: r49819:30a323a07b06
Date: 2011-11-26 16:19 +0100
http://bitbucket.org/pypy/pypy/changeset/30a323a07b06/
Log: merge defauli
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -188,6 +188,10 @@
# -------------------------------------------------------------------
+ def is_w(self, space, w_other):
+ return self is w_other
+
+ def unique_id(self, space):
def str_w(self, space):
w_msg = typed_unwrap_error_msg(space, "string", self)
raise OperationError(space.w_TypeError, w_msg)
@@ -684,6 +688,7 @@
def is_w(self, w_obj1, w_obj2):
"""shortcut for space.is_true(space.is_(w_obj1, w_obj2))"""
return self.is_true(self.is_(w_obj1, w_obj2))
+ return w_obj.unique_id(self)
def hash_w(self, w_obj):
"""shortcut for space.int_w(space.hash(w_obj))"""
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -97,6 +97,12 @@
self.executioncontext.recorder = previous_recorder
self.concrete_mode -= 1
+ def is_w(self, w_one, w_two):
+ return self.is_true(self.is_(w_one, w_two))
+
+ is_ = None # real version added by add_operations()
+ id = None # real version added by add_operations()
+
def newdict(self):
if self.concrete_mode:
return Constant({})
diff --git a/pypy/objspace/flow/operation.py b/pypy/objspace/flow/operation.py
--- a/pypy/objspace/flow/operation.py
+++ b/pypy/objspace/flow/operation.py
@@ -315,7 +315,7 @@
del _add_exceptions, _add_except_ovf
def make_op(fs, name, symbol, arity, specialnames):
- if hasattr(fs, name):
+ if getattr(fs, name, None) is not None:
return
op = None
diff --git a/pypy/objspace/std/complexobject.py
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -5,12 +5,46 @@
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.floatobject import W_FloatObject, _hash_float
from pypy.objspace.std.longobject import W_LongObject
+from pypy.rlib.rbigint import rbigint
from pypy.rlib.rfloat import (
formatd, DTSF_STR_PRECISION, isinf, isnan, copysign)
import math
-class W_ComplexObject(W_Object):
+
+class W_AbstractComplexObject(W_Object):
+ __slots__ = ()
+
+ def is_w(self, space, w_other):
+ from pypy.rlib.longlong2float import float2longlong
+ if not isinstance(w_other, W_AbstractComplexObject):
+ return False
+ if self.user_overridden_class or w_other.user_overridden_class:
+ return self is w_other
+ real1 = space.float_w(space.getattr(self, space.wrap("real")))
+ real2 = space.float_w(space.getattr(w_other, space.wrap("real")))
+ imag1 = space.float_w(space.getattr(self, space.wrap("imag")))
+ imag2 = space.float_w(space.getattr(w_other, space.wrap("imag")))
+ real1 = float2longlong(real1)
+ real2 = float2longlong(real2)
+ imag1 = float2longlong(imag1)
+ imag2 = float2longlong(imag2)
+ return real1 == real2 and imag1 == imag2
+
+ def unique_id(self, space):
+ if self.user_overridden_class:
+ return W_Object.unique_id(self, space)
+ from pypy.rlib.longlong2float import float2longlong
+ from pypy.objspace.std.model import IDTAG_COMPLEX as tag
+ real = space.float_w(space.getattr(self, space.wrap("real")))
+ imag = space.float_w(space.getattr(self, space.wrap("imag")))
+ real_b = rbigint.fromrarith_int(float2longlong(real))
+ imag_b = rbigint.fromrarith_int(float2longlong(imag))
+ val = real_b.lshift(64).or_(imag_b).lshift(3).or_(rbigint.fromint(tag))
+ return space.newlong_from_rbigint(val)
+
+
+class W_ComplexObject(W_AbstractComplexObject):
"""This is a reimplementation of the CPython "PyComplexObject"
"""
from pypy.objspace.std.complextype import complex_typedef as typedef
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
@@ -21,10 +21,33 @@
import math
from pypy.objspace.std.intobject import W_IntObject
-class W_FloatObject(W_Object):
- """This is a reimplementation of the CPython "PyFloatObject"
- it is assumed that the constructor takes a real Python float as
- an argument"""
+class W_AbstractFloatObject(W_Object):
+ __slots__ = ()
+
+ def is_w(self, space, w_other):
+ from pypy.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 unique_id(self, space):
+ if self.user_overridden_class:
+ return W_Object.unique_id(self, space)
+ from pypy.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']
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -19,6 +19,22 @@
class W_AbstractIntObject(W_Object):
__slots__ = ()
+ def is_w(self, space, w_other):
+ if not isinstance(w_other, W_AbstractIntObject):
+ return False
+ if self.user_overridden_class or w_other.user_overridden_class:
+ return self is w_other
+ return space.int_w(self) == space.int_w(w_other)
+
+ def unique_id(self, space):
+ if self.user_overridden_class:
+ return W_Object.unique_id(self, space)
+ from pypy.objspace.std.model import IDTAG_INT as tag
+ b = space.bigint_w(self)
+ b = b.lshift(3).or_(rbigint.fromint(tag))
+ return space.newlong_from_rbigint(b)
+
+
class W_IntObject(W_AbstractIntObject):
__slots__ = 'intval'
_immutable_fields_ = ['intval']
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit