[pypy-svn] r29782 - in pypy/dist/pypy/rpython: . ootypesystem test
antocuni at codespeak.net
antocuni at codespeak.net
Sat Jul 8 10:35:10 CEST 2006
Author: antocuni
Date: Sat Jul 8 10:35:02 2006
New Revision: 29782
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/ootypesystem/ooregistry.py
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/rstr.py
pypy/dist/pypy/rpython/test/test_rstr.py
Log:
Added support for string hashing to ootypesystem.
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Sat Jul 8 10:35:02 2006
@@ -830,6 +830,9 @@
except ValueError:
self.make_llexception()
+ def op_oohash(self, s):
+ return ootype.oohash(s)
+
class Tracer(object):
Counter = 0
file = None
Modified: pypy/dist/pypy/rpython/ootypesystem/ooregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ooregistry.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ooregistry.py Sat Jul 8 10:35:02 2006
@@ -48,3 +48,16 @@
hop.has_implicit_exception(ValueError)
hop.exception_is_here()
return hop.genop('ooparse_int', hop.args_v, resulttype = ootype.Signed)
+
+class Entry_oohash(ExtRegistryEntry):
+ _about_ = ootype.oohash
+
+ def compute_result_annotation(self, str_s):
+ assert isinstance(str_s, annmodel.SomeOOInstance)\
+ and str_s.ootype is ootype.String
+ return annmodel.SomeInteger()
+
+ def specialize_call(self, hop):
+ assert isinstance(hop.args_s[0], annmodel.SomeOOInstance)\
+ and hop.args_s[0].ootype is ootype.String
+ return hop.genop('oohash', hop.args_v, resulttype=ootype.Signed)
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Sat Jul 8 10:35:02 2006
@@ -1257,6 +1257,10 @@
assert isinstance(typeOf(inst), (Instance, Record))
return inst._identityhash()
+def oohash(inst):
+ assert typeOf(inst) is String # for now only strings are supported
+ return hash(inst._str)
+
def oostring(obj, base):
"""
Convert char, int, float, instances and str to str.
Modified: pypy/dist/pypy/rpython/ootypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rstr.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rstr.py Sat Jul 8 10:35:02 2006
@@ -67,6 +67,12 @@
def ll_chr2str(ch):
return ootype.oostring(ch, LLHelpers.ll_const(-1))
+ def ll_strhash(s):
+ return ootype.oohash(s)
+
+ def ll_strfasthash(s):
+ return ootype.oohash(s)
+
def ll_char_mul(ch, times):
buf = ootype.new(ootype.StringBuilder)
buf.ll_allocate(times)
Modified: pypy/dist/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rstr.py (original)
+++ pypy/dist/pypy/rpython/test/test_rstr.py Sat Jul 8 10:35:02 2006
@@ -562,6 +562,19 @@
res = self.interpret(f, ['a', 0])
assert self.ll_to_string(res) == ""
+ def test_hash(self):
+ def fn(i):
+ if i == 0:
+ s = ''
+ else:
+ s = "xxx"
+ return hash(s)
+ res = self.interpret(fn, [0])
+ assert res == self.EMPTY_STRING_HASH
+ res = self.interpret(fn, [1])
+ assert typeOf(res) == Signed
+
+
def FIXME_test_str_to_pystringobj():
def f(n):
if n >= 0:
@@ -581,6 +594,8 @@
class TestLLtype(BaseTestRstr, LLRtypeMixin):
+ EMPTY_STRING_HASH = -1
+
def llstr(self, s):
p = malloc(STR, len(s))
for i in range(len(s)):
@@ -599,18 +614,6 @@
assert res == s1.rfind(s2)
- def test_hash(self):
- def fn(i):
- if i == 0:
- s = ''
- else:
- s = "xxx"
- return hash(s)
- res = self.interpret(fn, [0])
- assert res == -1
- res = self.interpret(fn, [1])
- assert typeOf(res) == Signed
-
-
class TestOOtype(BaseTestRstr, OORtypeMixin):
- pass
+
+ EMPTY_STRING_HASH = 0
More information about the Pypy-commit
mailing list