[pypy-svn] r15583 - in pypy/dist/pypy: interpreter objspace objspace/std
pedronis at codespeak.net
pedronis at codespeak.net
Thu Aug 4 03:56:36 CEST 2005
Author: pedronis
Date: Thu Aug 4 03:56:31 2005
New Revision: 15583
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/objspace/descroperation.py
pypy/dist/pypy/objspace/std/objecttype.py
Log:
issue106 in-progress
start of refactoring of the implementation of identity hash computation. Use the rtyper support for hash() and
value preservation across translation.
This is a first stab. By attaching a identity_hash using hash() only where stricly necessary we can avoid
all W_Root object to internally grow an hash_cache field: this rearragement is to be done later.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Thu Aug 4 03:56:31 2005
@@ -5,7 +5,7 @@
from pypy.interpreter.pycompiler import PythonCompiler, PyPyCompiler
from pypy.interpreter.miscutils import ThreadLocals
from pypy.tool.cache import Cache
-from pypy.rpython.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint, intmask
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'BaseWrappable',
'W_Root']
@@ -59,6 +59,9 @@
def setslotvalue(self, index, w_val):
raise NotImplementedError
+ def identity_hash(self, space):
+ return space.wrap(intmask(hash(self))) #space.id(self)
+
class BaseWrappable(W_Root):
"""A subclass of BaseWrappable is an internal, interpreter-level class
that can nevertheless be exposed at application-level by space.wrap()."""
Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py (original)
+++ pypy/dist/pypy/objspace/descroperation.py Thu Aug 4 03:56:31 2005
@@ -269,7 +269,7 @@
space.lookup(w_obj, '__cmp__') is not None:
raise OperationError(space.w_TypeError,
space.wrap("unhashable type"))
- return space.id(w_obj)
+ return w_obj.identity_hash(space)
w_result = space.get_and_call_function(w_hash, w_obj)
if space.is_true(space.isinstance(w_result, space.w_int)):
return w_result
Modified: pypy/dist/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objecttype.py (original)
+++ pypy/dist/pypy/objspace/std/objecttype.py Thu Aug 4 03:56:31 2005
@@ -53,7 +53,7 @@
return w_obj
def descr__hash__(space, w_obj):
- return space.id(w_obj)
+ return w_obj.identity_hash(space)
def descr__init__(space, w_obj, __args__):
pass
More information about the Pypy-commit
mailing list