Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74779:3b6c35deccbc
Date: 2014-11-26 19:54 +0100
http://bitbucket.org/pypy/pypy/changeset/3b6c35deccbc/

Log:    return BC blocks from FrameBlock.handle()

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -507,9 +507,13 @@
 
 @bc_reader.register_opcode
 class CONTINUE_LOOP(BCInstruction):
+    def bc_flow(self, reader):
+        reader.curr_block.operations.append(self)
+        self.target = reader.get_block_at(self.arg)
+
     def eval(self, ctx):
         from rpython.flowspace.flowcontext import Continue
-        raise Continue(self.arg)
+        raise Continue(self.target)
 
 class SetupInstruction(BCInstruction):
     def bc_flow(self, reader):
@@ -525,19 +529,19 @@
 class SETUP_EXCEPT(SetupInstruction):
     def make_block(self, ctx):
         from rpython.flowspace.flowcontext import ExceptBlock
-        return ExceptBlock(ctx.stackdepth, self.arg)
+        return ExceptBlock(ctx.stackdepth, self.target)
 
 @bc_reader.register_opcode
 class SETUP_LOOP(SetupInstruction):
     def make_block(self, ctx):
         from rpython.flowspace.flowcontext import LoopBlock
-        return LoopBlock(ctx.stackdepth, self.arg)
+        return LoopBlock(ctx.stackdepth, self.target)
 
 @bc_reader.register_opcode
 class SETUP_FINALLY(SetupInstruction):
     def make_block(self, ctx):
         from rpython.flowspace.flowcontext import FinallyBlock
-        return FinallyBlock(ctx.stackdepth, self.arg)
+        return FinallyBlock(ctx.stackdepth, self.target)
 
 @bc_reader.register_opcode
 class SETUP_WITH(SetupInstruction):
@@ -551,7 +555,7 @@
         ctx.settopvalue(w_exit)
         w_enter = op.getattr(w_manager, const('__enter__')).eval(ctx)
         w_result = op.simple_call(w_enter).eval(ctx)
-        block = WithBlock(ctx.stackdepth, self.arg)
+        block = WithBlock(ctx.stackdepth, self.target)
         ctx.blockstack.append(block)
         ctx.pushvalue(w_result)
 
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -16,6 +16,7 @@
     rpython_print_newline)
 from rpython.flowspace.operation import op
 from rpython.flowspace.bytecode import BytecodeCorruption, bc_reader
+from rpython.flowspace.bytecode import BytecodeBlock
 from rpython.flowspace.pygraph import PyGraph
 
 w_None = const(None)
@@ -356,12 +357,11 @@
                 try:
                     next_block = instr.eval(self)
                 except FlowSignal as signal:
-                    next_position = bc_graph.get_position(self.unroll(signal))
+                    next_block = self.unroll(signal)
+                if next_block is None:
+                    next_position = bc_graph.next_pos()
                 else:
-                    if next_block is None:
-                        next_position = bc_graph.next_pos()
-                    else:
-                        next_position = next_block, 0
+                    next_position = next_block, 0
                 bc_graph.curr_position = next_position
                 self.recorder.final_state = self.getstate(next_position)
 
@@ -1125,20 +1125,20 @@
     """Abstract base class for frame blocks from the blockstack,
     used by the SETUP_XXX and POP_BLOCK opcodes."""
 
-    def __init__(self, stackdepth, handlerposition):
-        self.handlerposition = handlerposition
+    def __init__(self, stackdepth, handler):
+        self.handler = handler
         self.stackdepth = stackdepth
 
     def __eq__(self, other):
         return (self.__class__ is other.__class__ and
-                self.handlerposition == other.handlerposition and
+                self.handler == other.handler and
                 self.stackdepth == other.stackdepth)
 
     def __ne__(self, other):
         return not (self == other)
 
     def __hash__(self):
-        return hash((self.handlerposition, self.stackdepth))
+        return hash((self.handler, self.stackdepth))
 
     def cleanupstack(self, ctx):
         ctx.dropvaluesuntil(self.stackdepth)
@@ -1161,7 +1161,7 @@
         else:
             # jump to the end of the loop
             self.cleanupstack(ctx)
-            return self.handlerposition
+            return self.handler
 
 class ExceptBlock(FrameBlock):
     """An try:except: block.  Stores the position of the exception handler."""
@@ -1181,7 +1181,7 @@
         ctx.pushvalue(w_exc.w_value)
         ctx.pushvalue(w_exc.w_type)
         ctx.last_exception = w_exc
-        return self.handlerposition   # jump to the handler
+        return self.handler   # jump to the handler
 
 class FinallyBlock(FrameBlock):
     """A try:finally: block.  Stores the position of the exception handler."""
@@ -1193,7 +1193,7 @@
         # the block unrolling and the entering the finally: handler.
         self.cleanupstack(ctx)
         ctx.pushvalue(unroller)
-        return self.handlerposition   # jump to the handler
+        return self.handler   # jump to the handler
 
 
 class WithBlock(FinallyBlock):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to