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

sanxiyn at codespeak.net sanxiyn at codespeak.net
Mon Apr 24 08:58:58 CEST 2006


Author: sanxiyn
Date: Mon Apr 24 08:58:54 2006
New Revision: 26229

Modified:
   pypy/dist/pypy/translator/cl/gencl.py
   pypy/dist/pypy/translator/cl/test/test_cltrans_oo.py
Log:
(sanxiyn, nik, yusei)
Start of list implementation in Common Lisp backend, but tests don't run yet.


Modified: pypy/dist/pypy/translator/cl/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/cl/gencl.py	(original)
+++ pypy/dist/pypy/translator/cl/gencl.py	Mon Apr 24 08:58:54 2006
@@ -1,9 +1,10 @@
-from pypy.objspace.flow.model import Constant, Variable, last_exception
+from pypy.objspace.flow.model import Constant
 from pypy.annotation.annrpython import RPythonAnnotator
 
 from pypy.translator.simplify import simplify_graph
 from pypy.translator.transform import transform_graph, default_extra_passes, transform_slice
 
+from pypy.rpython.ootypesystem.ootype import Instance, List
 from pypy.translator.cl.clrepr import repr_arg, repr_var, repr_const
 
 
@@ -116,10 +117,28 @@
 
     def op_new(self):
         cls = self.args[0].value
+        if isinstance(cls, List):
+            self.op_new_list(cls)
+        else:
+            self.op_new_instance(cls)
+
+    def op_new_list(self, cls):
+        target = self.str(self.result)
+        print "(setq %s (make-array 0 :adjustable t))" % (target,)
+
+    def op_new_instance(self, cls):
         print self.declare_class(cls)
         target = self.str(self.result)
         print "(setq %s (make-%s))" % (target, cls._name)
 
+    def op_oosend(self):
+        method = self.args[0].value
+        receiver = self.args[1]
+        args = self.args[2:]
+        if isinstance(receiver.concretetype, List):
+            impl = ListImpl(receiver)
+            getattr(impl, method)(*args)
+
     def op_oogetfield(self):
         target = self.str(self.result)
         clsname = self.args[0].concretetype._name
@@ -211,6 +230,27 @@
         print ")"
 
 
+class ListImpl:
+
+    def __init__(self, receiver):
+        self.obj = repr_arg(receiver)
+
+    def ll_length(self):
+        pass
+
+    def ll_getitem_fast(self, index):
+        pass
+
+    def ll_setitem_fast(self, index, value):
+        index = repr_arg(index)
+        value = repr_arg(value)
+        return "(setf (aref %s %s) %s)" % (self.obj, index, value)
+
+    def _ll_resize(self, size):
+        size = repr_arg(size)
+        return "(adjust-array %s %s)" % (self.obj, size)
+
+
 class GenCL:
 
     def __init__(self, fun, input_arg_types=[]):

Modified: pypy/dist/pypy/translator/cl/test/test_cltrans_oo.py
==============================================================================
--- pypy/dist/pypy/translator/cl/test/test_cltrans_oo.py	(original)
+++ pypy/dist/pypy/translator/cl/test/test_cltrans_oo.py	Mon Apr 24 08:58:54 2006
@@ -9,3 +9,17 @@
         return obj.answer
     cl_new_get_set = make_cl_func(new_get_set)
     assert cl_new_get_set() == 42
+
+def dont_test_list_length():
+    def list_length_one(number):
+        lst = [number]
+        return len(lst)
+    cl_list_length_one = make_cl_func(list_length_one, [int])
+    assert cl_list_length_one(0) == 1
+
+def dont_test_list_get():
+    def list_and_get(number):
+        lst = [number]
+        return lst[0]
+    cl_list_and_get = make_cl_func(list_and_get, [int])
+    assert cl_list_and_get(1985) == 1985



More information about the Pypy-commit mailing list