Friday, July 9, 2010

Various types of arguments and cache

Good news!

So, I have finally managed how to omit the limitation of RPython to pass arguments of various type to the called functions. The limitation was due to passing the arguments as a list (which has to have elements of the same type in RPython). Instead of this, internally the jitffi module fishes elements from the passed list (this is a wrapped list from app-level) and pushes them directly to the calling stack.

I have added a simple cache for compiled loops. It's a bit primitive but it works. Simple, once the loop is compiled it has been stored in the cache and then before the whole compiling operation, we check if there is already compiled code (if the result type and arguments are the same).
It still needs some extra work, e.g. once we pushed something to the cache, it has never been removed from. So the cache can grow infinitely. I will try to add some cleaning operation later. It's not really important for now.

And this week..

I will continue my work to have C pointers working as arguments for calling functions.

That's all.
Have a nice weekend!

Monday, July 5, 2010

What have I done... far :)
As you see I'm not really into blogging however I would like to share about the progress with PyPy - fast ctypes project.

The code lives in a branch at codespeak and you can simple take a look at:
or even better check it out:
svn co

What is already done?

I guess not too much :-) I've started a new Foreign Function Interface called jitffi which you can find in pypy/rlib/ For object space go to pypy/module/jitffi/. It uses the PyPy JIT to call functions.

With this module we can simply load dynamic C libraries and call functions from the loaded library. There are some limitations such as all function arguments have to be the same type. Other limitation is that jitffi supports only int and float types (and void obviously) so far.

Here is a sample to see how we can use it:

import jitffi
lib = jitffi.CDLL('')

func = lib.get('func_name1', ['int', 'int'], 'int')[1,2]) # return int

func = lib.get('func_name2', ['int'])[10]) # return None (as it's equivalent to C void)

This API is completely unstable and changes are made from time to time, or rather from commit to commit :-) The best way is to check appropriate tests to see the current API and how to use it.

What am I doing now?

The next step is to drop the limitation of same type of passing arguments. The problem is that the RPython lists can store only elements of the same type in one instance.
The idea is to fish the passed arguments from app-level and push it onto the stack. I'm working on it now.

Next? The PyPy JIT supports ints, floats and pointers. So, I will go to give a support for the latter.

This is it. The plan for the next week.