diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-01 22:48:12 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-01 22:48:12 (GMT) |
commit | 3faa52ecc4aeb30f8913b4dd105184f6f7bc733d (patch) | |
tree | d4c6c78e934c98ef15aaf79fae249063b5a41a1b /Python/compile.c | |
parent | 1bbc04831071891c5bbeb53a2c1defbbf83245d9 (diff) | |
download | cpython-3faa52ecc4aeb30f8913b4dd105184f6f7bc733d.zip cpython-3faa52ecc4aeb30f8913b4dd105184f6f7bc733d.tar.gz cpython-3faa52ecc4aeb30f8913b4dd105184f6f7bc733d.tar.bz2 |
Allow 'continue' inside 'try' clause
SF patch 102989 by Thomas Wouters
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Python/compile.c b/Python/compile.c index 68f9e7f..3dae4c8 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -5,7 +5,7 @@ XXX add __doc__ attribute == co_doc to code object attributes? XXX (it's currently the first item of the co_const tuple) XXX Generate simple jump for break/return outside 'try...finally' - XXX Allow 'continue' inside try-finally + XXX Allow 'continue' inside finally clause of try-finally XXX New opcode for loading the initial index for a for loop XXX other JAR tricks? */ @@ -3247,19 +3247,24 @@ com_continue_stmt(struct compiling *c, node *n) } else { int j; - for (j = 0; j <= i; ++j) { + for (j = i-1; j >= 0; --j) { if (c->c_block[j] == SETUP_LOOP) break; } - if (j < i+1) { + if (j >= 0) { /* there is a loop, but something interferes */ - for (++j; j <= i; ++j) { - if (c->c_block[i] == SETUP_EXCEPT - || c->c_block[i] == SETUP_FINALLY) { - com_error(c, PyExc_SyntaxError, - "'continue' not supported inside 'try' clause"); + for (; i > j; --i) { + if (c->c_block[i] == SETUP_EXCEPT || + c->c_block[i] == SETUP_FINALLY) { + com_addoparg(c, CONTINUE_LOOP, + c->c_begin); return; } + if (c->c_block[i] == END_FINALLY) { + com_error(c, PyExc_SyntaxError, + "'continue' not supported inside 'finally' clause"); + return; + } } } com_error(c, PyExc_SyntaxError, |