[pypy-svn] r68367 - in pypy/branch/gc-hash/pypy/rlib: . test

arigo at codespeak.net arigo at codespeak.net
Tue Oct 13 13:15:26 CEST 2009


Author: arigo
Date: Tue Oct 13 13:15:25 2009
New Revision: 68367

Modified:
   pypy/branch/gc-hash/pypy/rlib/jit.py
   pypy/branch/gc-hash/pypy/rlib/objectmodel.py
   pypy/branch/gc-hash/pypy/rlib/rarithmetic.py
   pypy/branch/gc-hash/pypy/rlib/rope.py
   pypy/branch/gc-hash/pypy/rlib/test/test_objectmodel.py
Log:
Finish the refactoring of rlib/objectmodel.


Modified: pypy/branch/gc-hash/pypy/rlib/jit.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rlib/jit.py	(original)
+++ pypy/branch/gc-hash/pypy/rlib/jit.py	Tue Oct 13 13:15:25 2009
@@ -206,9 +206,6 @@
             raise JitHintError("%s expects the following keyword "
                                "arguments: %s" % (self.instance,
                                                   expected))
-        for name in driver.greens:
-            s_green_key = kwds_s['s_' + name]
-            s_green_key.hash()      # force the hash cache to appear
 
         if self.instance.__name__ == 'jit_merge_point':
             self.annotate_hooks(**kwds_s)

Modified: pypy/branch/gc-hash/pypy/rlib/objectmodel.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rlib/objectmodel.py	(original)
+++ pypy/branch/gc-hash/pypy/rlib/objectmodel.py	Tue Oct 13 13:15:25 2009
@@ -230,9 +230,9 @@
 def _hash_tuple(t):
     """NOT_RPYTHON.  The algorithm behind compute_hash() for a tuple.
     It is modelled after the old algorithm of Python 2.3, which is
-    slightly faster than the one introduced by Python 2.4.  We assume
-    that nested tuples are very uncommon in RPython, making the case
-    unlikely.
+    a bit faster than the one introduced by Python 2.4.  We assume
+    that nested tuples are very uncommon in RPython, making the bad
+    case unlikely.
     """
     from pypy.rlib.rarithmetic import intmask
     x = 0x345678
@@ -266,13 +266,13 @@
         return annmodel.SomeInteger()
 
     def specialize_call(self, hop):
+        from pypy.rpython.lltypesystem import lltype
         vobj, = hop.inputargs(hop.args_r[0])
         if hop.rtyper.type_system.name == 'lltypesystem':
-            from pypy.rpython.lltypesystem import lltype
             ok = (isinstance(vobj.concretetype, lltype.Ptr) and
                   vobj.concretetype.TO._gckind == 'gc')
         else:
-            from pypy.rpython.lltypesystem import ootype
+            from pypy.rpython.ootypesystem import ootype
             ok = isinstance(vobj.concretetype, ootype.OOType)
         if not ok:
             from pypy.rpython.error import TyperError
@@ -288,23 +288,19 @@
         return annmodel.SomeInteger()
 
     def specialize_call(self, hop):
+        from pypy.rpython.lltypesystem import lltype
         vobj, = hop.inputargs(hop.args_r[0])
         if hop.rtyper.type_system.name == 'lltypesystem':
-            from pypy.rpython.lltypesystem import lltype
-            if isinstance(vobj.concretetype, lltype.Ptr):
-                return hop.genop('gc_id', [vobj],
-                                 resulttype = lltype.Signed)
-        elif hop.rtyper.type_system.name == 'ootypesystem':
+            ok = (isinstance(vobj.concretetype, lltype.Ptr) and
+                  vobj.concretetype.TO._gckind == 'gc')
+        else:
             from pypy.rpython.ootypesystem import ootype
-            if isinstance(vobj.concretetype, ootype.Instance):
-                # XXX wrong implementation for now, fix me
-                from pypy.rpython.rmodel import warning
-                warning("compute_unique_id() is not fully supported on ootype")
-                return hop.genop('identityhash', [vobj],
-                                 resulttype = ootype.Signed)
-        from pypy.rpython.error import TyperError
-        raise TyperError("compute_unique_id() cannot be applied to %r" % (
-            vobj.concretetype,))
+            ok = isinstance(vobj.concretetype, ootype.Instance)
+        if not ok:
+            from pypy.rpython.error import TyperError
+            raise TyperError("compute_unique_id() cannot be applied to"
+                             " %r" % (vobj.concretetype,))
+        return hop.genop('gc_id', [vobj], resulttype=lltype.Signed)
 
 class Entry(ExtRegistryEntry):
     _about_ = current_object_addr_as_int

Modified: pypy/branch/gc-hash/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rlib/rarithmetic.py	(original)
+++ pypy/branch/gc-hash/pypy/rlib/rarithmetic.py	Tue Oct 13 13:15:25 2009
@@ -463,23 +463,6 @@
 
     return formatd(fmt, x)
 
-# a common string hash function
-
-def _hash_string(s):
-    length = len(s)
-    if length == 0:
-        x = -1
-    else:
-        x = ord(s[0]) << 7
-        i = 0
-        while i < length:
-            x = (1000003*x) ^ ord(s[i])
-            i += 1
-        x ^= length
-        if x == 0:
-            x = -1
-    return intmask(x)
-
 # the 'float' C type
 
 class r_singlefloat(object):

Modified: pypy/branch/gc-hash/pypy/rlib/rope.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rlib/rope.py	(original)
+++ pypy/branch/gc-hash/pypy/rlib/rope.py	Tue Oct 13 13:15:25 2009
@@ -1,6 +1,6 @@
 import py
 import sys
-from pypy.rlib.rarithmetic import intmask, _hash_string, ovfcheck
+from pypy.rlib.rarithmetic import intmask, ovfcheck
 from pypy.rlib.rarithmetic import r_uint, LONG_BIT
 from pypy.rlib.objectmodel import we_are_translated
 import math

Modified: pypy/branch/gc-hash/pypy/rlib/test/test_objectmodel.py
==============================================================================
--- pypy/branch/gc-hash/pypy/rlib/test/test_objectmodel.py	(original)
+++ pypy/branch/gc-hash/pypy/rlib/test/test_objectmodel.py	Tue Oct 13 13:15:25 2009
@@ -349,8 +349,10 @@
         q = Foo()
 
         def f(i):
+            assert compute_hash(None) == 0
             assert compute_hash(i) == h_42
             assert compute_hash(i+1.0) == h_43_dot_0
+            assert compute_hash((i+3)/6.0) == h_7_dot_5
             assert compute_hash("Hello" + str(i)) == h_Hello42
             if i == 42:
                 p = None
@@ -362,6 +364,7 @@
             return i*2
         h_42       = compute_hash(42)
         h_43_dot_0 = compute_hash(43.0)
+        h_7_dot_5  = compute_hash(7.5)
         h_Hello42  = compute_hash("Hello42")
         h_None     = compute_hash(None)
         h_tuple    = compute_hash(("world", None, 42, 7.5))



More information about the Pypy-commit mailing list