[pypy-svn] r26250 - in pypy/dist/pypy/translator/cl: . test
sanxiyn at codespeak.net
sanxiyn at codespeak.net
Mon Apr 24 11:52:40 CEST 2006
Author: sanxiyn
Date: Mon Apr 24 11:52:35 2006
New Revision: 26250
Added:
pypy/dist/pypy/translator/cl/test/test_cltrans_multi.py
Modified:
pypy/dist/pypy/translator/cl/clrepr.py
pypy/dist/pypy/translator/cl/gencl.py
Log:
(nik, sanxiyn)
Implement direct_call and multiple function graphs
Modified: pypy/dist/pypy/translator/cl/clrepr.py
==============================================================================
--- pypy/dist/pypy/translator/cl/clrepr.py (original)
+++ pypy/dist/pypy/translator/cl/clrepr.py Mon Apr 24 11:52:35 2006
@@ -1,4 +1,5 @@
from pypy.objspace.flow.model import Constant, Variable, last_exception
+from pypy.rpython.ootypesystem.ootype import _static_meth
def repr_unknown(obj):
return '#<%r>' % (obj,)
@@ -7,6 +8,8 @@
return var.name
def repr_const(val):
+ if isinstance(val, _static_meth):
+ return val._name # XXX make sure function names are unique
if isinstance(val, tuple):
val = map(repr_const, val)
return "'(%s)" % ' '.join(val)
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 11:52:35 2006
@@ -59,6 +59,12 @@
def op_int_is_true(self, result, arg):
yield "(setf %s (not (zerop %s)))" % (result, arg)
+ def op_direct_call(self, result, fun, *args):
+ graph = self.args[0].value.graph
+ self.gen.pendinggraphs.append(graph)
+ args = " ".join(args)
+ yield "(setf %s (%s %s))" % (result, fun, args)
+
def declare_class(self, cls):
# cls is really type of Instance
name = cls._name
@@ -122,11 +128,8 @@
class GenCL:
- def __init__(self, fun, input_arg_types=[]):
- # NB. 'fun' is a graph!
- simplify_graph(fun)
- self.fun = fun
- self.blockref = {}
+ def __init__(self, entry_point, input_arg_types=[]):
+ self.pendinggraphs = [entry_point]
self.declarations = []
def annotate(self, input_arg_types):
@@ -148,8 +151,10 @@
return declarations + "\n" + code
def emit(self):
- for line in self.emit_defun(self.fun):
- yield line
+ while self.pendinggraphs:
+ graph = self.pendinggraphs.pop()
+ for line in self.emit_defun(graph):
+ yield line
def emit_defun(self, fun):
yield ";;;; Main"
@@ -162,6 +167,7 @@
yield "(prog"
blocklist = list(fun.iterblocks())
vardict = {}
+ self.blockref = {}
for block in blocklist:
tag = len(self.blockref)
self.blockref[block] = tag
Added: pypy/dist/pypy/translator/cl/test/test_cltrans_multi.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/cl/test/test_cltrans_multi.py Mon Apr 24 11:52:35 2006
@@ -0,0 +1,10 @@
+from pypy.translator.cl.buildcl import make_cl_func
+
+def test_call():
+ def add_one(n):
+ n = add_one_really(n)
+ return n
+ def add_one_really(n):
+ return n + 1
+ cl_add_one = make_cl_func(add_one, [int])
+ assert cl_add_one(1) == 2
More information about the Pypy-commit
mailing list