[pypy-svn] r26145 - in pypy/dist/pypy/rpython: ootypesystem test

antocuni at codespeak.net antocuni at codespeak.net
Sat Apr 22 20:26:10 CEST 2006


Author: antocuni
Date: Sat Apr 22 20:26:00 2006
New Revision: 26145

Modified:
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/rdict.py
   pypy/dist/pypy/rpython/test/test_rdict.py
Log:
Added method keys() to rdict.



Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Sat Apr 22 20:26:00 2006
@@ -302,7 +302,7 @@
             "ll_set": Meth([self.KEYTYPE_T, self.VALUETYPE_T], Void),
             "ll_remove": Meth([self.KEYTYPE_T], Bool), # return False is key was not present
             "ll_contains": Meth([self.KEYTYPE_T], Bool),
-            #"ll_keys": Meth([], List(self.KEYTYPE_T)),
+            "ll_keys": Meth([], List(self.KEYTYPE_T)),
         })
 
         self._setup_methods(generic_types)
@@ -691,6 +691,12 @@
         assert typeOf(key) == self._TYPE._KEYTYPE
         return key in self._dict
 
+    def ll_keys(self):
+        # NOT_RPYTHON
+        keys = _list(List(self._TYPE._KEYTYPE))
+        keys._list = self._dict.keys()
+        return keys
+
 class _null_dict(_null_mixin(_dict), _dict):
 
     def __init__(self, DICT):

Modified: pypy/dist/pypy/rpython/ootypesystem/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rdict.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rdict.py	Sat Apr 22 20:26:00 2006
@@ -85,6 +85,10 @@
         v_res = hop.gendirectcall(ll_dict_setdefault, v_dict, v_key, v_default)
         return self.recast_value(hop.llops, v_res)
 
+    def rtype_method_keys(self, hop):
+        hop.exception_cannot_occur()        
+        return self.send_message(hop, 'll_keys')
+
 
 class __extend__(pairtype(DictRepr, rmodel.Repr)): 
 

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	Sat Apr 22 20:26:00 2006
@@ -726,6 +726,9 @@
 class TestOotypeRtyping(BaseTestDictRtyping):
     ts = "ootype"
 
+    def ll_to_list(self, l):
+        return l._list[:]
+
     # these tests are similar to those above, but they don't use strings
     def test_dict_creation(self):
         def createdict(i):
@@ -789,4 +792,10 @@
             d.setdefault(x, y)
             return d[x]
         assert self.interpret(func, [42, 13]) == 13
-    
+
+    def test_keys(self):
+        def func(x, y):
+            d = {x: x+1, y: y+1}
+            return d.keys()
+        res = self.ll_to_list(self.interpret(func, [42, 13]))
+        assert res == [42, 13] or res == [13, 42]



More information about the Pypy-commit mailing list