[pypy-svn] r5986 - pypy/trunk/src/pypy/translator

arigo at codespeak.net arigo at codespeak.net
Mon Aug 16 15:33:00 CEST 2004


Author: arigo
Date: Mon Aug 16 15:32:59 2004
New Revision: 5986

Modified:
   pypy/trunk/src/pypy/translator/annrpython.py
Log:
Detect unbound method calls with constant self, e.g. calls to a parent method 
from a space method.



Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py	(original)
+++ pypy/trunk/src/pypy/translator/annrpython.py	Mon Aug 16 15:32:59 2004
@@ -133,6 +133,16 @@
 
     def recursivecall(self, func, factory, *args):
         parent_fn, parent_block, parent_index = factory.position_key
+        # detect unbound methods with a constant first argument
+        # and turn them into bound methods
+        if (hasattr(func, 'im_self') and func.im_self is None and
+            len(args) > 0 and args[0].is_constant()):
+            try:
+                func = func.__get__(args[0].const, type(args[0].const))
+            except TypeError:
+                pass
+            else:
+                args = args[1:]
         graph = self.translator.getflowgraph(func, parent_fn,
                                              factory.position_key)
         # self.notify[graph.returnblock] is a dictionary of



More information about the Pypy-commit mailing list