Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

On-topic: alternate Python implementations

 

 

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded


steve+comp.lang.python at pearwood

Aug 3, 2012, 11:15 PM

Post #1 of 43 (911 views)
Permalink
On-topic: alternate Python implementations

Most people are aware, if only vaguely, of the big Four Python
implementations:

CPython, or just Python, the reference implementation written in C.
IronPython, written in .NET.
Jython, written in Java.
PyPy, the optimizing implementation written in Python (actually, it's
written in a subset of Python, RPython).

But the Python ecosystem is a lot bigger than just those four. Here are
just a few other implementations that you might be interested in:


Stackless - the "forgetten Python", Stackless is, I believe, the oldest
implementation behind only CPython itself. It's a fork of CPython with
the calling stack removed and fast and lightweight microthreads, and is
used extensively in EVE Online.

http://www.stackless.com/


Nuitka - optimising Python compiler written in C++, supports Python 2.6
and 2.7, claims to be up to twice as fast as CPython.

http://nuitka.net/pages/overview.html


WPython - another optimizing version of Python with wordcodes instead of
bytecodes.

http://code.google.com/p/wpython/


CLPython, an implementation of Python written in Common Lisp.

http://common-lisp.net/project/clpython/


CapPython is an experimental restricted version of Python with
capabilities.

http://plash.beasts.org/wiki/CapPython
http://en.wikipedia.org/wiki/Object-capability_model


Berp - a compiler which works by translating Python to Haskell and
compiling that.

https://github.com/bjpop/berp/wiki



Give them some love!



--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


rosuav at gmail

Aug 3, 2012, 11:34 PM

Post #2 of 43 (894 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano
<steve+comp.lang.python [at] pearwood> wrote:
> CLPython, an implementation of Python written in Common Lisp.
>
> Berp - a compiler which works by translating Python to Haskell and
> compiling that.

Okay. WHY? CLPython gives some reason, but how often do you need to
bridge that particular pair of languages? And why compile Python via
Haskell, when C is available as a "high level assembly language"?

The mind boggles...

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 3, 2012, 11:40 PM

Post #3 of 43 (893 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Steven D'Aprano, 04.08.2012 08:15:
> Most people are aware, if only vaguely, of the big Four Python
> implementations:
>
> CPython, or just Python, the reference implementation written in C.
> IronPython, written in .NET.
> Jython, written in Java.
> PyPy, the optimizing implementation written in Python (actually, it's
> written in a subset of Python, RPython).
>
> But the Python ecosystem is a lot bigger than just those four. Here are
> just a few other implementations that you might be interested in:
>
>
> Stackless - the "forgetten Python", Stackless is, I believe, the oldest
> implementation behind only CPython itself. It's a fork of CPython with
> the calling stack removed and fast and lightweight microthreads, and is
> used extensively in EVE Online.
>
> http://www.stackless.com/
>
>
> Nuitka - optimising Python compiler written in C++, supports Python 2.6
> and 2.7, claims to be up to twice as fast as CPython.
>
> http://nuitka.net/pages/overview.html
>
>
> WPython - another optimizing version of Python with wordcodes instead of
> bytecodes.
>
> http://code.google.com/p/wpython/
>
>
> CLPython, an implementation of Python written in Common Lisp.
>
> http://common-lisp.net/project/clpython/
>
>
> CapPython is an experimental restricted version of Python with
> capabilities.
>
> http://plash.beasts.org/wiki/CapPython
> http://en.wikipedia.org/wiki/Object-capability_model
>
>
> Berp - a compiler which works by translating Python to Haskell and
> compiling that.
>
> https://github.com/bjpop/berp/wiki

And not to forget Cython, which is the only static Python compiler that is
widely used. Compiles and optimises Python to C code that uses the CPython
runtime and allows for easy manual optimisations to get C-like performance
out of it.

http://cython.org/

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


steve+comp.lang.python at pearwood

Aug 4, 2012, 12:49 AM

Post #4 of 43 (888 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote:

> And not to forget Cython, which is the only static Python compiler that
> is widely used. Compiles and optimises Python to C code that uses the
> CPython runtime and allows for easy manual optimisations to get C-like
> performance out of it.
>
> http://cython.org/

Cython is great, but I question that it is a *Python* implementation.
That's not a criticism of Cython, but it is different from Python. Take
this example code from the tutorial:

from libc.math cimport sin

cdef double f(double x):
return sin(x*x)

If that's Python code, then I'm Ethel the Aardvark.

Cython is very Python-like, but there is no doubt in my mind that it is a
superset of Python and therefore a different language.


--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 2:10 AM

Post #5 of 43 (887 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Steven D'Aprano, 04.08.2012 09:49:
> On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote:
>> And not to forget Cython, which is the only static Python compiler that
>> is widely used. Compiles and optimises Python to C code that uses the
>> CPython runtime and allows for easy manual optimisations to get C-like
>> performance out of it.
>>
>> http://cython.org/
>
> Cython is great, but I question that it is a *Python* implementation.
> That's not a criticism of Cython, but it is different from Python. Take
> this example code from the tutorial:
>
> from libc.math cimport sin
>
> cdef double f(double x):
> return sin(x*x)
>
> If that's Python code, then I'm Ethel the Aardvark.

We never met in person, so I can't comment on the last part.

However, the above is Cython code and, yes, that's a different language.
Note that it uses a different file extension: ".pyx". Try putting the above
code into a .py file and compiling that. Cython will reject it and tell you
that "cimport" is not valid Python syntax.


> Cython is very Python-like, but there is no doubt in my mind that it is a
> superset of Python and therefore a different language.

As long as you don't use any features of the Cython language, it's plain
Python. That makes it a Python compiler in my eyes. The fact that you can
easily use C features to optimise your code (also in Python syntax, BTW)
doesn't impact that.

You mentioned a couple of other implementations and I'm sure they have
features (and bugs) that CPython doesn't have. Interaction with Lisp code
in CLPython, for example. I don't think additional features or language
implementation bugs make a Python implementation non-Python per se.

Also note that most of the less widely known "alternative Python
implementations" do not even publish their results of running the CPython
test suite, so how do you actually know they can run Python code?

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


breamoreboy at yahoo

Aug 4, 2012, 3:05 AM

Post #6 of 43 (886 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On 04/08/2012 08:49, Steven D'Aprano wrote:
> On Sat, 04 Aug 2012 08:40:16 +0200, Stefan Behnel wrote:
>
>> And not to forget Cython, which is the only static Python compiler that
>> is widely used. Compiles and optimises Python to C code that uses the
>> CPython runtime and allows for easy manual optimisations to get C-like
>> performance out of it.
>>
>> http://cython.org/
>
> Cython is great, but I question that it is a *Python* implementation.
> That's not a criticism of Cython, but it is different from Python. Take
> this example code from the tutorial:
>
> from libc.math cimport sin
>
> cdef double f(double x):
> return sin(x*x)
>
> If that's Python code, then I'm Ethel the Aardvark.
>
> Cython is very Python-like, but there is no doubt in my mind that it is a
> superset of Python and therefore a different language.
>
>

I agree so it's off topic and can't be discussed here. Isn't that
right, Stefan?

--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


steve+comp.lang.python at pearwood

Aug 4, 2012, 3:54 AM

Post #7 of 43 (886 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On Sat, 04 Aug 2012 16:34:17 +1000, Chris Angelico wrote:

> On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano
> <steve+comp.lang.python [at] pearwood> wrote:
>> CLPython, an implementation of Python written in Common Lisp.
>>
>> Berp - a compiler which works by translating Python to Haskell and
>> compiling that.
>
> Okay. WHY? CLPython gives some reason, but how often do you need to
> bridge that particular pair of languages? And why compile Python via
> Haskell, when C is available as a "high level assembly language"?

For much the same reason that PyPy uses RPython when C is available.
Because Haskell is available as a high level non-assembly language.

Berp is based on the Glasgow Haskell Compiler, which is a modern,
efficient, optimizing compiler capable of producing excellent quality
machine code on Windows, Mac, Linux and many Unixes. It gives you all the
advantages of a high-level language with high-level data structures, type
inference, and a compiler capable of generating optimized, fast, machine
code.

Who would want to deal with C's idiosyncrasies, low-powered explicit type
system, difficult syntax, and core-dumps, when you could use something
better? Apart from C programmers, of course.



--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 3:59 AM

Post #8 of 43 (887 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Mark Lawrence, 04.08.2012 12:05:
> I agree so it's off topic and can't be discussed here. Isn't that right,
> Stefan?

Hmm, in case you are referring to a recent friendly and diplomatic request
of mine regarding a couple of people who were burdening a public high
volume mailing list with a purely private back-and-forth chat about having
beer and getting drunk - then, no, I don't think the discussion in this
thread qualifies as yet another example for that so far.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


stefan-usenet at bytereef

Aug 4, 2012, 4:18 AM

Post #9 of 43 (887 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Steven D'Aprano <steve+comp.lang.python [at] pearwood> wrote:
> Who would want to deal with C's idiosyncrasies, low-powered explicit type
> system, difficult syntax, and core-dumps, when you could use something
> better?

In the free software world, apparently many people like C. C is also
quite popular in the zero-fault software world: Several verification
tools do exist and Leroy et al. are writing a certified compiler for
C to plug the hole between the verified source code and the generated
assembly.


Stefan Krah



--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 4:32 AM

Post #10 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Steven D'Aprano, 04.08.2012 12:54:
> Berp is based on the Glasgow Haskell Compiler, which is a modern,
> efficient, optimizing compiler capable of producing excellent quality
> machine code on Windows, Mac, Linux and many Unixes. It gives you all the
> advantages of a high-level language with high-level data structures, type
> inference, and a compiler capable of generating optimized, fast, machine
> code.

Although all those optimisations don't mean that Python code would run fast
on top of it. Just because you translate Python to another language and
platform doesn't mean that there's any benefit from the underlying platform
optimisations. Both PyPy and Cython run Python code faster than CPython,
but not because they eventually translate it into machine code but because
they optimise and specialise it along the way, based on its high-level code
constructs. One big success of the Unladen Swallow project was to show that
bare JIT compilation is mostly worthless for high level languages.


> Who would want to deal with C's idiosyncrasies, low-powered explicit type
> system, difficult syntax, and core-dumps, when you could use something
> better?

The core developers of both CPython and Cython aim for exactly that. They
write C so you don't have to. But keep in mind that C is still *the* lingua
franca of software development. A major reason why Python is (slowly)
catching up these days is that the main implementation is written in C and
makes it easy to interface with C code.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spa

Aug 4, 2012, 5:51 AM

Post #11 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Am 04.08.2012 11:10 schrieb Stefan Behnel:

> As long as you don't use any features of the Cython language, it's plain
> Python. That makes it a Python compiler in my eyes.

Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless,
C and C++ are distinct languages and so are Python and Cython.


Thomas
--
http://mail.python.org/mailman/listinfo/python-list


maniandram01 at gmail

Aug 4, 2012, 6:10 AM

Post #12 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

The first time I did reply not 'reply all', so I'm posting again. ;-)
I think Cython is a Python implementation because you can only use the
Python features, not the extra features.
C++ is different because of the different rules (C was in a time of
assembly and costly computers, C++ was made in the time of (relatively)
cheaper computers and computers doing more things)

On 4 August 2012 18:21, Thomas Rachel <
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 [at] spamschutz> wrote:

> Am 04.08.2012 11:10 schrieb Stefan Behnel:
>
>
> As long as you don't use any features of the Cython language, it's plain
>> Python. That makes it a Python compiler in my eyes.
>>
>
> Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C
> and C++ are distinct languages and so are Python and Cython.
>
>
> Thomas
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>


stefan_ml at behnel

Aug 4, 2012, 6:53 AM

Post #13 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Thomas Rachel, 04.08.2012 14:51:
> Am 04.08.2012 11:10 schrieb Stefan Behnel:
>> As long as you don't use any features of the Cython language, it's plain
>> Python. That makes it a Python compiler in my eyes.
>
> Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C
> and C++ are distinct languages and so are Python and Cython.

So, if a C++ compiler takes a .c file and compiles it with C language
semantics, it doesn't qualify as a C compiler? That implies a rather weird
definition of a C compiler, I'd say.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 7:03 AM

Post #14 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Stefan Behnel, 04.08.2012 15:53:
> Thomas Rachel, 04.08.2012 14:51:
>> Am 04.08.2012 11:10 schrieb Stefan Behnel:
>>> As long as you don't use any features of the Cython language, it's plain
>>> Python. That makes it a Python compiler in my eyes.
>>
>> Tell that the C++ guys. C++ is mainly a superset of C. But nevertheless, C
>> and C++ are distinct languages and so are Python and Cython.
>
> So, if a C++ compiler takes a .c file and compiles it with C language
> semantics, it doesn't qualify as a C compiler? That implies a rather weird
> definition of a C compiler, I'd say.

Ah, sorry. Got it. You were again talking about Cython the language. Sure,
Cython the language is different from Python the language. Cython the
compiler can compile both.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


no.email at nospam

Aug 4, 2012, 8:59 AM

Post #15 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Stefan Krah <stefan-usenet [at] bytereef> writes:
> In the free software world, apparently many people like C. C is also
> quite popular in the zero-fault software world: Several verification
> tools do exist and Leroy et al. are writing a certified compiler for
> C to plug the hole between the verified source code and the generated
> assembly.

C is pretty poor as a compiler target: how would you translate Python
generators into C, for example? How would you handle garbage
collection?

C isn't so great for high-assurance stuff either, compared to (say) Ada.
People do use it in critical apps, but that's just because it is (or
anyway used to be) so ubiquitous. I'm wondering what you mean about
verification tools, other than analyzers like Coverity that mainly check
for bugs that in a safer language would be caught by the compiler.
Compcert is not all that C-specific it has been adapted to compile a
Haskell-derived language (Habit).

Haskell doesn't sound all that great as a translation target for Python
either, unfortunately, because its execution semantics are so different.
GHC is a very powerful compiler but it was made to compile Haskell code
that people actually write, and may do less good of a job with compiler
output from an imperative language like Python. Compiling Python to
Scheme and then using a Scheme compiler might be a more natural fit.
But, compiling to Haskell was probably pretty convenient for that
particular project.

Finally, Python itself isn't all that well suited for compilation, given
its high dynamicity. It will be interesting to see if the language
evolves due to PyPy.
--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 9:55 AM

Post #16 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Paul Rubin, 04.08.2012 17:59:
> Stefan Krah writes:
>> In the free software world, apparently many people like C. C is also
>> quite popular in the zero-fault software world: Several verification
>> tools do exist and Leroy et al. are writing a certified compiler for
>> C to plug the hole between the verified source code and the generated
>> assembly.
>
> C is pretty poor as a compiler target: how would you translate Python
> generators into C, for example?

Depends. If you have CPython available, that'd be a straight forward
extension type. Otherwise, I guess you'd either have a class for them in
C++ or a struct in C. Not exactly complex.

For the yielding, you can use labels and goto. Given that you generate the
code, that's pretty straight forward as well.


> How would you handle garbage collection?

CPython does it automatically for us at least. Lacking that, you'd use one
of the available garbage collection implementations, or provide none at all.


> Haskell doesn't sound all that great as a translation target for Python
> either, unfortunately, because its execution semantics are so different.
> GHC is a very powerful compiler but it was made to compile Haskell code
> that people actually write, and may do less good of a job with compiler
> output from an imperative language like Python. Compiling Python to
> Scheme and then using a Scheme compiler might be a more natural fit.
> But, compiling to Haskell was probably pretty convenient for that
> particular project.

You'd have some kind of emulation layer that does most of the translation
at runtime. That's why I said that you shouldn't expect too much of a
performance gain from what the platform gives you for the underlying
implementation. It can optimise the emulator, but it won't see enough of
the Python code to make anything efficient out of it. Jython is an example
for that.


> Finally, Python itself isn't all that well suited for compilation, given
> its high dynamicity.

You can get pretty far with static code analysis, optimistic optimisations
and code specialisation. We've decided against whole program analysis in
Cython not only for compiler complexity reasons but also because it would
let the normal compilation time explode for gains that you can much easier
get by manual optimisation. Obviously, optimising JIT compilers can do much
more here (because they actually have to do less), although they won't
always be able to figure out the right thing to do either. That's where
manual optimisation wins again.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


no.email at nospam

Aug 4, 2012, 11:18 AM

Post #17 of 43 (880 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Stefan Behnel <stefan_ml [at] behnel> writes:
>> C is pretty poor as a compiler target: how would you translate Python
>> generators into C, for example?
> Depends. If you have CPython available, that'd be a straight forward
> extension type.

Calling CPython hardly counts as compiling Python into C.

> For the yielding, you can use labels and goto. Given that you generate
> the code, that's pretty straight forward as well.

You're going to compile the whole Python program into a single C
function so that you can do gotos inside of it? What happens if the
program imports a generator?

>> How would you handle garbage collection?
> CPython does it automatically for us at least.

You mean you're going to have all the same INCREF/DECREF stuff on every
operation in compiled data? Ugh.

> Lacking that, you'd use one of the available garbage collection
> implementations,

What implementations would those be? There's the Boehm GC which is
useful for some purposes but not really suitable at large scale, from
what I can tell. Is there something else?

> or provide none at all.

You're going to let the program just leak memory until it crashes??

> you shouldn't expect too much of a performance gain from what the
> platform gives you for the underlying implementation. It can optimise
> the emulator, but it won't see enough of the Python code to make
> anything efficient out of it. Jython is an example for that.

Compare that to the performance gain of LuaJIT and it starts to look
like something is wrong with that approach, or maybe some issue inherent
in Python itself.

> You can get pretty far with static code analysis, optimistic
> optimisations and code specialisation.

It seems very hard to do reasonable optimizations in the presence of
standard Python techniques like dynamically poking class instance
attributes. I guess some optimizations are still possible, like storing
attributes named as literals in the program in fixed slots, saving some
dictionary lookups even though the slot contents would have to still be
mutable.
--
http://mail.python.org/mailman/listinfo/python-list


breamoreboy at yahoo

Aug 4, 2012, 11:24 AM

Post #18 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On 04/08/2012 11:59, Stefan Behnel wrote:
> Mark Lawrence, 04.08.2012 12:05:
>> I agree so it's off topic and can't be discussed here. Isn't that right,
>> Stefan?
>
> Hmm, in case you are referring to a recent friendly and diplomatic request
> of mine regarding a couple of people who were burdening a public high
> volume mailing list with a purely private back-and-forth chat about having
> beer and getting drunk - then, no, I don't think the discussion in this
> thread qualifies as yet another example for that so far.
>
> Stefan
>
>

With arrogance like that German by any chance?

--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


lamialily at cleverpun

Aug 4, 2012, 11:34 AM

Post #19 of 43 (883 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On Sat, 04 Aug 2012 19:24:12 +0100, Mark Lawrence
<breamoreboy [at] yahoo> wrote:

>On 04/08/2012 11:59, Stefan Behnel wrote:
>> Mark Lawrence, 04.08.2012 12:05:
>>> I agree so it's off topic and can't be discussed here. Isn't that right,
>>> Stefan?
>>
>> Hmm, in case you are referring to a recent friendly and diplomatic request
>> of mine regarding a couple of people who were burdening a public high
>> volume mailing list with a purely private back-and-forth chat about having
>> beer and getting drunk - then, no, I don't think the discussion in this
>> thread qualifies as yet another example for that so far.
>>
>> Stefan
>>
>>
>
>With arrogance like that German by any chance?

Hey now, cool it with the passive-aggression. We're here to discuss
code, right? If you want to fight it out, you can gladly do it by
e-mail.

~Temia
--
Invective! Verb your expletive nouns!
--
http://mail.python.org/mailman/listinfo/python-list


schesis at gmail

Aug 4, 2012, 11:42 AM

Post #20 of 43 (880 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

:

On 4 August 2012 14:24, Mark Lawrence <breamoreboy [at] yahoo> wrote:
>
> With arrogance like that German by any chance?

I didn't give a monkeys about the beer conversation personally, but
can we leave the national stereotypes out of it?

-[]z.
--
http://mail.python.org/mailman/listinfo/python-list


breamoreboy at yahoo

Aug 4, 2012, 11:50 AM

Post #21 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

________________________________
From: Zero Piraeus <schesis [at] gmail>
To: Mark Lawrence <breamoreboy [at] yahoo>
Cc: python-list [at] python
Sent: Saturday, 4 August 2012, 19:42
Subject: Re: On-topic: alternate Python implementations

:

On 4 August 2012 14:24, Mark Lawrence <breamoreboy [at] yahoo> wrote:
>
> With arrogance like that German by any chance?

I didn't give a monkeys about the beer conversation personally, but
can we leave the national stereotypes out of it?

-[]z.

No.  Next question?


schesis at gmail

Aug 4, 2012, 11:56 AM

Post #22 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

:

On 4 August 2012 14:50, Mark Lawrence <breamoreboy [at] yahoo> wrote:
>
> No. Next question?

*plonk*

-[]z.
--
http://mail.python.org/mailman/listinfo/python-list


stefan_ml at behnel

Aug 4, 2012, 12:06 PM

Post #23 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Paul Rubin, 04.08.2012 20:18:
> Stefan Behnel writes:
>>> C is pretty poor as a compiler target: how would you translate Python
>>> generators into C, for example?
>> Depends. If you have CPython available, that'd be a straight forward
>> extension type.
>
> Calling CPython hardly counts as compiling Python into C.

CPython is written in C, though. So anything that CPython does can be done
in C. It's not like the CPython project used a completely unusual way of
writing C code.

Besides, I find your above statement questionable. You will always need
some kind of runtime infrastructure when you "compile Python into C", so
you can just as well use CPython for that instead of reimplementing it
completely from scratch. Both Cython and Nuitka do exactly that, and one of
the major advantages of that approach is that they can freely interact with
arbitrary code (Python or not) that was written for CPython, regardless of
its native dependencies. What good would it be to throw all of that away,
just for the sake of having "pure C code generation"?


>> For the yielding, you can use labels and goto. Given that you generate
>> the code, that's pretty straight forward as well.
>
> You're going to compile the whole Python program into a single C
> function so that you can do gotos inside of it? What happens if the
> program imports a generator?

No, you are going to compile only the generator function into a function
that uses gotos, maybe with an additional in-out struct parameter that
holds its state. Then, on entry, you read the label (or its ID) from the
previous state, reset local variables and jump to the label. On exit, you
store the state back end return. Cython does it that way. Totally straight
forward, as I said.


>>> How would you handle garbage collection?
>> CPython does it automatically for us at least.
>
> You mean you're going to have all the same INCREF/DECREF stuff on every
> operation in compiled data? Ugh.

If you don't like that, you can experiment with anything from a dedicated
GC to transactional memory.


>> Lacking that, you'd use one of the available garbage collection
>> implementations,
>
> What implementations would those be? There's the Boehm GC which is
> useful for some purposes but not really suitable at large scale, from
> what I can tell. Is there something else?

No idea - I'll look it up when I need one. Last I heard, PyPy had a couple
of GCs to choose from, but I don't know how closely the are tied into its
infrastructure.


>> or provide none at all.
>
> You're going to let the program just leak memory until it crashes??

Well, it's not like CPython leaks memory until it crashes, now does it? And
it's written in C. So there must be ways to handle this also in C.

Remember that CPython didn't even have a GC before something around 2.0,
IIRC. That worked quite ok in most cases and simply left the tricky cases
to the programmers. It really depends on what your requirements are. Small
embedded systems, time critical code and real-time systems are often much
better off without garbage collection. It's pure convenience, after all.


>> you shouldn't expect too much of a performance gain from what the
>> platform gives you for the underlying implementation. It can optimise
>> the emulator, but it won't see enough of the Python code to make
>> anything efficient out of it. Jython is an example for that.
>
> Compare that to the performance gain of LuaJIT and it starts to look
> like something is wrong with that approach, or maybe some issue inherent
> in Python itself.

Huh? LuaJIT is a reimplementation of Lua that uses an optimising JIT
compiler specifically for Lua code. How is that similar to the Jython
runtime that runs *on top of* the JVM with its generic byte code based JIT
compiler?

Basically, LuaJIT's JIT compiler works at the same level as the one in
PyPy, which is why both can theoretically provide the same level of
performance gains.


>> You can get pretty far with static code analysis, optimistic
>> optimisations and code specialisation.
>
> It seems very hard to do reasonable optimizations in the presence of
> standard Python techniques like dynamically poking class instance
> attributes. I guess some optimizations are still possible, like storing
> attributes named as literals in the program in fixed slots, saving some
> dictionary lookups even though the slot contents would have to still be
> mutable.

Sure. Even when targeting the CPython runtime with the generated C code
(like Cython or Nuitka), you can still do a lot. And sure, static code
analysis will never be able to infer everything that a JIT compiler can see.

Stefan


--
http://mail.python.org/mailman/listinfo/python-list


python at mrabarnett

Aug 4, 2012, 12:24 PM

Post #24 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

On 04/08/2012 20:06, Stefan Behnel wrote:
> Paul Rubin, 04.08.2012 20:18:
>> Stefan Behnel writes:
>>>> C is pretty poor as a compiler target: how would you translate Python
>>>> generators into C, for example?
>>> Depends. If you have CPython available, that'd be a straight forward
>>> extension type.
>>
>> Calling CPython hardly counts as compiling Python into C.
>
> CPython is written in C, though. So anything that CPython does can be done
> in C. It's not like the CPython project used a completely unusual way of
> writing C code.
>
> Besides, I find your above statement questionable. You will always need
> some kind of runtime infrastructure when you "compile Python into C", so
> you can just as well use CPython for that instead of reimplementing it
> completely from scratch. Both Cython and Nuitka do exactly that, and one of
> the major advantages of that approach is that they can freely interact with
> arbitrary code (Python or not) that was written for CPython, regardless of
> its native dependencies. What good would it be to throw all of that away,
> just for the sake of having "pure C code generation"?
>
>
>>> For the yielding, you can use labels and goto. Given that you generate
>>> the code, that's pretty straight forward as well.
>>
>> You're going to compile the whole Python program into a single C
>> function so that you can do gotos inside of it? What happens if the
>> program imports a generator?
>
> No, you are going to compile only the generator function into a function
> that uses gotos, maybe with an additional in-out struct parameter that
> holds its state. Then, on entry, you read the label (or its ID) from the
> previous state, reset local variables and jump to the label. On exit, you
> store the state back end return. Cython does it that way. Totally straight
> forward, as I said.
>
>
>>>> How would you handle garbage collection?
>>> CPython does it automatically for us at least.
>>
>> You mean you're going to have all the same INCREF/DECREF stuff on every
>> operation in compiled data? Ugh.
>
> If you don't like that, you can experiment with anything from a dedicated
> GC to transactional memory.
>
>
>>> Lacking that, you'd use one of the available garbage collection
>>> implementations,
>>
>> What implementations would those be? There's the Boehm GC which is
>> useful for some purposes but not really suitable at large scale, from
>> what I can tell. Is there something else?
>
> No idea - I'll look it up when I need one. Last I heard, PyPy had a couple
> of GCs to choose from, but I don't know how closely the are tied into its
> infrastructure.
>
>
>>> or provide none at all.
>>
>> You're going to let the program just leak memory until it crashes??
>
> Well, it's not like CPython leaks memory until it crashes, now does it? And
> it's written in C. So there must be ways to handle this also in C.
>
> Remember that CPython didn't even have a GC before something around 2.0,
> IIRC. That worked quite ok in most cases and simply left the tricky cases
> to the programmers. It really depends on what your requirements are. Small
> embedded systems, time critical code and real-time systems are often much
> better off without garbage collection. It's pure convenience, after all.
>
[snip]
CPython relied entirely on reference counting, so memory could leak you
if inadvertently created a cycle of memory references. That problem was
fixed when a mark-and-sweep mechanism was added (it's called
occasionally to collect any unreachable cycles).

--
http://mail.python.org/mailman/listinfo/python-list


timr at probo

Aug 4, 2012, 1:07 PM

Post #25 of 43 (878 views)
Permalink
Re: On-topic: alternate Python implementations [In reply to]

Steven D'Aprano <steve+comp.lang.python [at] pearwood> wrote:
>
>Most people are aware, if only vaguely, of the big Four Python
>implementations:
>
>CPython, or just Python, the reference implementation written in C.
>IronPython, written in .NET.

Technicality: .NET is not a language, it is a run-time framework.
IronPython is written in C#. It generates code that runs in the .NET
Framework.
--
Tim Roberts, timr [at] probo
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.