[pypy-commit] pypy default: Issue 1247: Fix for the syntax "()[...]".
arigo
noreply at buildbot.pypy.org
Fri Aug 31 12:35:01 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r57053:aba0616c4c1b
Date: 2012-08-31 12:34 +0200
http://bitbucket.org/pypy/pypy/changeset/aba0616c4c1b/
Log: Issue 1247: Fix for the syntax "()[...]".
diff --git a/pypy/interpreter/astcompiler/optimize.py b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -21,28 +21,22 @@
def as_constant_truth(self, space):
"""Return the truth of this node if known."""
- raise AssertionError("only for expressions")
-
- def as_constant(self):
- """Return the value of this node as a wrapped constant if possible."""
- raise AssertionError("only for expressions")
-
- def accept_jump_if(self, gen, condition, target):
- raise AssertionError("only for expressions")
-
-
-class __extend__(ast.expr):
-
- def as_constant_truth(self, space):
const = self.as_constant()
if const is None:
return CONST_NOT_CONST
return int(space.is_true(const))
def as_constant(self):
+ """Return the value of this node as a wrapped constant if possible."""
return None
def accept_jump_if(self, gen, condition, target):
+ raise AssertionError("only for expressions")
+
+
+class __extend__(ast.expr):
+
+ def accept_jump_if(self, gen, condition, target):
self.walkabout(gen)
if condition:
gen.emit_jump(ops.POP_JUMP_IF_TRUE, target, True)
diff --git a/pypy/interpreter/test/test_compiler.py b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -851,7 +851,7 @@
('a = 14%4', '(2)'), # binary modulo
('a = 2+3', '(5)'), # binary add
('a = 13-4', '(9)'), # binary subtract
- # ('a = (12,13)[1]', '(13)'), # binary subscr - pointless optimization
+ ('a = (12,13)[1]', '(13)'), # binary subscr
('a = 13 << 2', '(52)'), # binary lshift
('a = 13 >> 2', '(3)'), # binary rshift
('a = 13 & 7', '(5)'), # binary and
@@ -872,6 +872,10 @@
asm = dis_single('a="x"*1000')
assert '(1000)' in asm
+ def test_folding_of_binops_on_constants_crash(self):
+ compile('()[...]', '', 'eval')
+ # assert did not crash
+
def test_dis_stopcode(self):
source = """def _f(a):
print a
More information about the pypy-commit
mailing list