[pypy-svn] r26415 - pypy/dist/pypy/rpython/ootypesystem

nik at codespeak.net nik at codespeak.net
Thu Apr 27 10:12:10 CEST 2006


Author: nik
Date: Thu Apr 27 10:12:07 2006
New Revision: 26415

Modified:
   pypy/dist/pypy/rpython/ootypesystem/rdict.py
Log:
add a convert_const to ootype DictRepr. this fixes the test failures in
test_rtuple that have existed for a few days. but this convert_const
implementation is not complete, it ignores r_dict (see the lltype
DictRepr.convert_const) which i still don't completely understand even
after a lecture about it by Samuele. ;)


Modified: pypy/dist/pypy/rpython/ootypesystem/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rdict.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rdict.py	Thu Apr 27 10:12:07 2006
@@ -135,6 +135,28 @@
         hop.exception_cannot_occur()
         return self.send_message(hop, 'll_clear')
 
+    def convert_const(self, dictobj):
+        if dictobj is None:
+            return lltype.nullptr(self.DICT)
+        if not isinstance(dictobj, dict):
+            raise TyperError("expected a dict: %r" % (dictobj,))
+        try:
+            key = Constant(dictobj)
+            return self.dict_cache[key]
+        except KeyError:
+            self.setup()
+            l_dict = ll_newdict(self.DICT)
+            self.dict_cache[key] = l_dict 
+            r_key = self.key_repr
+            r_value = self.value_repr
+
+            # XXX need handling of r_dict here
+            for dictkey, dictvalue in dictobj.items():
+                llkey = r_key.convert_const(dictkey)
+                llvalue = r_value.convert_const(dictvalue)
+                l_dict.ll_set(llkey, llvalue)
+            return l_dict
+
 class __extend__(pairtype(DictRepr, rmodel.Repr)): 
 
     def rtype_getitem((r_dict, r_key), hop):



More information about the Pypy-commit mailing list