[pypy-commit] pypy python-loop-unroll: RPython + handle comprehensions without crashing

alex_gaynor noreply at buildbot.pypy.org
Wed May 29 00:39:43 CEST 2013


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: python-loop-unroll
Changeset: r64651:8e979a30ce19
Date: 2013-05-28 15:39 -0700
http://bitbucket.org/pypy/pypy/changeset/8e979a30ce19/

Log:	RPython + handle comprehensions without crashing

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -881,8 +881,10 @@
         w_iterable = self.popvalue()
         if isinstance(w_iterable, W_LoopUnroller):
             lastblock = self.lastblock
-            assert isinstance(lastblock, LoopBlock)
-            lastblock.should_unroll = True
+            # This is the case for comprehensions, which don't add a frame
+            # block, annoying (for now ignore the problem).
+            if isinstance(lastblock, LoopBlock):
+                lastblock.should_unroll = True
         w_iterator = self.space.iter(w_iterable)
         self.pushvalue(w_iterator)
 
@@ -1209,7 +1211,7 @@
     """Abstract base class for frame blocks from the blockstack,
     used by the SETUP_XXX and POP_BLOCK opcodes."""
 
-    _immutable_ = True
+    _immutable_fields_ = ["handlerposition", "valuestackdepth", "previous"]
 
     def __init__(self, frame, handlerposition, previous):
         self.handlerposition = handlerposition
@@ -1249,7 +1251,6 @@
 class LoopBlock(FrameBlock):
     """A loop block.  Stores the end-of-loop pointer in case of 'break'."""
 
-    _immutable_fields_ = ["handlerposition", "valuestackdepth", "previous"]
     _opname = 'SETUP_LOOP'
     handling_mask = SBreakLoop.kind | SContinueLoop.kind
 
@@ -1275,7 +1276,6 @@
 class ExceptBlock(FrameBlock):
     """An try:except: block.  Stores the position of the exception handler."""
 
-    _immutable_ = True
     _opname = 'SETUP_EXCEPT'
     handling_mask = SApplicationException.kind
 
@@ -1299,7 +1299,6 @@
 class FinallyBlock(FrameBlock):
     """A try:finally: block.  Stores the position of the exception handler."""
 
-    _immutable_ = True
     _opname = 'SETUP_FINALLY'
     handling_mask = -1     # handles every kind of SuspendedUnroller
 
@@ -1314,8 +1313,6 @@
 
 class WithBlock(FinallyBlock):
 
-    _immutable_ = True
-
     def handle(self, frame, unroller):
         if isinstance(unroller, SApplicationException):
             unroller.operr.normalize_exception(frame.space)


More information about the pypy-commit mailing list