[pypy-svn] rev 2215 - pypy/trunk/src/pypy/translator

sanxiyn at codespeak.net sanxiyn at codespeak.net
Tue Nov 18 05:26:14 CET 2003


Author: sanxiyn
Date: Tue Nov 18 05:26:13 2003
New Revision: 2215

Modified:
   pypy/trunk/src/pypy/translator/annrpython.py
   pypy/trunk/src/pypy/translator/gencl.py
   pypy/trunk/src/pypy/translator/genpyrex.py
   pypy/trunk/src/pypy/translator/transform.py
Log:
simplify_calls is dead!
long live transform.transform_simple_call!

annrpython: simplify_calls removed
transform: wrote transform_simple_call accordingly
gencl, genpyrex: removed call to annotator.simplify().

Currently snippet.powerset is broken in gencl. Will fix shortly.


Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py	(original)
+++ pypy/trunk/src/pypy/translator/annrpython.py	Tue Nov 18 05:26:13 2003
@@ -81,6 +81,10 @@
 
     #___ simplification (should be moved elsewhere?) _______
 
+    # it should be!
+    # now simplify_calls is moved to transform.py.
+    # i kept reverse_binding here for future(?) purposes though. --sanxiyn
+
     def reverse_binding(self, known_variables, cell):
         """This is a hack."""
         # In simplify_calls, when we are trying to create the new
@@ -99,39 +103,6 @@
             else:
                 raise CannotSimplify
 
-    def simplify_calls(self):
-        t = self.transaction()
-        for block in self.annotated:
-            known_variables = block.inputargs[:]
-            newops = []
-            for op in block.operations:
-                try:
-                    if op.opname == "call":
-                        func, varargs, kwargs = [self.binding(a)
-                                                 for a in op.args]
-                        c = t.get('len', [varargs])
-                        if not isinstance(c, XConstant):
-                            raise CannotSimplify
-                        length = c.value
-                        v = self.reverse_binding(known_variables, func)
-                        args = [v]
-                        for i in range(length):
-                            c = t.get('getitem', [varargs, self.constant(i)])
-                            if c is None:
-                                raise CannotSimplify
-                            v = self.reverse_binding(known_variables, c)
-                            args.append(v)
-                        op = SpaceOperation('simple_call', args, op.result)
-                        # XXX check that kwargs is empty
-                except CannotSimplify:
-                    pass
-                newops.append(op)
-                known_variables.append(op.result)
-            block.operations = newops
-
-    def simplify(self):
-        self.simplify_calls()
-
 
     #___ flowing annotations in blocks _____________________
 

Modified: pypy/trunk/src/pypy/translator/gencl.py
==============================================================================
--- pypy/trunk/src/pypy/translator/gencl.py	(original)
+++ pypy/trunk/src/pypy/translator/gencl.py	Tue Nov 18 05:26:13 2003
@@ -157,7 +157,6 @@
     def annotate(self, input_arg_types):
         ann = RPythonAnnotator()
         ann.build_types(self.fun, input_arg_types)
-        ann.simplify()
         self.setannotator(ann)
     def setannotator(self, annotator):
         self.ann = annotator

Modified: pypy/trunk/src/pypy/translator/genpyrex.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genpyrex.py	(original)
+++ pypy/trunk/src/pypy/translator/genpyrex.py	Tue Nov 18 05:26:13 2003
@@ -148,7 +148,6 @@
     def annotate(self, input_arg_types):
         a = RPythonAnnotator()
         a.build_types(self.functiongraph, input_arg_types)
-        a.simplify()
         self.setannotator(a)
 
     def setannotator(self, annotator):

Modified: pypy/trunk/src/pypy/translator/transform.py
==============================================================================
--- pypy/trunk/src/pypy/translator/transform.py	(original)
+++ pypy/trunk/src/pypy/translator/transform.py	Tue Nov 18 05:26:13 2003
@@ -59,7 +59,42 @@
                                          op2.result)
                 block.operations[i:i+2] = [new_op]
 
+# a(*b)
+# -->
+# c = newtuple(*b)
+# d = newdict()
+# e = call(function a, c, d)
+# -->
+# e = simple_call(a, *b)
+
+def transform_simple_call(self):
+    """Transforms a(*b) to simple_call(a, *b)"""
+    t = self.transaction()
+    for block in self.annotated:
+        operations = block.operations[:]
+        n_op = len(operations)
+        for i in range(0, n_op-2):
+            op1 = operations[i]
+            op2 = operations[i+1]
+            op3 = operations[i+2]
+            if not op3.args: continue
+            op3arg0type = t.get_type(self.binding(op3.args[0]))
+            if (op1.opname == 'newtuple' and
+                op2.opname == 'newdict' and
+                len(op2.args) == 0 and
+                op3.opname == 'call' and
+                op1.result is op3.args[1] and
+                op2.result is op3.args[2] and
+                # eek!
+                (op3arg0type is types.FunctionType or
+                 op3arg0type is types.BuiltinFunctionType)):
+                new_op = SpaceOperation('simple_call',
+                                        (op3.args[0],) + tuple(op1.args),
+                                        op3.result)
+                block.operations[i:i+3] = [new_op]
+
 def transform_graph(ann):
     """Apply set of transformations available."""
     transform_allocate(ann)
     transform_slice(ann)
+    transform_simple_call(ann)


More information about the Pypy-commit mailing list