[pypy-svn] r13726 - in pypy/dist/pypy/rpython: . test
hpk at codespeak.net
hpk at codespeak.net
Thu Jun 23 17:32:33 CEST 2005
Author: hpk
Date: Thu Jun 23 17:32:32 2005
New Revision: 13726
Modified:
pypy/dist/pypy/rpython/rdict.py
pypy/dist/pypy/rpython/test/test_rdict.py
Log:
(arre, hpk)
added some delitem and len support (still no resizing is going on)
Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py (original)
+++ pypy/dist/pypy/rpython/rdict.py Thu Jun 23 17:32:32 2005
@@ -79,9 +79,9 @@
# result.items[i] = r_item.convert_const(x)
# return result
- #def rtype_len(self, hop):
- # v_lst, = hop.inputargs(self)
- # return hop.gendirectcall(ll_len, v_lst)
+ def rtype_len(self, hop):
+ v_dict, = hop.inputargs(self)
+ return hop.gendirectcall(ll_strdict_len, v_dict)
class __extend__(pairtype(StrDictRepr, rmodel.StringRepr)):
@@ -89,6 +89,10 @@
v_dict, v_key = hop.inputargs(r_dict, string_repr)
return hop.gendirectcall(ll_strdict_getitem, v_dict, v_key)
+ def rtype_delitem((r_dict, r_string), hop):
+ v_dict, v_key = hop.inputargs(r_dict, string_repr)
+ return hop.gendirectcall(ll_strdict_delitem, v_dict, v_key)
+
def rtype_setitem((r_dict, r_string), hop):
v_dict, v_key, v_value = hop.inputargs(r_dict, string_repr, r_dict.value_repr)
hop.gendirectcall(ll_strdict_setitem, v_dict, v_key, v_value)
@@ -134,8 +138,17 @@
entry = ll_strdict_lookup(d, key)
if not entry.key:
entry.key = key
+ d.num_used_entries += 1
entry.value = value
+def ll_strdict_delitem(d, key):
+ entry = ll_strdict_lookup(d, key)
+ if not entry.key or entry.key == deleted_entry_marker:
+ raise KeyError
+ entry.key = deleted_entry_marker
+ d.num_used_entries -= 1
+ # XXX: entry.value = ???
+
def ll_strdict_lookup(d, key):
keyhash = rstr.ll_strhash(key)
n = len(d.entries)
Modified: pypy/dist/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rdict.py (original)
+++ pypy/dist/pypy/rpython/test/test_rdict.py Thu Jun 23 17:32:32 2005
@@ -19,3 +19,23 @@
return d['hello'] * d['world']
res = interpret(func, [6])
assert res == 42
+
+def test_dict_getitem_keyerror():
+ def func(i):
+ d = {'hello' : i}
+ try:
+ return d['world']
+ except KeyError:
+ return 0
+ res = interpret(func, [6])
+ assert res == 0
+
+def test_dict_del_simple():
+ def func(i):
+ d = {'hello' : i}
+ d['world'] = i + 1
+ del d['hello']
+ return len(d)
+ res = interpret(func, [6])
+ assert res == 1
+
More information about the Pypy-commit
mailing list