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

da-woods dw-git at d-woods.co.uk
Thu Feb 25 14:20:44 EST 2021


> 1. I'm not sure why there would be any dependency on a C compiler in
> either mine or Celelibi's proposal. Could you please elaborate? At
> least in my proposal, we only ever go from Cython AST to Cython AST
> and use Python to do it. None of these things require a C compiler.
To me it looked like Celelibi's proposal was basically asking for "some 
subset" of regular Cython code to be evaluated at Cythonization time. 
Since evaluation of Cython code requires compiling the C code first, it 
seems to me it'd need a C compiler. It depends on the subset of course. 
I agree that your suggestion of modifying the AST can/should be done in 
Python.
> 2. Again I can't speak for Celelibi but my proposal would be
> compile-time only. I'm happy to add restrictions (decorators on cdef
> functions only or maybe even special syntax) to ensure that this is
> the case.

The D-language which Celelibi linked as an example claims "All functions 
that execute in CTFE must also be executable at run time. The compile 
time evaluation of a function does the equivalent of running the 
function at run time" and Celelibi didn't seem to be proposing any 
special syntax. So on that basis I don't see where any compile-time only 
restrictions can come from.

It's quite possible that I've missed the point of the proposal in both 
cases though.




More information about the cython-devel mailing list