Sunday 11 January 2009

Pypy is great

Even though I was in holidays recently, I spent some time to have a look at the update from the pypy project.

I get really excited by what the project has achieved so far.

Pypy is a python interpreter written in python.
The most interesting part of the project is the ability to use it to translate python code into other languages, like C, java, javascript, and LLVM.

So far only a subset of python language is translatable (for example generators won't work.) [edit: as the pypy people pointed out, full python language will never be translatable, that is not the goal of the project.]

But this simplified python (called RPython) is already good enough for many projects. As an example pypy interpreter itself is written in RPython and so can be compiled into machine code.

The good thing about this is that you can develop an application totally in python and then use the translators to generate fast machine code. So python could become some sort of universal language that replaces all other languages.

An other interesting things about pypy is the ability to generate stackless code, that allow many cool things, like tasklets (see the documentation about this).

Now I can't help thinking about OpenMoko paroli project, that uses python and tasklets. Could it be possible to use pypy to translate the python code into machine code and so create optimized version of paroli ?

The idea is very seducing, but many problems would need to be solved before we can get to there. The first thing is that we would have to modify our code to remove all the things that are not supported by pypy.

The second things is that even though pypy supports tasklets, it is impossible to do it using the python yield statement and the trick explained in PEP342.

An other good use of pypy would be to create web application without having to write -quite ugly- javascript code.

4 comments:

vak said...

hi,
BTW, do you know the current status regarding PyPy and LLVM?
regards, Valery

Guillaume Chéreau said...

vak: I have never tried the LLVM backend of pypy so I can't help you, you should probably ask on the pypy irc channel.

josch said...

you say that pypy might be interesting for paroli which, when written in rpython could be translated to native code but some sentences before you realized that rpython does not support generators or yields and the principle paroli works by IS using yield to emulate concurrency - so somthing like that would only be possible by dropping the tichy concept of abusing yield to the extend as it is done in tichy/paroli

Guillaume Chéreau said...

Josh : you are perfectly right.

The problem is that tichy needs coroutines, and the easiest way to get them in python is by using this "yield" trick, which I also find not very nice.

Another approach would have been to use python stackless, or py.greenlet library, but that wouldn't work on the arm target.

I am going to give a try at using threads - arg! - to emulate coroutines in tichy, but I am not sure that would work.

this being said, there are some other things in tichy that would make it difficult to port to rpython, for example the signal/slot system relies on deferred calls to methods with different signatures. That would also be tricky to implement in rpython.