[Cython] Utility Codes and templates
Vitja Makarov
vitja.makarov at gmail.com
Mon Jul 25 08:41:45 CEST 2011
2011/7/23 Robert Bradshaw <robertwb at math.washington.edu>:
> On Fri, Jul 22, 2011 at 3:12 AM, mark florisson
> <markflorisson88 at gmail.com> wrote:
>> For my work on the _memview branch (and also on fused types) I noticed
>> that UtilityCodes started weighing heavily on me in their current
>> form, so I wrote a little loader in the _memview branch:
>>
>> https://github.com/markflorisson88/cython/commit/e13debed2db78680ec0bd8c343433a2b73bd5e64#L2R110
>>
>> The idea is simple: you put your utility codes in Cython/Utility in
>> .pyx, .c, .h files etc, and then load them. It works for both
>> prototypes and implementations, for UtilityCode and CythonUtilityCode:
>
> This sounds like it could be a nice way to organize our UtilityCode
> snippets. So far we haven't really needed any more templating than
> simple substitution, but for what you're doing I can see this being
> quite handy. This may also provide a more flexible way forward for
> supporting multiple backends.
>
>> myutility.c
>>
>> // UtilityProto: MyUtility
>> header code here
>>
>> // UtilityCode: MyUtility
>> implementation code here
>>
>> You can add as many other utilities as you like to the same file. You
>> can then load it using
>>
>> UtilityCode.load_utility_from_file("myutility.c", "MyUtility")
>
> I agree with you that having multiple related, named snippets in same
> file is worthwhile. What about
>
> ////////////////////// MyUtility.proto ///////////////////////////
>
> and
>
> ############ MyCyUtility ##############
>
> so the chunks are easy to see.
>
C++ comments looks ugly. May be it's better to have something like this:
/* UtilityCode: MyUtility.proto */
and
# UtilityCode: MyCyUtility
That's also pretty easy to parse
--
vitja.
More information about the cython-devel
mailing list