[pypy-svn] r55153 - in pypy/branch/oo-jit/pypy/translator: cli cli/src cli/test oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Fri May 23 19:08:48 CEST 2008
Author: antocuni
Date: Fri May 23 19:08:46 2008
New Revision: 55153
Modified:
pypy/branch/oo-jit/pypy/translator/cli/cts.py
pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs
pypy/branch/oo-jit/pypy/translator/cli/test/test_dict.py
pypy/branch/oo-jit/pypy/translator/oosupport/constant.py
Log:
implement dict with void key for gencli; this allows
jit/codegen/cli/test_gencli_portal/test_main_as_portal to pass, but it
seems that such dicts are not really supported by rpython, as you can
see by uncommeting the test in test_dict or moving the tests to
rpython/test/test_rdict :-(
Modified: pypy/branch/oo-jit/pypy/translator/cli/cts.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/cts.py (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/cts.py Fri May 23 19:08:46 2008
@@ -129,6 +129,7 @@
WEAKREF = types.weakref.classname()
PYPY_DICT_OF_VOID = '[pypylib]pypy.runtime.DictOfVoid`2<%s, int32>'
+PYPY_DICT_OF_VOID_KEY = '[pypylib]pypy.runtime.DictOfVoidKey`2<int32, %s>'
_lltype_to_cts = {
@@ -277,6 +278,9 @@
else:
# XXX
return CliClassType(None, PYPY_DICT_OF_VOID % key_type)
+ elif key_type == types.void:
+ assert value_type != types.void
+ return CliClassType(None, PYPY_DICT_OF_VOID_KEY % value_type)
return types.dict.specialize(key_type, value_type)
elif isinstance(t, ootype.DictItemsIterator):
key_type = self.lltype_to_cts(t._KEYTYPE)
Modified: pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/src/pypylib.cs Fri May 23 19:08:46 2008
@@ -593,6 +593,43 @@
}
}
+ // it assumes TKey is a placeholder, it's not really used
+ public class DictOfVoidKey<TKey, TValue>
+ {
+ private int length = 0;
+ private TValue elem = default(TValue);
+
+ public DictOfVoidKey() {}
+
+ public int ll_length() { return this.length; }
+ public TValue ll_get() { return this.elem; }
+
+ public void ll_set(TValue value) {
+ this.length = 1;
+ this.elem = value;
+ }
+
+ public bool ll_remove() {
+ if (this.length > 0) {
+ this.length = 0;
+ return true;
+ }
+ return false;
+ }
+
+ public bool ll_contains() { return (this.length > 0); }
+ public void ll_contains_get() { }
+ public void ll_clear() { this.length = 0; }
+
+ public DictItemsIterator<TKey, TValue> ll_get_items_iterator()
+ {
+ List<KeyValuePair<TKey, TValue>> foo = new List<KeyValuePair<TKey, TValue>>();
+ if (length == 1)
+ foo.Add(new KeyValuePair<TKey, TValue>(default(TKey), this.elem));
+ return new DictItemsIterator<TKey, TValue>(foo.GetEnumerator());
+ }
+ }
+
public class DictVoidVoid
{
private int length = 0;
Modified: pypy/branch/oo-jit/pypy/translator/cli/test/test_dict.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/test/test_dict.py (original)
+++ pypy/branch/oo-jit/pypy/translator/cli/test/test_dict.py Fri May 23 19:08:46 2008
@@ -17,6 +17,26 @@
return d[0]
assert self.interpret(fn, [2]) is None
+ def test_dict_with_void_key(self):
+ def fn(flag):
+ d = {}
+ if flag:
+ d[None] = flag
+ return bool(d)
+ res = self.interpret(fn, [42])
+ assert res is True
+
+## XXX: it fails because of a bug in the annotator, which thinks the
+## last line always raises
+## def test_dict_with_void_key_pbc(self):
+## d = {}
+## def fn(flag):
+## if flag:
+## d[None] = flag
+## return d[None]
+## res = self.interpret(fn, [42], backendopt=False)
+## assert res == 42
+
class TestCliEmptyDict(CliTest, oodict.BaseTestEmptyDict):
pass
Modified: pypy/branch/oo-jit/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/oosupport/constant.py (original)
+++ pypy/branch/oo-jit/pypy/translator/oosupport/constant.py Fri May 23 19:08:46 2008
@@ -709,8 +709,7 @@
gen.add_comment('Initializing dictionary constant')
- if KEYTYPE is ootype.Void:
- assert VALUETYPE is ootype.Void
+ if KEYTYPE is ootype.Void and VALUETYPE is ootype.Void:
return
for key, value in self.value._dict.iteritems():
More information about the Pypy-commit
mailing list