Dag Sverre Seljebotn wrote:
> So:
> - Each node still flags whether it needs a result variable (i.e. the 
> is_temp of today, or rather needs_target as I'll call it from here on).
> 
> - Before the parent calls subexpr.generate_result_code, it has to check 
> subexpr.needs_target. If True, the parent must call 
> subexpr.set_target(some_cname)
> 
> - If the parent doesn't have a variable handy to put the result in, it 
> needs to allocate a temp, hand it to the child for it to store its 
> result in, and finally release the temp when the result is no longer needed.

OK, I've played with it a bit. Here's a couple of extra points. Summary: 
I'm not satisfied with my proposal, and Stefan's original approach might 
be better.

With e.g. x = ((((a + b) + c) + d) + e), and also the reverse nesting, 
the theoretical optimum is 1 temporary. My approach by default makes 
O(depth) temps, because each parent makes a new temp; while the old 
approach achieves 2 = O(1).

Now, this was easily fixed by a manual override in BinopNode, so that 
the result variable (which is known to be temp) is used as a temporary 
inside the calculation. This got the number of needed temps down to 1.

Still, that is kind of a hack (and could be broken if types were not the 
same etc., though I'm not sure if that ever happens). In general, it 
looks better to have the child allocate the temp at the place where it 
is needed.

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

Reply via email to