[pypy-svn] r32993 - in pypy/dist/pypy/translator/cli: . src test

antocuni at codespeak.net antocuni at codespeak.net
Sat Oct 7 20:35:41 CEST 2006


Author: antocuni
Date: Sat Oct  7 20:35:39 2006
New Revision: 32993

Modified:
   pypy/dist/pypy/translator/cli/cts.py
   pypy/dist/pypy/translator/cli/src/pypylib.cs
   pypy/dist/pypy/translator/cli/test/test_objectmodel.py
Log:
Implement DictOfVoid::ll_copy.



Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py	(original)
+++ pypy/dist/pypy/translator/cli/cts.py	Sat Oct  7 20:35:39 2006
@@ -219,6 +219,7 @@
                 METH = oopspec.get_method(TYPE, name)                
             class_name = self.lltype_to_cts(TYPE)
             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 \
@@ -228,3 +229,11 @@
 
         else:
             assert False
+
+def dict_of_void_ll_copy_hack(TYPE, ret_type):
+    # XXX: ugly hack to make the ll_copy signature correct when
+    # CustomDict is special-cased to DictOfVoid.
+    if isinstance(TYPE, ootype.CustomDict) and TYPE._VALUETYPE is ootype.Void:
+        return ret_type.replace('Dict`2', 'DictOfVoid`2')
+    else:
+        return ret_type

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	Sat Oct  7 20:35:39 2006
@@ -417,6 +417,14 @@
     // it assumes TValue is a placeholder, it's not really used
     public class DictOfVoid<TKey, TValue>: System.Collections.Generic.Dictionary<TKey, TValue>
     {
+        IEqualityComparer<TKey> comparer = null;
+
+        public DictOfVoid() {}
+        public DictOfVoid(IEqualityComparer<TKey> comparer): base(comparer)
+        {
+            this.comparer = comparer;
+        }
+
         public int ll_length() { return this.Count; }
         public void ll_get(TKey key) { }
         public void ll_set(TKey key) { this[key] = default(TValue); }
@@ -428,6 +436,14 @@
         {
             return new DictItemsIterator<TKey, TValue>(this.GetEnumerator());
         }
+
+        public DictOfVoid<TKey, TValue> ll_copy() // XXX: why it should return a Dict?
+        {
+            DictOfVoid<TKey, TValue> res = new DictOfVoid<TKey, TValue>(comparer);
+            foreach(KeyValuePair<TKey, TValue> item in this)
+                res[item.Key] = item.Value;
+            return res;            
+        }
     }
 
     public class DictVoidVoid

Modified: pypy/dist/pypy/translator/cli/test/test_objectmodel.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_objectmodel.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_objectmodel.py	Sat Oct  7 20:35:39 2006
@@ -11,6 +11,16 @@
 class TestCliObjectModel(CliTest, BaseTestObjectModel):
     test_rtype_r_dict_bm = skip_r_dict
 
+    def test_rdict_of_void_copy(self):
+        from pypy.rpython.test.test_objectmodel import r_dict, strange_key_eq, strange_key_hash
+        def fn():
+            d = r_dict(strange_key_eq, strange_key_hash)
+            d['hello'] = None
+            d['world'] = None
+            d1 = d.copy()
+            return len(d1)
+        assert self.interpret(fn, []) == 2
+
     # this test is copied from TestLLtype in
     # rpython/test_objectmodel.py. It is not in TestOOtype because at
     # the moment llinterpret can't handle cast_*weakadr*


More information about the pypy-svn mailing list