Monday, May 30, 2011

Cython backend aiming PyPy : Week 1

During last week and the community bonding period, I tried to refine my subject by doing researches on what features of Cython can be handled and how I could implement those. To summarize, the backend aims to produce pure Python code (I decided to use ctypes to wrap C libraries as it will allow other Python implementations to use the backend). This introduces some restrictions :
  • ctypes is not compatible with C++, thus the backend will not implement any C++ wrapping functionality
  • We have to care about the ABI while the standard backend does only care about the API, ctypes can only call C functions so C macros and C global variables will have to be handled differently (probably by generating C functions returning the macros or, for some very explicit cases, inline the macro into the Python code)
On the implementation point of view, I'm currently writing a transformation which will turn extern function definition into variable assignment:
cdef extern from "foo.h":
    int bar(int, long)
will become:
bar = library.bar
bar.argtypes = [c_int, c_long]
bar.restype = c_int
This creates another problem, while the standard Cython backend leaves the linking phase to the C compiler, this backend will need the name of the C libraries to realise some kind of linking. For the following weeks, I plan to :
  • finish the "cdef extern from" declaration transformation
  • implement the "linking" phase
  • turn cdef-ed variable into ctypes objects
  • implement the pass by value mechanism
This will probably give me enough work for quite some time.

No comments:

Post a Comment