compiling to python byte codes

Michael Foord fuzzyman at gmail.com
Thu Sep 2 07:21:44 EDT 2004


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<4136bbf3$0$197$9b622d9e at news.freenet.de>...
> Maurice LING wrote:
> > I remembered reading a MSc thesis about compiling Perl to Java bytecodes 
> > (as in java class files).
> 
> You don't have to look that far. Jython compiles Python code into Java
> bytecode; IronPython compiles Python code into Microsoft intermediate
> language.
> 
> > I'm wondering if 
> > something of such had been attempted in python, as in compiling X 
> > language into .pyc. 
> 
> The easiest way to create a .pyc file is to create a Python file,
> and then compile that. There are various tools that compile X to
> .pyc. For example, Fnorb compiles OMG IDL into .pyc files.
> 
> > I do not understand the schematics of .pyc files but 
> > I assume that they are the so called python bytecode files.
> 
> That's correct.
> 
> > Or is there any documentation or books that is the python equivalent of 
> > "Programming for the Java Virtual Machine" by Joshua Engel?
> 
> There is the dis module and its documentation. However, as I said, in
> Python, you don't really *need* to create .pyc files directly, as
> the Python compiler is always available through the compile() builtin
> function. This is unlike Java or .NET, where the compiler is not
> available in the JRE, or the .NET commercial framework.
> 
> Regards,
> Martin


But that still doesn't answer the OPs question which is about writing
code in another language to generate python bytecode....

Which is interesting.. but not that interesting I suppose.
Is python bytecode *that* different to Java bytecode (not in detail
but in concept ?). There's no reason why another compiler couldn't
emit python bytecode to run on the 'python virtual machine' ? (plenty
of reasons not to do it I suppose just no reasons why it shouldn't be
possible).

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list