Thursday, 22 January 2009

online javascript game, in python

Last time I spoke about pypy, which allow (among other things) to translate python code into other languages.

This week I wrote a small video game (inspired by the famous boulder dash game) in rpython and used pypy to create an online version of the game out of it.

You can play the game here.
The sources can be found here.

The game as it is now is not really fun, but I only wrote it as an example of using pypy.

What I like with this approach is that I can develop in rpython, and even run the game using python interpreter, and only before I publish it use pypy to create the javascript version.

I could also create a C version using the same code for the game engine (only the graphic functions would have to be rewritten for each backends.)

This open the door to a lot of interesting applications.

On a side note, the pypy javascript translation is really not optimised. For example, let's try to guess what this generated function does :

function (){
var v1086,v1087,self_145;
var block = 0;
case 0:
self_144 = this;
self_145 = self_144;
block = 1;
case 1:
v1086 = 'H';
block = 2;
case 2:
return ( v1086 );

I don't want to spoil the fun of figuring this out by giving the answer...

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.

Paroli get a website

Happy new year everybody !
I just come back from holidays, and haven't worked for a few weeks, but now I am back to Taipei where I still work for OpenMoko, with a few news about our next software stack :

The tichy project had a lot of modifications ; it is now entirely based on etk and edje (part of raster enlightenment windows manager). It has also been renamed "paroli-core". We loose the ability to use different graphic back-ends, but the other features are still presents. Paroli-core offers :
  • Signal / slot objects (à la Qt.)
  • A service system to allow user to register and retrieve python object based on there role.
  • A tasklet library for easy creation of chained callback function.
  • A plug-in system.
  • A set of services that create a layer between the plug-ins and Mikey FSO framework.

The Paroli project based on paroli-core started.
The project includes paroli-core (ex tichy), plus a set of applets that aim at providing basic telephony functionalities.

More information (and the sources) can be found from the paroli-project web site.