Python Compiling

Martin v. Löwis loewis at informatik.hu-berlin.de
Fri Sep 20 16:30:14 EDT 2002


"Terje Johan Abrahamsen" <spoermeg at voldelig.com> writes:

> Could someone write a compiler and get Python to be a compiled
> language like C?

Yes; there have been a few demonstrations that this is possible.

> Is it not possible to write a complete compiler like the C compiler for
> Python? Or is it just that nobody has done it? 

It has been done, see John Aycock's IPC7 paper (Converting Python
Virtual Machine Code to C) for an example, and Jonathan Riehl's IPC7
paper (PyFront: Conversion of Python to C Extension Modules) for
another.

> Or must the language be constructed differently?

To merely produce a complete "machine-code" binary, no, with
Johnathan's technique. 

The question is: why do you want to have a compiler? Using it is much
more difficult than an interpreter, and more time-consuming during
development of an application. People often expect significant speed
increases from compilation, but it turns out that those don't
materialize. 

The reason for that is that any compiler would need to maintain the
semantics of the Python language, which means that certain
optimizations that a C compiler does for C code are not possible in
Python, since, at compile time, it is uncertain whether the
prerequisites for that optimization are met.

HTH,
Martin



More information about the Python-list mailing list