Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74679:aa96c8f015da
Date: 2014-05-05 02:05 +0100
http://bitbucket.org/pypy/pypy/changeset/aa96c8f015da/

Log:    Create BytecodeGraph.next_pos() and use it.

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -70,9 +70,9 @@
         for block in pendingblocks:
             for i, op in enumerate(block.operations):
                 graph.pos_index[op.offset] = block, i
-        graph.next_pos = dict([(offsets[i], offsets[i+1])
+        graph._next_pos = dict([(offsets[i], offsets[i+1])
             for i in range(len(offsets) - 1)])
-        graph.next_pos[offsets[-1]] = len(self.co_code)
+        graph._next_pos[offsets[-1]] = len(self.co_code)
         while pendingblocks:
             block = pendingblocks.pop()
             for i, op in enumerate(block.operations):
@@ -98,6 +98,7 @@
     def is_generator(self):
         return bool(self.co_flags & CO_GENERATOR)
 
+
 class BytecodeReader(object):
     def __init__(self, opnames):
         self.opnames = opnames
@@ -176,11 +177,17 @@
         self.entry.set_exits([startblock])
         self.pos_index = {}
 
-    def read(self, offset):
-        block, i = self.pos_index[offset]
-        op = block[i]
-        next_offset = self.next_pos[offset]
-        return next_offset, op
+    def read(self, pos):
+        bc_block, i = self.pos_index[pos]
+        return bc_block[i]
+
+    def next_pos(self, opcode):
+        return self._next_pos[opcode.offset]
+
+    def add_jump(self, block, target_block):
+        last_op = block.operations[-1]
+        self._next_pos[last_op.offset] = target_block.startpos
+        block.set_exits([target_block])
 
 
 class BytecodeBlock(object):
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -15,6 +15,7 @@
 from rpython.flowspace.framestate import FrameState
 from rpython.flowspace.specialcase import (rpython_print_item,
     rpython_print_newline)
+from rpython.flowspace.bytecode import BytecodeBlock
 from rpython.flowspace.operation import op
 from rpython.flowspace.bytecode import BytecodeCorruption
 
@@ -449,13 +450,18 @@
                     break
 
     def handle_bytecode(self, next_offset):
-        self.last_offset = next_offset
+        bc_graph = self.pycode.graph
         next_offset, instr = self.pycode.read(next_offset)
+        self.last_offset = instr.offset
         try:
             offset = instr.eval(self)
-            return offset if offset is not None else next_offset
         except FlowSignal as signal:
             return self.unroll(signal)
+        if next_offset is None:
+            next_offset = bc_graph.next_pos(instr)
+        elif isinstance(next_offset, BytecodeBlock):
+            next_offset = next_offset.startpos
+        return next_offset
 
     def unroll(self, signal):
         while self.blockstack:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to