[pypy-commit] pypy py3k: loosen codegen's constant expression optimization, cpython's test_sys_settrace
pjenvey
noreply at buildbot.pypy.org
Fri Apr 5 01:18:49 CEST 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r63034:ff08b8863a84
Date: 2013-04-04 16:17 -0700
http://bitbucket.org/pypy/pypy/changeset/ff08b8863a84/
Log: loosen codegen's constant expression optimization, cpython's
test_sys_settrace expects a constant bool to be emitted, e.g.
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -844,8 +844,8 @@
if self.interactive:
expr.value.walkabout(self)
self.emit_op(ops.PRINT_EXPR)
- # Only compile if the expression isn't constant.
- elif not expr.value.constant:
+ elif not (isinstance(expr.value, ast.Num) or
+ isinstance(expr.value, ast.Str)):
expr.value.walkabout(self)
self.emit_op(ops.POP_TOP)
diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py
--- a/pypy/interpreter/test/test_pyframe.py
+++ b/pypy/interpreter/test/test_pyframe.py
@@ -436,6 +436,25 @@
sys.settrace(None)
assert res == 42
+ def test_trace_onliner_if(self):
+ import sys
+ l = []
+ def trace(frame, event, arg):
+ l.append((frame.f_lineno, event))
+ return trace
+ def onliners():
+ if True: False
+ else: True
+ return 0
+ sys.settrace(trace)
+ onliners()
+ sys.settrace(None)
+ firstlineno = onliners.__code__.co_firstlineno
+ assert l == [(firstlineno + 0, 'call'),
+ (firstlineno + 1, 'line'),
+ (firstlineno + 3, 'line'),
+ (firstlineno + 3, 'return')]
+
def test_set_unset_f_trace(self):
import sys
seen = []
More information about the pypy-commit
mailing list