[pypy-svn] r13926 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Sun Jun 26 12:35:30 CEST 2005


Author: arigo
Date: Sun Jun 26 12:35:28 2005
New Revision: 13926

Modified:
   pypy/dist/pypy/rpython/rconstantdict.py
   pypy/dist/pypy/rpython/test/test_rconstantdict.py
Log:
'contains' for constant dicts.


Modified: pypy/dist/pypy/rpython/rconstantdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rconstantdict.py	(original)
+++ pypy/dist/pypy/rpython/rconstantdict.py	Sun Jun 26 12:35:28 2005
@@ -97,6 +97,13 @@
         return hop.gendirectcall(ll_constantdict_getitem, v_dict, v_key,
                                  chashcompute)
 
+    def rtype_contains((r_dict, r_key), hop):
+        v_dict, v_key = hop.inputargs(r_dict, r_dict.key_repr)
+        hashcompute = r_dict.get_key_hash_function()
+        chashcompute = hop.inputconst(lltype.Void, hashcompute)
+        return hop.gendirectcall(ll_constantdict_contains, v_dict, v_key,
+                                 chashcompute)
+
 # ____________________________________________________________
 #
 #  Low-level methods.  These can be run for testing, but are meant to
@@ -113,6 +120,10 @@
     else: 
         raise KeyError 
 
+def ll_constantdict_contains(d, key, hashcompute):
+    entry = ll_constantdict_lookup(d, key, hashcompute)
+    return entry.valid
+
 def ll_constantdict_setnewitem(d, key, value, hashcompute): 
     entry = ll_constantdict_lookup(d, key, hashcompute)
     assert not entry.valid 

Modified: pypy/dist/pypy/rpython/test/test_rconstantdict.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rconstantdict.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rconstantdict.py	Sun Jun 26 12:35:28 2005
@@ -7,3 +7,12 @@
         return d[i]
     res = interpret(func, [3])
     assert res == 4
+
+def test_constantdict_contains():
+    d = {1: True, 4: True, 16: True}
+    def func(i):
+        return i in d
+    res = interpret(func, [15])
+    assert res is False
+    res = interpret(func, [4])
+    assert res is True



More information about the Pypy-commit mailing list