Stefan Behnel wrote:
> Hi,
> 
> thanks for doing that.
> 
> Dag Sverre Seljebotn wrote:
>> Just a quick note that in the gsoc-kurt branch I've implemented this:
>>
>> from UtilityCode import CythonUtilityCode
>>
>> ...
>>     env.use_utility_code(foo) # only on env. currently, not code.
> 
> That's too bad, because 'code' is where it belongs.
> 
> I assume the environment is required to define the utility code? In that
> case, what about splitting it up, so that 'env' can be used to define
> (parse/analyse/compile) the utility code snippet, but 'code' provides the
> functionality to actually use it? (so that it won't turn up in the code if
> the code generation decides not to need it)

I definitely see this as "one step along the road"; in the end I really 
want to be able to use this on code. Not now though.

(It's really just about how ModuleNode is currently used to generate 
code -- I just copy the nodes in there before the code generation 
starts, similar to how inline code in pxd files are handled. This is a 
hack, I definitely see ModuleNode refactored at some point.)

Perfect is the enemy of good.

>> foo = CythonUtilityCode(u"""
>>
>> class __Pyx_UtilClass:
>>      pass
>>.
>> cdef int __Pyx_UtilityFunction(int arg):
>>      return arg * 2
>>
>> """)
>>
>> Now, this will cause __Pyx_UtilityFunction to be dumped into the final C 
>> file, and the type descriptor to be called __Pyx_UtilClass (i.e. name 
>> mangling is dropped in some important cases).
> 
> Sounds hairy, but I think that makes sense. You have to know the name to

What prompted me to it is that in the current C utility code, it works 
the same way. I would really like name mangling and what kind of method 
was used to generate utility code to be orthogonal concepts.

I added a "prefix" keyword argument BTW, above one could pass 
prefix="__Pyx_" and then define "cdef UtilityFunction" to get the same 
result.

> call the function after all. We could provide the utility code with a way
> to mangle names, though. The code generator could then call into it,
> instead of knowing the mangled name, so that
> 
>       my_utility_code.mangle("UtilityFunction")
> 
> would return the above "__Pyx_UtilityFunction", or whatever the compiler
> decided to use as name.

Hmm. I'll think about it and see.

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to