[Compiler-sig] Python Bytecode

Michael Hudson mwh21@cam.ac.uk
05 Apr 2000 10:12:44 +0100


"Timothy Downs" <timdowns@hotmail.com> writes:

> I'm interested in writing a Python Virtual Machine, which processes the 
> Python Bytecode (ie, the *pyc files).
> 
> However, I cannot work out the format from the python source :(.
> Just wondering if anyone has any information of the format for the pyc 
> files, for example, when the empty .py file produces a 100 byte or so pyc 
> file.
> 
> Information of bytecode programming, Python, or otherwise would be very 
> hand.
> 
> (BTW. yes i have read the Python standard docs (dis.dis))
> 

The *.pyc files are 8 bytes of header (a magic number and a time
stamp, though I can't remember which order...) followed by a
marshalled code object.  So if you wan't to have a completely
independent VM, you first need to write a demarshaller ...
documentation is probably the source of Modules/marshal.c.

Cheers,
M.

-- 
well, take it from an old hand: the only reason it would be easier
to program in C is that you can't easily express complex  problems
in C, so you don't.                 -- Erik Naggum, comp.lang.lisp