Tuesday, September 28, 2010

RPythonic

RPythonic takes in C code and outputs three different formats: 1. pure RPython code, 2. ctypes wrappers, and 3. rffi wrappers. Using the PyPy translation toolchain the pure RPython code can be translated back to C, or C# and Java (allowing your C code to be executed by .Net or Java runtimes). The generated ctypes wrapper can be used from CPython. The rffi wrappers allow you to use C code from RPython. RPythonic is built using PycParser, a powerful C parser written by Eli Bendersky written in Python.

Why not Pygccxml?
Pygccxml is made up of about 50 files and several thousands of lines of code, totalling about 1MB of code; and relies on the external program Gccxml. Gccxml is old and development has stalled. Another automatic binding generator Pybindgen uses Pygccxml, and the interface between Pybindgen and Pygccxml alone is over two thousands lines of code, not pretty!

PycParser is super clean, 10 files, less than 150KB of code; is pure Python and relies on no external programs. While Pygccxml can parse C/C++ code, it can not parse the function bodies. On the other hand, PycParser can fully parse C and function bodies, but not C++. For RPython and ctypes wrappers we are only interested in C; and because PycParser can fully parse C, translation of C to RPython is also possible at the same time the bindings are generated.

RPythonic on google code

3 comments:

  1. My goodness... this is the project I've been looking for, for a while :)

    If it could generate ctypes wrappers for pygi libraries as well I think I'd have it's babies :D

    ReplyDelete
  2. hi Stuaxo,

    I have tested RPythonic with GTK, it works. I have also started writing a by-hand PyGTK-like wrapper on top of ctypes-gtk generated API, called minigtk.py, have a look at test2.

    http://rpythonic.googlecode.com/files/ctypes-gtk-test2.tar.bz2

    ReplyDelete
  3. Cool, I'll have a look at the ctypes gtk stuff when I get a spare moment.

    I made some progress towards a pycairo style using ctypes, rpythonic looks like it might be a pretty good base for that, at the moment I'm using ctypes-codegen.

    ReplyDelete