Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r75870:e578fa65e31c
Date: 2015-02-14 14:48 +0000
http://bitbucket.org/pypy/pypy/changeset/e578fa65e31c/

Log:    move RETURN_VALUE to bytecode.py and clean up

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -233,22 +233,27 @@
                 instr.do_signals(self)
 
     def splice_finally_handler(self, block, context):
+        cell = []
         def copy_block(handler):
             b = handler.copy()
             if handler is context.handler_end:
                 instr = b.operations.pop()
                 assert isinstance(instr, END_FINALLY)
+                cell.append(b)
             else:
                 b.set_exits([copy_block(child) for child in handler._exits])
             self.blocks.append(b)
             return b
         block.set_exits([copy_block(context.handler)])
+        copy_of_handler_end, = cell
+        return copy_of_handler_end
 
     def check_graph(self):
         for b in self.blocks:
             if not b._exits:
-                assert any(instr.name in ('RETURN_VALUE', 'RAISE_VARARGS')
-                        for instr in b.operations)
+                instr = b.operations[-1]
+                assert instr.name in (
+                        'RETURN_VALUE', 'RAISE_VARARGS', 'EXEC_STMT')
             for x in b._exits:
                 assert x in self.blocks
 
@@ -614,6 +619,17 @@
             "A continue statement should not escape from the function")
 
 @bc_reader.register_opcode
+class RETURN_VALUE(BCInstruction):
+    def bc_flow(self, reader):
+        reader.curr_block.operations.append(self)
+        reader.end_block()
+
+    def eval(self, ctx):
+        from rpython.flowspace.flowcontext import Return
+        w_returnvalue = ctx.popvalue()
+        raise Return(w_returnvalue)
+
+@bc_reader.register_opcode
 class END_FINALLY(BCInstruction):
     def bc_flow(self, reader):
         reader.curr_block.operations.append(self)
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -606,9 +606,10 @@
         w_module = self.peekvalue()
         self.pushvalue(self.import_from(w_module, w_name))
 
-    def RETURN_VALUE(self, oparg):
-        w_returnvalue = self.popvalue()
-        raise Return(w_returnvalue)
+    def return_value(self, w_result):
+        link = Link([w_result], self.graph.returnblock)
+        self.recorder.crnt_block.closeblock(link)
+        raise StopFlowing
 
     def YIELD_VALUE(self, _):
         assert self.pycode.is_generator
@@ -1014,10 +1015,7 @@
         self.w_value = w_value
 
     def nomoreblocks(self, ctx):
-        w_result = self.w_value
-        link = Link([w_result], ctx.graph.returnblock)
-        ctx.recorder.crnt_block.closeblock(link)
-        raise StopFlowing
+        ctx.return_value(self.w_value)
 
     @property
     def args(self):
diff --git a/rpython/flowspace/test/test_bytecode.py 
b/rpython/flowspace/test/test_bytecode.py
--- a/rpython/flowspace/test/test_bytecode.py
+++ b/rpython/flowspace/test/test_bytecode.py
@@ -12,7 +12,7 @@
         else:
             return 0
     bc_graph = make_graph(f)
-    assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10]
+    assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10, 14]
     assert bc_graph.dump()[0][0] == bc_reader.new_instr('LOAD_FAST', 0)
 
 def test_blockstack():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to