Python Bytecode

Tim Peters tim.one at comcast.net
Sat Aug 3 21:08:44 CEST 2002


[Terry Reedy]
> Can you or someone answer a question regarding the following from the
> above:
> "
> JUMP_IF_TRUE    delta
> If TOS is true, increment the byte code counter by delta. TOS is left
> on the stack.
>
> JUMP_IF_FALSE    delta
> If TOS is false, increment the byte code counter by delta. TOS is not
> changed.
> "
>
> Why isn't TOS removed?

[Michael Hudson]
> Haven't thought about this in a while, but I think it's for chained
> comparisons, e.g. code like:
>
> if 10 < a < 20:
>     ...

That may be its only use; as Terry suggested later, in other cases both
tails of the possible branch have to waste time with a POP_TOP.  I've been
complaining about this for years, but it's never bubbled to the top of the
stack.  Note that any change here would require bumping the PVM version
number.

> ...
> Hard to say whether this would be worth it without trying,

It would be a small win (since it does so little "real work", POP_TOP is
almost pure eval-loop overhead).

> and I'm unlikely to get around to trying it soon...

You're in good company <wink>.





More information about the Python-list mailing list