[pypy-svn] r5987 - in pypy/trunk/src: goal pypy/annotation pypy/translator

arigo at codespeak.net arigo at codespeak.net
Mon Aug 16 16:03:30 CEST 2004


Author: arigo
Date: Mon Aug 16 16:03:29 2004
New Revision: 5987

Modified:
   pypy/trunk/src/goal/translate_pypy.py
   pypy/trunk/src/pypy/annotation/unaryop.py
   pypy/trunk/src/pypy/translator/annrpython.py
   pypy/trunk/src/pypy/translator/translator.py
Log:
Got rid of the increasingly confusing constargs hacks and just build one 
control flow graph per function, even for methods with constant im_self.

Instead, allow reading attributes from any constant object in the annotation
phase.



Modified: pypy/trunk/src/goal/translate_pypy.py
==============================================================================
--- pypy/trunk/src/goal/translate_pypy.py	(original)
+++ pypy/trunk/src/goal/translate_pypy.py	Mon Aug 16 16:03:29 2004
@@ -6,13 +6,12 @@
 from pypy.objspace.std.objspace import StdObjSpace, W_Object
 from pypy.objspace.std.intobject import W_IntObject
 from pypy.translator.translator import Translator
+from pypy.annotation import model as annmodel
 
 
 # __________  Entry point  __________
 
-space = StdObjSpace()
-
-def entry_point():
+def entry_point(space):
     w_a = W_IntObject(space, -6)
     w_b = W_IntObject(space, -7)
     return space.mul(w_a, w_b)
@@ -55,8 +54,9 @@
             display.run()
 
     t = Translator(entry_point, verbose=True, simplifying=True)
+    space = StdObjSpace()
     try:
-        a = t.annotate([])
+        a = t.annotate([annmodel.immutablevalue(space)])
         a.simplify()
     except:
         import traceback

Modified: pypy/trunk/src/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/unaryop.py	(original)
+++ pypy/trunk/src/pypy/annotation/unaryop.py	Mon Aug 16 16:03:29 2004
@@ -38,6 +38,9 @@
             analyser = getattr(obj.__class__, 'method_' + attr, None)
             if analyser is not None:
                 return SomeBuiltin(analyser, obj)
+            # if the SomeObject is itself a constant, allow reading its attrs
+            if obj.is_constant() and hasattr(obj.const, attr):
+                return immutablevalue(getattr(obj.const, attr))
         return SomeObject()
 
     def classattribute(obj, classdef):

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 16:03:29 2004
@@ -132,17 +132,13 @@
     #___ interface for annotator.factory _______
 
     def recursivecall(self, func, factory, *args):
+        # calls to methods: expand the argument
+        if hasattr(func, 'im_func'):
+            if func.im_self is not None:
+                s_self = annmodel.immutablevalue(func.im_self)
+                args = [s_self] + list(args)
+            func = func.im_func
         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

Modified: pypy/trunk/src/pypy/translator/translator.py
==============================================================================
--- pypy/trunk/src/pypy/translator/translator.py	(original)
+++ pypy/trunk/src/pypy/translator/translator.py	Mon Aug 16 16:03:29 2004
@@ -68,14 +68,8 @@
                     func.func_globals.get('__name__', '?'),
                     func.func_code.co_firstlineno,
                     func.__name__)
-            im_func = getattr(func, 'im_func', func)
-            im_self = getattr(func, 'im_self', None)
-            if im_self is not None:    # bound method?
-                constargs = {0: im_self}
-            else:
-                constargs = {}
             space = FlowObjSpace()
-            graph = space.build_flow(im_func, constargs)
+            graph = space.build_flow(func)
             if self.simplifying:
                 graph = simplify_graph(graph)
             self.flowgraphs[func] = graph



More information about the Pypy-commit mailing list