[pypy-commit] pypy translation-cleanup: Move more code from FlowEC to FlowSpaceFrame

rlamy noreply at buildbot.pypy.org
Thu Aug 30 18:38:05 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56986:bd47cd975b2f
Date: 2012-08-09 21:31 +0100
http://bitbucket.org/pypy/pypy/changeset/bd47cd975b2f/

Log:	Move more code from FlowEC to FlowSpaceFrame

	* .is_generator moved to the frame
	* _init_graph() moved to the frame, along with supporting code also
	dealing with graph initialisation.

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -163,22 +163,6 @@
 
 class FlowExecutionContext(ExecutionContext):
 
-    def _init_graph(self, func, initialblock):
-        # CallableFactory.pycall may add class_ to functions that are methods
-        name = func.func_name
-        class_ = getattr(func, 'class_', None)
-        if class_ is not None:
-            name = '%s.%s' % (class_.__name__, name)
-        for c in "<>&!":
-            name = name.replace(c, '_')
-        self.graph = graph = FunctionGraph(name, initialblock)
-        graph.func = func
-        # attach a signature and defaults to the graph
-        # so that it becomes even more interchangeable with the function
-        # itself
-        graph.signature = self.code.signature()
-        graph.defaults = func.func_defaults or ()
-
     make_link = Link # overridable for transition tracking
 
     def bytecode_trace(self, frame):
@@ -210,20 +194,15 @@
     def build_flow(self, func, constargs={}):
         space = self.space
         code = PyCode._from_code(space, func.func_code)
-        self.is_generator = bool(code.co_flags & CO_GENERATOR)
         self.code = code
 
         self.crnt_offset = -1
         self.frame = frame = FlowSpaceFrame(self.space, code,
                                func, constargs)
         self.joinpoints = {}
-        initialblock = SpamBlock(frame.getstate())
-        self.pendingblocks = collections.deque([initialblock])
-        self._init_graph(func, initialblock)
+        self.graph = frame._init_graph(func)
+        self.pendingblocks = collections.deque([self.graph.startblock])
 
-        if self.is_generator:
-            initialblock.operations.append(
-                SpaceOperation('generator_mark', [], Variable()))
 
         while self.pendingblocks:
             block = self.pendingblocks.popleft()
@@ -284,7 +263,7 @@
         self.fixeggblocks()
 
     def generate_yield(self, frame, w_result):
-        assert self.is_generator
+        assert frame.is_generator
         self.recorder.crnt_block.operations.append(
             SpaceOperation('yield', [w_result], Variable()))
         # we must push a dummy value that will be POPped: it's the .send()
@@ -384,6 +363,7 @@
 class FlowSpaceFrame(pyframe.CPythonFrame):
 
     def __init__(self, space, code, func, constargs=None):
+        self.is_generator = bool(code.co_flags & CO_GENERATOR)
         w_globals = Constant(func.func_globals)
         class outerfunc: pass # hack
         if func.func_closure is not None:
@@ -402,6 +382,29 @@
             arg_list[position] = Constant(value)
         self.setfastscope(arg_list)
 
+    def _init_graph(self, func):
+        # CallableFactory.pycall may add class_ to functions that are methods
+        name = func.func_name
+        class_ = getattr(func, 'class_', None)
+        if class_ is not None:
+            name = '%s.%s' % (class_.__name__, name)
+        for c in "<>&!":
+            name = name.replace(c, '_')
+
+        initialblock = SpamBlock(self.getstate())
+        if self.is_generator:
+            initialblock.operations.append(
+                SpaceOperation('generator_mark', [], Variable()))
+        graph = FunctionGraph(name, initialblock)
+        graph.func = func
+        # attach a signature and defaults to the graph
+        # so that it becomes even more interchangeable with the function
+        # itself
+        graph.signature = self.pycode.signature()
+        graph.defaults = func.func_defaults or ()
+        graph.is_generator = self.is_generator
+        return graph
+
     def getstate(self):
         # getfastscope() can return real None, for undefined locals
         data = self.save_locals_stack()
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -270,7 +270,7 @@
 
         graph = ec.graph
         checkgraph(graph)
-        if ec.is_generator and tweak_for_generator:
+        if graph.is_generator and tweak_for_generator:
             from pypy.translator.generator import tweak_generator_graph
             tweak_generator_graph(graph)
         return graph


More information about the pypy-commit mailing list