Compile decorator

The PyPy project has some very nice things in it. Among those things is the translator module. The purpose of this module is to compile a restricted subset of Python (RPython) into C and other lower level languages. Within the PyPy project, the translator is used to compile the PyPy interpreter. However, it is also possible to compile individual Python functions at runtime and dynamically execute the compiled function. The translator module makes this task very easy. I have written a class which allows using the compiled version of a Python functions simply by adding a decorator to the function:

@compdec
def foo(x, y):
    return x + y

The nice thing about doing things this way is that all the code is pure Python code, and switching between the compiled and uncompiled version of the function is as simple as possible. You can find the definition of this decorator on my personal enthought site.

2 thoughts on “Compile decorator

  1. avatarDogan

    I’m very interested in hard core approaches to optimizing Python code and I think this is a great idea but the link is broken, I can’t find much about this project anymore. 🙁

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 100,994 bad guys.