Python "byte code" description

Grant Edwards grante at visi.com
Sat Dec 7 11:18:45 EST 2002


In article <7h38yz1kf1c.fsf at pc150.maths.bris.ac.uk>, Michael Hudson wrote:

> You can't.  But there are really very few tools that operate on
> bytecode.  You can expect them to break with every major release of
> Python.  I don't personally think that avoiding this is a worthwhile
> pursuit.
> 
>> 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?

IMO, a more interesting (from a geek/CS POV) project would be somebody who
wants to write a compiler for a different language that generates bytecode
that would be executed by they Python VM and inter-operate with "Python"
bytecode. One of the big strengths of Python is the library.  If you
generated Python bytecodes and used the same calling interface, then you
could impliment a new language that could also take advantage of the
existing libraries.

The fact that JVM is documented allowed JPython to do exactly this.

If the Python VM definition does not exist or is not stable, it prohibits
other compilers from taking advantage of the VM and existing code base.

> This strikes me as a silly thing to do: surely more sensible would be
> compiling Python source to these alternative bytecodes.

Or compiling alternative languages to Python bytecodes.

>> 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.
> 
> There may be.  I personally don't think so.

If I wanted to compile a different language into Python bytecode I _would_
think so.  [But I don't, so this is all academic.]

>> What if I wanted to implement an interpreter?
> 
> Why would you want to use the same bytecode as CPython currently does?
> Duplicating the effort to that point seems, well, pointless.

Perhaps somebody wants to impliment a hardware-assisted interpreter.  It's
been done for JVM.  If PVM isn't defined/stable, then doing HW accelleration
is going to be a bit difficult.

-- 
Grant Edwards                   grante             Yow!  MERYL STREEP is my
                                  at               obstetrician!
                               visi.com            



More information about the Python-list mailing list