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

Robert Brewer fumanchu at amor.org
Thu Jul 8 18:23:56 CEST 2004

Paul Prescod wrote:
>  >>> def foo(a):
> ...     b = a + 5
> ...     return b
> Why does the RETURN_VALUE opcode have to return something from the
> stack? Why not have a RETURN_VAR opcode that would directly return a
> variable or constant? (a leading bit could indicate whether to look in
> the const or var tuple).

I notice that your example could be rewritten to return directly from
the stack. Perhaps the 'code' module could grow an .optimize function or

> And as long as we are talking about referring to things more directly,
> wouldn't it be possible to refer to constants by pointer rather than
> indirecting through the index? You'd have to fix up pointers when you
> first loaded the code but only once per function.

Then all our fancy bytecode hacks would have to redirect the pointers
back into the index again. ;)

Robert Brewer
Amor Ministries
fumanchu at amor.org

More information about the Python-Dev mailing list