From: Stefan Behnel <[EMAIL PROTECTED]>
Date: Tuesday, Jul 22, 2008 7:41 am
Subject: Re: [Cython] Problem with multiple assignment
To: [EMAIL PROTECTED]: [email protected]

Hi,
>
>thanks for the report.
>
>Marc Christiansen wrote:
> I'm not sure if multiple assignment is the right name, but have a look
> at this code:
> 
> cdef f1():
>     cdef char a, b
> 
>     a = b = False
> 
> Cython 0.9.8 creates this:
> 
> [...]
>  *
>  *     a = b = False             # <<<<<<<<<<<<<<
>  */
>   __pyx_1 = __pyx_PyInt_char(Py_False); if (unlikely((__pyx_1 == (char)-1) && 
> PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; 
> __pyx_clineno = __LINE__; goto __pyx_L1;}
>   __pyx_v_a = __pyx_1;
>   __pyx_1 = __pyx_PyInt_char(Py_False); if (unlikely((__pyx_1 == (char)-1) && 
> PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; 
> __pyx_clineno = __LINE__; goto __pyx_L1;}
>   __pyx_v_b = __pyx_1;
> 
> [...]
> 
> If I write a = b = 0 (or a = False; b = False), the result is the expected
>   __pyx_v_a = 0;
>   __pyx_v_b = 0;
>
>This is not really a problem, more of a missing optimisation for a case that's 
>handled differently internally. It sounds like it could go away with Dag's 
>work on the assignment handling anyway. Dag?
>

The way I visioned it it would turn into

cdef object tmp
..
tmp = False
a = tmp
b = tmp

However I suppose I could handle "rhs is a simple NameNode referring to 
something which is not in the global module dict etc etc" as an optimizezable 
special case which would give

a = None
b = None

instead. So the answer is "I didn't think about it, but it is possible, but 
needs extra attention". 

(The assignment work will probably end up on pause this time around though, but 
if you want it I might get back to it at a later time. The way I would prefer 
to do it it depends on result_code refactoring, same as closures).

Dag Sverre

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

Reply via email to