Python "byte code" description

Derek Thomson derek at wedgetail.com
Sat Dec 7 05:24:37 EST 2002


Terry Reedy wrote:

> It is not a part of the language itself or its
> definition. 


I think you could argue that it would be useful in some situations if it 
were well defined. Or how else how can you be sure other interpeters, 
debuggers, or other tools that operate on the byte code (or virtual 
machine) are correct?

Or, what if I wanted to convert Python byte codes to JVM byte codes 
directly? Or Parrot byte codes? Or [insert VM here] byte codes?

> You can understand almost all of Python without knowing
> about compilation for efficiency.


True. But my question wasn't about understanding Python.

>
>
> >Is there anything more comprehensive, apart from the Python
> >implementation itself? Not only do I need the actual file format,
>
> The internal .pyc format is an internal implementation detail
> subject to change with each version.  


Maybe, but that fact *itself* isn't documented. Also, that doesn't 
always have to be true ...  there may be advantages in defining it 
concretely and limiting change, or at least managing it.

A trivial example: how do you know if the current behaviour of the C 
implementation for a particular case is a bug, or the way it's supposed 
to be, unless it's well defined, or you are Guido? ;)

>
>
> Python grabs what it needs as long as the OS will give it.  Specifics
> depend on your OS and hardware.  It 'assumes' that the system
> resources are sufficient for the task you give it.


That's not what I mean. I'm asking what assumptions the byte code makes 
about its environment (or, it's virtual machine/interpreter). For 
example, some of the operators assume the existence of a co_varnames 
variable. Others assume a stack.

>
>
> Perhaps you can restate your question to be more specific, and give a
> bit of context.


What if I wanted to implement an interpreter? I'd need to know what the 
properties of the stack are, and other environmental assumptions that 
the byte code instruction set makes.

But, I think this answers my question anyway. I'm just going to have to 
reverse engineer it for myself :(

Thanks anyhow!

--
D.




More information about the Python-list mailing list