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

sanxiyn at codespeak.net sanxiyn at codespeak.net
Tue May 2 07:32:32 CEST 2006


Author: sanxiyn
Date: Tue May  2 07:32:19 2006
New Revision: 26643

Modified:
   pypy/dist/pypy/translator/cl/clrepr.py
   pypy/dist/pypy/translator/cl/gencl.py
   pypy/dist/pypy/translator/cl/opformatter.py
   pypy/dist/pypy/translator/cl/test/test_call.py
Log:
Implement op_indirect_call


Modified: pypy/dist/pypy/translator/cl/clrepr.py
==============================================================================
--- pypy/dist/pypy/translator/cl/clrepr.py	(original)
+++ pypy/dist/pypy/translator/cl/clrepr.py	Tue May  2 07:32:19 2006
@@ -107,7 +107,7 @@
     return "'" + repr_class(item)
 
 def repr_static_method(item):
-    return clrepr(item.value._name, symbol=True)
+    return "'" + clrepr(item.value._name, symbol=True)
 
 dispatch = {
         Class: repr_class,

Modified: pypy/dist/pypy/translator/cl/gencl.py
==============================================================================
--- pypy/dist/pypy/translator/cl/gencl.py	(original)
+++ pypy/dist/pypy/translator/cl/gencl.py	Tue May  2 07:32:19 2006
@@ -1,7 +1,7 @@
 import types
 
 from pypy.tool.udir import udir
-from pypy.objspace.flow.model import Constant, c_last_exception
+from pypy.objspace.flow.model import Constant, c_last_exception, FunctionGraph
 from pypy.translator.translator import graphof
 from pypy.rpython.ootypesystem.ootype import dynamicType, oodowncast, Record, Instance, _class, _static_meth, _meth, ROOT
 from pypy.rpython.ootypesystem.rclass import OBJECT
@@ -163,6 +163,10 @@
                 name = obj._method_name # XXX
                 for line in self.emit_defmethod(graph, name):
                     yield line
+            elif isinstance(obj, FunctionGraph):
+                graph = obj
+                for line in self.emit_defun(graph):
+                    yield line
 
     def emit_defun(self, fun):
         yield "(defun " + clrepr(fun.name, symbol=True)

Modified: pypy/dist/pypy/translator/cl/opformatter.py
==============================================================================
--- pypy/dist/pypy/translator/cl/opformatter.py	(original)
+++ pypy/dist/pypy/translator/cl/opformatter.py	Tue May  2 07:32:19 2006
@@ -61,12 +61,20 @@
         yield "(setf %s (not (zerop %s)))" % (clrepr(result, True),
                                               clrepr(arg, True))
 
-    def op_direct_call(self, result, fun, *args):
+    def op_direct_call(self, result, _, *args):
         funobj = self.args[0].value
         self.gen.pendinggraphs.append(funobj)
+        fun = clrepr(funobj._name, symbol=True)
         funcall = " ".join((fun,) + args)
         yield "(setf %s (%s))" % (result, funcall)
 
+    def op_indirect_call(self, result, fun, *args):
+        graphs = self.args[-1].value
+        self.gen.pendinggraphs.extend(graphs)
+        args = args[:-1]
+        funcall = " ".join((fun,) + args)
+        yield "(setf %s (funcall %s))" % (result, funcall)
+
     def op_new(self, result, _):
         cls = self.args[0].value
         if isinstance(cls, List):

Modified: pypy/dist/pypy/translator/cl/test/test_call.py
==============================================================================
--- pypy/dist/pypy/translator/cl/test/test_call.py	(original)
+++ pypy/dist/pypy/translator/cl/test/test_call.py	Tue May  2 07:32:19 2006
@@ -9,3 +9,20 @@
         return n + 1
     cl_add_one = make_cl_func(add_one, [int])
     assert cl_add_one(1) == 2
+
+def test_indirect_call():
+    def add_one(n):
+        return n + 1
+    def add_two(n):
+        return n + 2
+    def pick_function(flag):
+        if flag:
+            return add_one
+        else:
+            return add_two
+    def add_one_or_two(n, flag):
+        function = pick_function(flag)
+        return function(n)
+    cl_add_one_or_two = make_cl_func(add_one_or_two, [int, bool])
+    assert cl_add_one_or_two(8, True) == 9
+    assert cl_add_one_or_two(7, False) == 9



More information about the Pypy-commit mailing list