bytecode JUMP_IF_* always followed by POP_TOP?

Robert Brewer fumanchu at amor.org
Thu Apr 22 16:54:53 EDT 2004


I asked:
> bytecode JUMP_IF_* always followed by POP_TOP?

Partially answering my own question:

>>> def f(x):
... 	if x and a:
... 		y
... 	else:
... 		z
... 		
>>> dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 JUMP_IF_FALSE            4 (to 10)
              6 POP_TOP             
              7 LOAD_GLOBAL              1 (a)
        >>   10 JUMP_IF_FALSE            8 (to 21)
             13 POP_TOP             

  3          14 LOAD_GLOBAL              2 (y)
             17 POP_TOP             
             18 JUMP_FORWARD             5 (to 26)
        >>   21 POP_TOP             

  5          22 LOAD_GLOBAL              3 (z)
             25 POP_TOP             
        >>   26 LOAD_CONST               0 (None)
             29 RETURN_VALUE        

...the first JIF branches to either POP_TOP or the JIF at instr#10,
which then POPs the TOS. So intermediate JUMPs are possible. Any other
intermediates?


FuManChu




More information about the Python-list mailing list