[Cython] [ENH] Compile-time code execution (macros / templates)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 26 00:13:13 EST 2021


On 26/02/21 3:21 pm, Celelibi wrote:
> def twice(f):
>      fun = CdefFunction(... use f ...)
>      return fun
> 
> foo = CdefFunction(...)
> ast.append(AstCdefFunction("foo", twice(foo)))
> 
> I think this might even be doable without having to even detect the
> closure in cython. We'd just have to let python perform the name lookup.

The cdef function created inside twice() is going to have
to be some kind of closure, because it needs access at run
time to the particular f that was passed to twice() at
compile time.

-- 
Greg


More information about the cython-devel mailing list