2010/11/24 Stefan Behnel <[email protected]>:
> Stefan Behnel, 12.11.2010 22:07:
>> Vitja Makarov, 12.11.2010 16:28:
>>> 2010/11/12 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.
>>>>
>>>> This is a compiler, not an interpreter. Things don't simply happen in the
>>>> order they are executed in the code.
>>>>
>>>> Does that explain it?
>>>
>>> Can you show me where is static lookup performed?
>>
>> See the Entry class in Symtab.py, it holds the information about declared
>> names and their types.
>>
>>> Is this cython level lookup or C-level?
>>
>> Cython. Mostly during type analysis, but potentially also in the type
>> declaration phase and other places.
>>
>>> Can you show me example?
>>
>> You will find tons of places that call "lookup()" (recursively) or
>> "lookup_here()" (non-recusively) on the current scope. Take a look at the
>> three call node classes, for example.
>>
>>> Btw, if we see that function is redefined we can mark it as
>>> "overrided" and use special more dynamic rules to handle that (create
>>> it in runtime,  don't declare it in methods list and so on)
>>
>> Sure. I didn't say we lack solutions. It just needs to be done. And this
>> isn't trivial enough to be done within a couple of days, so no-one has
>> started working on it.
>
> 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?

> The trivial hack to allow name redefinitions almost works when using a
> unique cname. However, the problem is that the symtab entry of the function
> node is the same for the function definition and the Python variable.
> Ideally, the function definition entry shouldn't be stored in the symtab
> dict at all, and the name should be declared independently with a simple
> variable entry of py_object_type (unless already declared, in which case
> the variable entry can be reused but not the declaration entry).
>
> Stefan

I'm now trying to make "module scope lambda" work.
That's almost done.

I see that needs_assignment_synthesis() should be forced to create
PyMethodDef struct.
Now I do it this way:
def needs_assignment_synthesis(self, ...):
.....
             if self.name == '<lambda>':
.....

Seems like a dirty hack.

Also lambda function is defined in module methods table as
__pyx_lambda_funcdef4lala_lambda1,
Is it safe not to add lambda cname to pyfunc_entries in
Scope.declare_lambda_function()?

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

Reply via email to