[pypy-commit] pypy default: extract make_generator_entry_graph() from build_flow()

rlamy noreply at buildbot.pypy.org
Sun May 11 19:59:13 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r71466:2ef6be32a2ca
Date: 2014-05-11 18:58 +0100
http://bitbucket.org/pypy/pypy/changeset/2ef6be32a2ca/

Log:	extract make_generator_entry_graph() from build_flow()

diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py
--- a/rpython/flowspace/generator.py
+++ b/rpython/flowspace/generator.py
@@ -1,6 +1,8 @@
 """Flow graph building for generators"""
 
 from rpython.flowspace.argument import Signature
+from rpython.flowspace.bytecode import HostCode
+from rpython.flowspace.pygraph import PyGraph
 from rpython.flowspace.model import (Block, Link, Variable,
     Constant, checkgraph, const)
 from rpython.flowspace.operation import op
@@ -13,6 +15,16 @@
     _immutable_ = True
     _attrs_ = ()
 
+def make_generator_entry_graph(func):
+    code = HostCode._from_code(func.func_code)
+    graph = PyGraph(func, code)
+    block = graph.startblock
+    for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
+        if isinstance(w_value, Variable):
+            w_value.rename(name)
+    return bootstrap_generator(graph)
+
+
 def bootstrap_generator(graph):
     # This is the first copy of the graph.  We replace it with
     # a small bootstrap graph.
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -1,13 +1,13 @@
 """Implements the main interface for flow graph creation: build_flow().
 """
 
-from inspect import CO_NEWLOCALS
+from inspect import CO_NEWLOCALS, isgeneratorfunction
 
-from rpython.flowspace.model import Variable, checkgraph
+from rpython.flowspace.model import checkgraph
 from rpython.flowspace.bytecode import HostCode
 from rpython.flowspace.flowcontext import (FlowContext, fixeggblocks)
 from rpython.flowspace.generator import (tweak_generator_graph,
-        bootstrap_generator)
+        make_generator_entry_graph)
 from rpython.flowspace.pygraph import PyGraph
 
 
@@ -33,15 +33,10 @@
     Create the flow graph for the function.
     """
     _assert_rpythonic(func)
+    if (isgeneratorfunction(func) and
+            not hasattr(func, '_generator_next_method_of_')):
+        return make_generator_entry_graph(func)
     code = HostCode._from_code(func.func_code)
-    if (code.is_generator and
-            not hasattr(func, '_generator_next_method_of_')):
-        graph = PyGraph(func, code)
-        block = graph.startblock
-        for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
-            if isinstance(w_value, Variable):
-                w_value.rename(name)
-        return bootstrap_generator(graph)
     graph = PyGraph(func, code)
     ctx = FlowContext(graph, code)
     ctx.build_flow()


More information about the pypy-commit mailing list