Armin Rigo avatar Armin Rigo committed c5bd904

in-progress

Comments (0)

Files changed (3)

pypy/objspace/flow/flowcontext.py

 
     def build_flow(self):
         if self.is_generator:
-            self.produce_generator_entry()
+            self.produce_generator_mark()
         while self.pendingblocks:
             block = self.pendingblocks.popleft()
             frame = self.create_frame()
             del self.recorder
         self.fixeggblocks()
 
-    def produce_generator_entry(self):
+    def produce_generator_mark(self):
         [initialblock] = self.pendingblocks
         initialblock.operations.append(
-            SpaceOperation('generator_entry', list(initialblock.inputargs),
-                           Variable()))
+            SpaceOperation('generator_mark', [], Variable()))
 
     def generate_yield(self, frame, w_result):
         assert self.is_generator

pypy/objspace/flow/test/test_generator.py

                 i += 1
         graph = self.codetest(f)
         ops = self.all_operations(graph)
-        assert ops == {'generator_entry': 1,
+        assert ops == {'generator_mark': 1,
                        'lt': 1, 'is_true': 1,
                        'yield': 2,
                        'inplace_add': 1}

pypy/translator/test/test_generator.py

+from pypy.conftest import option
 from pypy.objspace.flow.objspace import FlowObjSpace
+from pypy.objspace.flow.model import Variable
 from pypy.translator.translator import TranslationContext
 from pypy.translator.generator import replace_graph_with_bootstrap
+from pypy.translator.generator import get_variable_names
 
 
 # ____________________________________________________________
 def test_explicit():
     assert list(f_gen(10)) == list(f_explicit(10))
 
+def test_get_variable_names():
+    lst = get_variable_names([Variable('a'), Variable('b_'), Variable('a')])
+    assert lst == ['g_a', 'g_b', 'g_a_']
+
 # ____________________________________________________________
 
 
         #
         space = FlowObjSpace()
         graph = space.build_flow(func)
-        assert graph.startblock.operations[0].opname == 'generator_entry'
+        assert graph.startblock.operations[0].opname == 'generator_mark'
         replace_graph_with_bootstrap(graph, 'newgraph')
+        if option.view:
+            graph.show()
         block = graph.startblock
         ops = block.operations
         assert ops[0].opname == 'call'      # e = Entry1()
-        assert ops[1].opname == 'setattr'   # e.n_0 = n
-        assert ops[1].args[1].value.startswith('n_')
-        assert ops[2].opname == 'setattr'   # e.x_0 = x
-        assert ops[2].args[1].value.startswith('x_')
-        assert ops[3].opname == 'setattr'   # e.y_0 = y
-        assert ops[3].args[1].value.startswith('y_')
-        assert ops[4].opname == 'setattr'   # e.z_0 = z
-        assert ops[4].args[1].value.startswith('z_')
-        assert ops[5].opname == 'call'      # g = Generator(e)
+        assert ops[1].opname == 'setattr'   # e.g_n = n
+        assert ops[1].args[1].value == 'g_n'
+        assert ops[2].opname == 'setattr'   # e.g_x = x
+        assert ops[2].args[1].value == 'g_x'
+        assert ops[3].opname == 'setattr'   # e.g_y = y
+        assert ops[3].args[1].value == 'g_y'
+        assert ops[4].opname == 'setattr'   # e.g_z = z
+        assert ops[4].args[1].value == 'g_z'
+        assert ops[5].opname == 'call'      # g = GeneratorIterator(e)
         assert ops[5].args[1] == ops[0].result
         assert len(ops) == 6
         assert len(block.exits) == 1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.