Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r86286:f8ffd7d38ab1 Date: 2016-08-18 19:34 +0200 http://bitbucket.org/pypy/pypy/changeset/f8ffd7d38ab1/
Log: Manual copy of b4e83acb5f3c, and fix of a resulting issue: two opcodes had a wrong stack effect diff --git a/pypy/interpreter/astcompiler/assemble.py b/pypy/interpreter/astcompiler/assemble.py --- a/pypy/interpreter/astcompiler/assemble.py +++ b/pypy/interpreter/astcompiler/assemble.py @@ -389,7 +389,8 @@ def _stacksize(self, blocks): """Compute co_stacksize.""" for block in blocks: - block.initial_depth = 0 + block.initial_depth = -99 + blocks[0].initial_depth = 0 # Assumes that it is sufficient to walk the blocks in 'post-order'. # This means we ignore all back-edges, but apart from that, we only # look into a block when all the previous blocks have been done. @@ -408,8 +409,11 @@ def _do_stack_depth_walk(self, block): depth = block.initial_depth + if depth == -99: # this block is never reached, skip + return 0 for instr in block.instructions: depth += _opcode_stack_effect(instr.opcode, instr.arg) + assert depth >= 0 if depth >= self._max_depth: self._max_depth = depth jump_op = instr.opcode @@ -560,7 +564,6 @@ ops.LIST_APPEND: -1, ops.SET_ADD: -1, ops.MAP_ADD: -2, - # XXX ops.BINARY_POWER: -1, ops.BINARY_MULTIPLY: -1, @@ -602,8 +605,8 @@ ops.PRINT_EXPR: -1, - ops.WITH_CLEANUP_START: -1, - ops.WITH_CLEANUP_FINISH: -1, # XXX Sometimes more + ops.WITH_CLEANUP_START: 1, + ops.WITH_CLEANUP_FINISH: -2, ops.LOAD_BUILD_CLASS: 1, ops.POP_BLOCK: 0, ops.POP_EXCEPT: -1, @@ -619,7 +622,6 @@ ops.YIELD_FROM: -1, ops.COMPARE_OP: -1, - # TODO ops.LOOKUP_METHOD: 1, ops.LOAD_NAME: 1, diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -511,6 +511,9 @@ x *= 7 """, 'x', 42 + def test_with_stacksize_bug(self): + compile_with_astcompiler("with a:\n pass", 'exec', self.space) + def test_with_bug(self): yield self.simple_test, """ class ContextManager: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit