Vitja Makarov, 27.11.2010 08:24:
> 2010/11/24 Stefan Behnel:
>>>>> you simply cannot currently define a function more than once within
>>>>> a namespace because it is looked up statically. So, when you redefine it,
>>>>> its Python name would get overwritten in the symbol table. So you couldn't
>>>>> refer to the previously defined function anymore from that point on, which
>>>>> means that you cannot even use it in the code that gets executed before 
>>>>> the
>>>>> redefinition. The symbol table is not dynamically adaptive to the position
>>>>> in the code, it's just a plain table that is global to a namespace.
>>
>> I took a deeper look and came to the conclusion that it will be easier to
>> do this at the same time as the split of Python functions into a Python
>> variable name, a Python function wrapper and a C function.
>
> How does that work? What is Python function wrapper?
> Is that described in generators CEP?

Yes, it's described in that CEP. Currently, cpdef functions create a 
DefNode internally. The idea is to actually represent *all* Python 
functions (and methods) as a C function with the correct signature, and a 
Python wrapper function that does the argument unpacking and return value 
conversion. There shouldn't be a performance difference as the C compiler 
can inline the C function into the wrapper if it thinks it's worth it. 
However, this has several advantages:

* it moves the lengthy argument unpacking and error handling code out of 
the actual function body, thus making the C code more readable.

* it restricts the inner C function code to what is really needed 
(including temp variables, visible arguments and exit points), which may 
make it easier for the C compiler to optimise it.

* it makes the inner C function directly callable, thus making it easier to 
implement things like cpdef functions and generators on top.

* it (likely) simplifies the code in the compiler, as the DefNode will get 
stripped down to handling the argument unpacking and Python name assignment 
(and maybe some glue stuff), and can delegate everything else to a plain 
CFuncDefNode.

This has been on the list for a while now, but no-one has started any 
serious work.

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

Reply via email to