summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b256198..35ec10a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -652,11 +652,16 @@ compiler_next_instr(struct compiler *c, basicblock *b)
return b->b_iused++;
}
-/* Set the i_lineno member of the instruction at offse off if the
- line number for the current expression/statement (?) has not
+/* Set the i_lineno member of the instruction at offset off if the
+ line number for the current expression/statement has not
already been set. If it has been set, the call has no effect.
- Every time a new node is b
+ The line number is reset in the following cases:
+ - when entering a new scope
+ - on each statement
+ - on each expression that start a new line
+ - before the "except" clause
+ - before the "for" and "while" expressions
*/
static void
@@ -1750,9 +1755,8 @@ compiler_for(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.For.iter);
ADDOP(c, GET_ITER);
compiler_use_next_block(c, start);
- /* XXX(nnorwitz): is there a better way to handle this?
- for loops are special, we want to be able to trace them
- each time around, so we need to set an extra line number. */
+ /* for expressions must be traced on each iteration,
+ so we need to set an extra line number. */
c->u->u_lineno_set = 0;
ADDOP_JREL(c, FOR_ITER, cleanup);
VISIT(c, expr, s->v.For.target);
@@ -1799,6 +1803,9 @@ compiler_while(struct compiler *c, stmt_ty s)
if (!compiler_push_fblock(c, LOOP, loop))
return 0;
if (constant == -1) {
+ /* while expressions must be traced on each iteration,
+ so we need to set an extra line number. */
+ c->u->u_lineno_set = 0;
VISIT(c, expr, s->v.While.test);
ADDOP_JREL(c, JUMP_IF_FALSE, anchor);
ADDOP(c, POP_TOP);
@@ -1979,8 +1986,8 @@ compiler_try_except(struct compiler *c, stmt_ty s)
s->v.TryExcept.handlers, i);
if (!handler->type && i < n-1)
return compiler_error(c, "default 'except:' must be last");
- c->u->u_lineno_set = 0;
- c->u->u_lineno = handler->lineno;
+ c->u->u_lineno_set = 0;
+ c->u->u_lineno = handler->lineno;
except = compiler_new_block(c);
if (except == NULL)
return 0;
@@ -3762,10 +3769,7 @@ assemble_lnotab(struct assembler *a, struct instr *i)
assert(d_bytecode >= 0);
assert(d_lineno >= 0);
- /* XXX(nnorwitz): is there a better way to handle this?
- for loops are special, we want to be able to trace them
- each time around, so we need to set an extra line number. */
- if (d_lineno == 0 && i->i_opcode != FOR_ITER)
+ if(d_bytecode == 0 && d_lineno == 0)
return 1;
if (d_bytecode > 255) {