[pypy-svn] r64172 - in pypy/trunk: lib-python/modified-2.5.2/test pypy/interpreter pypy/interpreter/astcompiler pypy/interpreter/astcompiler/test
iko at codespeak.net
iko at codespeak.net
Thu Apr 16 16:53:50 CEST 2009
Author: iko
Date: Thu Apr 16 16:53:49 2009
New Revision: 64172
Added:
pypy/trunk/lib-python/modified-2.5.2/test/test_trace.py
- copied, changed from r64136, pypy/trunk/lib-python/2.5.2/test/test_trace.py
Modified:
pypy/trunk/pypy/interpreter/astcompiler/pycodegen.py
pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
pypy/trunk/pypy/interpreter/pyopcode.py
Log:
(iko, pedronis)
fix test_trace issues
* bare except: gets line number
* implicit return gets line number
Copied: pypy/trunk/lib-python/modified-2.5.2/test/test_trace.py (from r64136, pypy/trunk/lib-python/2.5.2/test/test_trace.py)
==============================================================================
--- pypy/trunk/lib-python/2.5.2/test/test_trace.py (original)
+++ pypy/trunk/lib-python/modified-2.5.2/test/test_trace.py Thu Apr 16 16:53:49 2009
@@ -143,6 +143,8 @@
# Internally, the compiler visits the pass statement
# and stores its line number for use on the next instruction.
# The next instruction is the implicit return None.
+
+# XXX PyPy ignores the pass
def ireturn_example():
a = 5
b = 5
@@ -209,27 +211,31 @@
yield True
"continued"
finally:
- "finally"
+ x = "finally"
def generator_example():
# any() will leave the generator before its end
- x = any(generator_function())
+ gen = generator_function()
+ x = any(gen)
+ gen.close()
# the following lines were not traced
for x in range(10):
y = x
-
+
generator_example.events = ([(0, 'call'),
(2, 'line'),
+ (3, 'line'),
(-6, 'call'),
(-5, 'line'),
(-4, 'line'),
(-4, 'return'),
- (-4, 'call'),
+ (4, 'line'),
(-4, 'exception'),
+ (-4, 'call'),
(-1, 'line'),
(-1, 'return')] +
- [(5, 'line'), (6, 'line')] * 10 +
- [(5, 'line'), (5, 'return')])
+ [(7, 'line'), (8, 'line')] * 10 +
+ [(7, 'line'), (7, 'return')])
class Tracer:
@@ -330,11 +336,10 @@
for_example,
[(0, 'call'),
(1, 'line'),
- (2, 'line'),
(1, 'line'),
- (2, 'line'),
(1, 'line'),
- (1, 'return')])
+ (2, 'line'),
+ (2, 'return')])
def while_example():
# While expression should be traced on every loop
Modified: pypy/trunk/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/pycodegen.py (original)
+++ pypy/trunk/pypy/interpreter/astcompiler/pycodegen.py Thu Apr 16 16:53:49 2009
@@ -306,7 +306,7 @@
gen = FunctionCodeGenerator(self.space, node, isLambda,
self.get_module(), initialnode)
node.code.accept( gen )
- gen.finish()
+ gen.finish(node)
self.set_lineno(node)
for default in node.defaults:
default.accept( self )
@@ -330,7 +330,7 @@
gen = ClassCodeGenerator(self.space, node,
self.get_module())
node.code.accept( gen )
- gen.finish()
+ gen.finish(node)
self.set_lineno(node)
self.emitop_obj('LOAD_CONST', self.space.wrap(node.name) )
for base in node.bases:
@@ -631,7 +631,7 @@
inner = node.code
assert isinstance(inner, ast.GenExprInner)
inner.accept( gen )
- gen.finish()
+ gen.finish(node)
self.set_lineno(node)
self._makeClosure(gen, 0)
# precomputation of outmost iterable
@@ -761,6 +761,7 @@
self.emitop_block('JUMP_IF_FALSE', next)
self.emit('POP_TOP')
else:
+ self.set_lineno(body)
next = None
self.emit('POP_TOP')
if target:
@@ -1409,7 +1410,9 @@
def get_module(self):
return self.module
- def finish(self):
+ def finish(self, node=None):
+ if node:
+ self.set_lineno(node.flatten()[-1])
if not self.isLambda:
self.emitop_obj('LOAD_CONST', self.space.w_None)
self.emit('RETURN_VALUE')
@@ -1473,7 +1476,7 @@
def get_module(self):
return self.module
- def finish(self):
+ def finish(self, node=None):
self.emit('LOAD_LOCALS')
self.emit('RETURN_VALUE')
Modified: pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py (original)
+++ pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py Thu Apr 16 16:53:49 2009
@@ -433,10 +433,9 @@
def test_return_lineno(self):
# the point of this test is to check that there is no code associated
- # with any line greater than 4. The implicit return should not have
- # any line number - otherwise it would probably show up at line 5,
- # which is confusing because it's in the wrong branch of the "if"
- # in the case where a == b.
+ # with any line greater than 4.
+ # The implict return will have the line number of the last statement
+ # so we check that that line contains exactly the implicit return None
yield self.simple_test, """\
def ireturn_example(): # line 1
global b # line 2
@@ -446,8 +445,11 @@
if 1: pass # line 6
import dis
co = ireturn_example.func_code
- x = [lineno for addr, lineno in dis.findlinestarts(co)]
- """, 'x', [3, 4]
+ linestarts = list(dis.findlinestarts(co))
+ addrreturn = linestarts[-1][0]
+ x = [addrreturn == (len(co.co_code) - 4)]
+ x.extend([lineno for addr, lineno in linestarts])
+ """, 'x', [True, 3, 4, 6]
def test_type_of_constants(self):
yield self.simple_test, "x=[0, 0L]", 'type(x[1])', long
Modified: pypy/trunk/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyopcode.py (original)
+++ pypy/trunk/pypy/interpreter/pyopcode.py Thu Apr 16 16:53:49 2009
@@ -144,7 +144,12 @@
# dispatch_bytecode(), causing the real exception to be
# raised after the exception handler block was popped.
try:
- ec.bytecode_trace(self)
+ trace = self.w_f_trace
+ self.w_f_trace = None
+ try:
+ ec.bytecode_trace(self)
+ finally:
+ self.w_f_trace = trace
except OperationError, e:
operr = e
pytraceback.record_application_traceback(
More information about the Pypy-commit
mailing list