[pypy-svn] r26609 - in pypy/dist/pypy/translator/cl: . test

sanxiyn at codespeak.net sanxiyn at codespeak.net
Sun Apr 30 17:58:34 CEST 2006


Author: sanxiyn
Date: Sun Apr 30 17:58:28 2006
New Revision: 26609

Modified:
   pypy/dist/pypy/translator/cl/opformatter.py
   pypy/dist/pypy/translator/cl/test/test_dict.py
Log:
Beginning of Dict implementation in Lisp backend


Modified: pypy/dist/pypy/translator/cl/opformatter.py
==============================================================================
--- pypy/dist/pypy/translator/cl/opformatter.py	(original)
+++ pypy/dist/pypy/translator/cl/opformatter.py	Sun Apr 30 17:58:28 2006
@@ -1,4 +1,4 @@
-from pypy.rpython.ootypesystem.ootype import List, Record, Instance
+from pypy.rpython.ootypesystem.ootype import List, Dict, Record, Instance
 from pypy.translator.cl.clrepr import clrepr
 
 class OpFormatter:
@@ -71,6 +71,8 @@
         cls = self.args[0].value
         if isinstance(cls, List):
             yield "(setf %s (make-array 0 :adjustable t))" % (result,)
+        elif isinstance(cls, Dict):
+            yield "(setf %s (make-hash-table))" % (result,)
         elif isinstance(cls, Record):
             clsname = self.gen.declare_struct(cls)
             yield "(setf %s (make-%s))" % (result, clsname)
@@ -101,6 +103,10 @@
             impl = ListImpl(selfvar)
             code = getattr(impl, method)(*args)
             yield "(setf %s %s)" % (result, code)
+        elif isinstance(cls, Dict):
+            impl = DictImpl(selfvar)
+            code = getattr(impl, method)(*args)
+            yield "(setf %s %s)" % (result, code)
         elif isinstance(cls, Instance):
             name = clrepr(method, symbol=True)
             funcall = " ".join((name, selfvar) + args)
@@ -154,3 +160,14 @@
 
     def _ll_resize(self, size):
         return "(adjust-array %s %s)" % (self.obj, size)
+
+class DictImpl:
+
+    def __init__(self, obj):
+        self.obj = obj
+
+    def ll_length(self):
+        return "(hash-table-count %s)" % (self.obj,)
+
+    def ll_set(self, key, value):
+        return "(setf (gethash %s %s) %s)" % (key, self.obj, value)

Modified: pypy/dist/pypy/translator/cl/test/test_dict.py
==============================================================================
--- pypy/dist/pypy/translator/cl/test/test_dict.py	(original)
+++ pypy/dist/pypy/translator/cl/test/test_dict.py	Sun Apr 30 17:58:28 2006
@@ -1,6 +1,6 @@
 from pypy.translator.cl.buildcl import make_cl_func
 
-def notest_dict_length():
+def test_dict_length():
     def dict_length_one(key, val):
         dic = {key:val}
         return len(dic)



More information about the Pypy-commit mailing list