[Cython] Compile-time macros

Stefan Behnel stefan_ml at behnel.de
Sun Mar 9 15:39:30 CET 2008


Hi,

Martin C. Martin wrote:
> So if we could introduce the concept of a special kind of function, 
> which is run at compile time, and which takes the (unevaluated) parse 
> trees of its arguments, instead of the runtime values of them, we could 
> probably have something equivalent to Lisp macros.  A macro would be a 
> lot like transforming an XML DOM into another DOM, except instead of XML 
> it's a parse tree.

That reminds me of compile-time decorators. Imagine you could write something like

    @cython.memoize
    def dostuff(a,b):
        ...

(special casing the 'cython' prefix here) and Cython would call memoize() with
the *parse tree* of dostuff() as parameter. That would obviously use the same
infrastructure as compiler plugins, but it would allow you to explicitly run
plugins on your code.

Stefan


More information about the Cython-dev mailing list