Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Why not a Python compiler?
exarkun
2/7/2008 11:36:00 AM
On Thu, 07 Feb 2008 11:03:12 +0100, Stefan Behnel <stefan_ml@behnel.de> wrote:
>Santiago Romero wrote:
> [snip]
>>
>> Why not a Python COMPILER?
>>
>> It would be very nice to be able to output Linux, MAC or Windows
>> binaries of compiled (not bytecompiled) code. It would run faster, it
>> will be smaller in size (I think)
>
>Take a look at Cython. It's an optimising Python-to-C compiler for writing
>Python extensions. So you can basically take a Python module and compile it to
>C code that runs against the CPython runtime.
>
>
http://c...
>
It's a not-quite-Python-to-C compiler. I don't think it is an optimizing
compiler either. Can you provide a reference for this?
Jean-Paul
1 Answer
Stefan Behnel
2/7/2008 3:53:00 PM
0
Jean-Paul Calderone wrote:
> On Thu, 07 Feb 2008 11:03:12 +0100, Stefan Behnel <stefan_ml@behnel.de>
> wrote:
>> Take a look at Cython. It's an optimising Python-to-C compiler for
>> writing
>> Python extensions. So you can basically take a Python module and
>> compile it to
>> C code that runs against the CPython runtime.
>>
>>
http://c...
>
> It's a not-quite-Python-to-C compiler.
Ok, there are differences. For example, you can't define functions dynamically
(it doesn't currently support closures anyway). But it already supports a much
wider subset of the language than Pyrex originally did. For example, you can
use list comprehensions and Python 3 keyword-only arguments in function
signatures. I would expect it would compile quite a lot of Python code out
there without or with only minor modifications.
> I don't think it is an optimizing
> compiler either. Can you provide a reference for this?
It optimises a lot of common patterns into very fast sequences of Python API
calls (or even generates specialised non-API code for them). It also generates
optimised runtime code for special cases based on the type of an object (e.g.
if the object you iterate turns out to be a list, it uses fast list API calls
in loops, and a standard iterator otherwise). So the generated code is usually
much faster than what Pyrex gives you. Robert and I had an optimise session
lately where we dropped the function call-overhead by some 20-50% (!) compared
to the preceding Cython version (not even to Pyrex), just depending on the
signature.
I think that qualifies for an "optimising" compiler.
Stefan
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Why not a Python compiler?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password