[pypy-svn] r30120 - in pypy/dist/pypy/translator/cli: . src test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Jul 17 14:48:45 CEST 2006
Author: antocuni
Date: Mon Jul 17 14:48:38 2006
New Revision: 30120
Modified:
pypy/dist/pypy/translator/cli/cts.py
pypy/dist/pypy/translator/cli/src/pypylib.cs
pypy/dist/pypy/translator/cli/test/test_dict.py
Log:
Added support for iteration on dictionaries with void values.
Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py (original)
+++ pypy/dist/pypy/translator/cli/cts.py Mon Jul 17 14:48:38 2006
@@ -20,9 +20,10 @@
PYPY_LIST = '[pypylib]pypy.runtime.List`1<%s>'
PYPY_LIST_OF_VOID = '[pypylib]pypy.runtime.ListOfVoid'
PYPY_DICT = '[pypylib]pypy.runtime.Dict`2<%s, %s>'
-PYPY_DICT_OF_VOID = '[pypylib]pypy.runtime.DictOfVoid`1<%s>'
+PYPY_DICT_OF_VOID = '[pypylib]pypy.runtime.DictOfVoid`2<%s, int32>'
PYPY_DICT_VOID_VOID = '[pypylib]pypy.runtime.DictVoidVoid'
PYPY_DICT_ITEMS_ITERATOR = '[pypylib]pypy.runtime.DictItemsIterator`2<%s, %s>'
+PYPY_DICT_VOID_ITEMS_ITERATOR = '[pypylib]pypy.runtime.DictOfVoidItemsIterator`1<%s>'
PYPY_STRING_BUILDER = '[pypylib]pypy.runtime.StringBuilder'
_lltype_to_cts = {
@@ -117,8 +118,11 @@
elif isinstance(t, ootype.DictItemsIterator):
key_type = self.lltype_to_cts(t._KEYTYPE)
value_type = self.lltype_to_cts(t._VALUETYPE)
- if value_type == 'void' or key_type == 'void':
- assert False, 'iteration on dicts of voids is not supported, yet'
+ if key_type == 'void':
+ assert False, 'iteration on dicts with void keys is not supported, yet'
+ if value_type == 'void':
+ value_type = 'int32' # placeholder
+
return self.__class(PYPY_DICT_ITEMS_ITERATOR % (key_type, value_type), include_class)
return _get_from_dict(_lltype_to_cts, t, 'Unknown type %s' % t)
Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs Mon Jul 17 14:48:38 2006
@@ -360,22 +360,20 @@
}
}
- public class DictOfVoid<TKey>: System.Collections.Generic.Dictionary<TKey, int> // int is a placeholder
+ // it assumes TValue is a placeholder, it's not really used
+ public class DictOfVoid<TKey, TValue>: System.Collections.Generic.Dictionary<TKey, TValue>
{
public int ll_length() { return this.Count; }
public void ll_get(TKey key) { }
- public void ll_set(TKey key) { this[key] = 0; }
+ public void ll_set(TKey key) { this[key] = default(TValue); }
public bool ll_remove(TKey key) { return this.Remove(key); }
public bool ll_contains(TKey key) { return this.ContainsKey(key); }
public void ll_clear() { this.Clear(); }
- //XXX ll_get_items_iterator is not supported, yet
- /*
public DictItemsIterator<TKey, TValue> ll_get_items_iterator()
{
return new DictItemsIterator<TKey, TValue>(this.GetEnumerator());
}
- */
}
public class DictVoidVoid
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 Mon Jul 17 14:48:38 2006
@@ -13,6 +13,15 @@
res = self.interpret(f, [])
assert res == 2
+ def test_dict_of_void_iter(self):
+ def f():
+ d = {1: None, 2: None, 3: None}
+ total = 0
+ for k in d:
+ total += k
+ return total
+ assert self.interpret(f, []) == 6
+
def test_dict_of_dict(self):
py.test.skip("CLI doesn't support recursive dicts")
More information about the Pypy-commit
mailing list