[pypy-svn] r39847 - in pypy/dist/pypy: rpython/test translator/cli translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Sun Mar 4 10:12:01 CET 2007
Author: antocuni
Date: Sun Mar 4 10:11:59 2007
New Revision: 39847
Modified:
pypy/dist/pypy/rpython/test/test_remptydict.py
pypy/dist/pypy/translator/cli/cts.py
pypy/dist/pypy/translator/cli/test/test_dict.py
Log:
Make dict of voids working better
Modified: pypy/dist/pypy/rpython/test/test_remptydict.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_remptydict.py (original)
+++ pypy/dist/pypy/rpython/test/test_remptydict.py Sun Mar 4 10:11:59 2007
@@ -31,4 +31,11 @@
pass
class TestOOtype(BaseTestRemptydict, OORtypeMixin):
- pass
+ def test_almost_empty_dict(self):
+ def f(flag):
+ d = {}
+ if flag:
+ d[None] = None
+ return None in d
+ assert self.interpret(f, [True]) is True
+ assert self.interpret(f, [False]) is False
Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py (original)
+++ pypy/dist/pypy/translator/cli/cts.py Sun Mar 4 10:11:59 2007
@@ -244,15 +244,22 @@
if isinstance(TYPE, ootype.StaticMethod):
METH = TYPE
else:
- METH = oopspec.get_method(TYPE, name)
+ METH = oopspec.get_method(TYPE, name)
class_name = self.lltype_to_cts(TYPE)
- if isinstance(TYPE, ootype.Dict) and TYPE._KEYTYPE is ootype.Void and \
- TYPE._VALUETYPE is ootype.Void and name_or_desc == 'll_get_items_iterator':
- # ugly, ugly special case
- ret_type = 'class ' + PYPY_DICT_ITEMS_ITERATOR % ('int32', 'int32')
+ if isinstance(TYPE, ootype.Dict):
+ KEY = TYPE._KEYTYPE
+ VALUE = TYPE._VALUETYPE
+ name = name_or_desc
+ if KEY is ootype.Void and VALUE is ootype.Void and name == 'll_get_items_iterator':
+ # ugly, ugly special case
+ ret_type = 'class ' + PYPY_DICT_ITEMS_ITERATOR % ('int32', 'int32')
+ elif VALUE is ootype.Void and METH.RESULT is ootype.Dict.VALUETYPE_T:
+ ret_type = 'void'
+ else:
+ ret_type = self.lltype_to_cts(METH.RESULT)
+ ret_type = dict_of_void_ll_copy_hack(TYPE, ret_type)
else:
ret_type = self.lltype_to_cts(METH.RESULT)
- ret_type = dict_of_void_ll_copy_hack(TYPE, ret_type)
generic_types = getattr(TYPE, '_generic_types', {})
arg_types = [self.lltype_to_cts(arg) for arg in METH.ARGS if
arg is not ootype.Void and \
Modified: pypy/dist/pypy/translator/cli/test/test_dict.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dict.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_dict.py Sun Mar 4 10:11:59 2007
@@ -9,6 +9,13 @@
def test_recursive(self):
py.test.skip("CLI doesn't support recursive dicts")
+ def test_dict_of_void_special_case(self):
+ def fn(n):
+ d = {}
+ for i in xrange(n):
+ d[i] = None
+ return d[0]
+ assert self.interpret(fn, [2]) is None
class TestCliEmptyDict(CliTest, oodict.BaseTestEmptyDict):
pass
More information about the pypy-svn
mailing list