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

Eugene Toder eltoder at gmail.com
Tue Mar 15 16:49:49 CET 2011


> I think you guys are forgetting about FOR_ITER, listcomps, and the like.
>
> That is, IIRC, the reason loops use the block stack is because they put
> things on the regular stack, that need to be cleared off the stack when the
> loop is exited (whether normally or via an exception).

Good point. However, for exit via exception you always unwind till try
block, having loop block in the way seems unneeded?
While loops don't keep anything on values stack, so sounds like they
can avoid SETUP_LOOP?
Comprehensions don't use SETUP_LOOP already as you can't break from them.
Sounds like the only use case is for loop with explicit break. In this
case break can be compiled into POP and JUMP at the expense of
bytecode size if there are multiple breaks.

Eugene


More information about the Python-Dev mailing list