Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: 
Changeset: r71467:67067c56ae1a
Date: 2014-05-11 22:01 +0100
http://bitbucket.org/pypy/pypy/changeset/67067c56ae1a/

Log:    inline bootstrap_generator()

diff --git a/rpython/flowspace/generator.py b/rpython/flowspace/generator.py
--- a/rpython/flowspace/generator.py
+++ b/rpython/flowspace/generator.py
@@ -16,19 +16,16 @@
     _attrs_ = ()
 
 def make_generator_entry_graph(func):
+    # This is the first copy of the graph.  We replace it with
+    # a small bootstrap graph.
     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.
-    GeneratorIterator = make_generatoriterator_class(graph)
+    varnames = get_variable_names(graph.startblock.inputargs)
+    GeneratorIterator = make_generatoriterator_class(varnames)
     replace_graph_with_bootstrap(GeneratorIterator, graph)
     # We attach a 'next' method to the GeneratorIterator class
     # that will invoke the real function, based on a second
@@ -42,11 +39,11 @@
     tweak_generator_body_graph(GeneratorIterator.Entry, graph)
 
 
-def make_generatoriterator_class(graph):
+def make_generatoriterator_class(var_names):
     class GeneratorIterator(object):
         class Entry(AbstractPosition):
             _immutable_ = True
-            varnames = get_variable_names(graph.startblock.inputargs)
+            varnames = var_names
 
         def __init__(self, entry):
             self.current = entry
@@ -84,7 +81,7 @@
         self.current = next_entry
         return return_value
     GeneratorIterator.next = next
-    return func   # for debugging
+    graph._tweaked_func = func  # for testing
 
 def get_variable_names(variables):
     seen = set()
diff --git a/rpython/flowspace/test/test_generator.py 
b/rpython/flowspace/test/test_generator.py
--- a/rpython/flowspace/test/test_generator.py
+++ b/rpython/flowspace/test/test_generator.py
@@ -1,8 +1,8 @@
 from rpython.conftest import option
 from rpython.flowspace.objspace import build_flow
 from rpython.flowspace.model import Variable
-from rpython.flowspace.generator import (make_generatoriterator_class,
-        replace_graph_with_bootstrap, get_variable_names, attach_next_method)
+from rpython.flowspace.generator import (
+    make_generator_entry_graph, get_variable_names)
 from rpython.translator.simplify import join_blocks
 
 
@@ -93,14 +93,11 @@
             yield n + 1
             z -= 10
         #
-        graph = build_flow(f)
-        GeneratorIterator = make_generatoriterator_class(graph)
-        replace_graph_with_bootstrap(GeneratorIterator, graph)
-        func1 = attach_next_method(GeneratorIterator, graph)
+        graph = make_generator_entry_graph(f)
+        func1 = graph._tweaked_func
         if option.view:
             graph.show()
-        #
-        assert func1._generator_next_method_of_ is GeneratorIterator
+        GeneratorIterator = graph._tweaked_func._generator_next_method_of_
         assert hasattr(GeneratorIterator, 'next')
         #
         graph_next = build_flow(GeneratorIterator.next.im_func)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to