[Python-Dev] Why is Bytecode the way it is?

Phillip J. Eby pje at telecommunity.com
Thu Jul 8 18:52:00 CEST 2004

At 07:14 AM 7/8/04 -0700, Paul Prescod wrote:

>I'm really not even proposing a change to Python as much as trying to 
>understand why it is the way it is. I can see how a stack is helpful for 
>evaluating deeply nested expressions (although temporary variables seems 
>another good valid approach). I just don't see the payoff for shuffling 
>variables from locals onto the stack and back into the locals table.

The payoff is in shorter development time...  of the compiler.  :)

Essentially, most of Python compilation is simply rearranging expressions 
to be postfix notation instead of infix notation.  Thus, it's relatively 
straightforward to write a compiler for, because the bytecode emissions 
match the recursive structure.  Although you need to keep track of the 
maximum stack depth, you don't need to worry about register allocation.

More information about the Python-Dev mailing list