Python compilers?
Carl Banks
imbosol at aerojockey.invalid
Tue May 18 21:21:43 EDT 2004
[[ Note for Peter Hansen: all uses of the word "compiler" below is
understood to refer to an optimizing compiler to machine language, and
I mean a real, not virtual, machine. ]]
Heiko Wundram wrote:
> Am Dienstag, 18. Mai 2004 13:41 schrieb Jacek Generowicz:
>> Native compilers for other languages just as dynamic as Python
>> exist. These compilers manage to achieve very significant speed
>> increases[*].
>
> You are again refering to LISP as an example of a dynamic language
> which when compiled gives huge speed increases. This is true in some
> respect, in others it isn't. LISP has the advantage that
> type-inference may be used throughout the program to create one
> version of each function, which can then be compiled.
Can you give an example of a function Lisp is able to compile that
Python manifestly couldn't. I don't buy it.
[snip]
> In Python this isn't true. Python, instead of LISP, is "completely"
> dynamic, meaning that it's pretty impossible to do type-inference
> for each function that is called (even checking types isn't
> possible).
I don't follow you. In what way is Python dynamic that Lisp isn't?
And Python certainly can check types.
> E.g. how do you expect type-inference to work with the pickle
> module? string -> something/Error would be the best description what
> pickle does. For the function which calls pickle, do you want to
> create versions for each possible output of Pickle? Which outputs
> of Pickle are possible?
You can write pickling package in Lisp. I think the Lisp compiler
would handle such a package fine, and I see no reason why a
hypothetical Python compiler wouldn't.
> (depends on the loaded modules, which can be loaded at runtime)
> There is no (sane) way to create machine-code which calls into the
> appropriate (low-level) Python-runtime functions (such as Py_List*,
> Py_Dict*, etc.) for such a method, at least not at compile-time.
That might be true, but pickling is only one module. The fact that
I'm able to write a pickling package in Lisp doesn't make it
impossible to write a Lisp compiler, and the fact that pickling module
exists in Python doesn't make it impossible to write a Python
compiler.
What would a Lisp compiler do faced with a Lisp pickling package?
> At runtime, this is possible. See what psyco does. There's a nice
> presentation on the psyco-website which explains what it does, and I
> guess you'll understand when you see that why writing a "compiler"
> for Python is pretty impossible.
Well, I don't buy it, and I don't see any fundamental between Python
and Lisp dynamicism. The only thing you've demonstrated is that there
is some code in Python that could make optimizing difficult--a
statement which is true of Lisp also--but it's a specific case that is
not applicable generally.
--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
More information about the Python-list
mailing list