Style question on recursive generators

Jeff Epler jepler at unpythonic.net
Wed Oct 20 09:43:22 EDT 2004


On Wed, Oct 20, 2004 at 09:12:59AM +0200, Alex Martelli wrote:
> Anyway, the bytecode that idiom makes is something like:
> 
>               3 LOAD_FAST                0 (other)
>               6 GET_ITER            
>         >>    7 FOR_ITER                10 (to 20)
>              10 STORE_FAST               1 (x)
>              13 LOAD_FAST                1 (x)
>              16 YIELD_VALUE         
>              17 JUMP_ABSOLUTE            7

I think that the other thing the compiler must recognize, beyond this
sequence, is that "x" is dead below the loop (no longer used, or stored
to before the next use).

On the other hand, I guess the new YIELD_VALUES opcode could leave the
last value on the top of the stack, replacing this sequence with
    LOAD_FAST    0 (other)
    GET_ITER
    YIELD_VALUES
    STORE_FAST   1 (x)
I was imagining that YIELD_VALUES would not put anything on the stack,
if it was used to implement a new 'yield from'/'yield *' statement.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041020/8a8375b8/attachment.sig>


More information about the Python-list mailing list