[Python-Dev] The purpose of SETUP_LOOP, BREAK_LOOP, CONTINUE_LOOP

Eugene Toder eltoder at gmail.com
Sat Mar 12 02:24:09 CET 2011


Hello,

What is the purpose of SETUP_LOOP instruction? From a quick look it
seems like it just pushes the size of the loop into blocks stack; that
size is only used by BREAK_LOOP instruction.
BREAK_LOOP could just contain the target address directly, like
CONTINUE_LOOP does. This would avoid SETUP_LOOP/POP_BLOCK overhead for
all loops.
Am I missing something? Does SETUP_LOOP serve any other purpose?

Similarly, it looks like BREAK_LOOP and CONTINUE_LOOP are just jumps
that respect try/finally blocks (i.e. jumping out of try executes
finally). Is there more semantics to them than this? If not, this can
be simplified to:
1) If not in try/finally, simply generate a direct jump outside of the
loop (break) or to the start of the loop (continue).
2) If in try/finally, generate a new instruction JUMP_FROM_TRY which
replaces both BREAK_LOOP and CONTINUE_LOOP. It behaves the same way as
CONTINUE_LOOP but without restriction to only jump backwards (could
reuse CONTINUE_LOOP, but the name would be misleading).
continue statement is already handled this way, but break always uses
BREAK_LOOP.

Any comments are appreciated.

Regards,
Eugene


More information about the Python-Dev mailing list