On Sep 24, 2008, at 3:09 PM, Dag Sverre Seljebotn wrote:

> Thanks to Robert's recent work with result_code (thanks!), I'm able to
> clean up some long-standing transform issues with temps.
>
> I've been wrong about such approaches before so I thought I'd check by
> if there are any opinions before I push to -devel.
>
> The solution I coded up is that one can create a TempsBlockNode which
> allocates temporaries during code generation, and use them by using a
> TempRefNode. (This is then used in TreeFragment, one can see the  
> effect
> on slightly cleaner generated "with" statement C code.)
>
> Example:
>
> tempblock = TempsBlockNode(pos, [PyrexTypes.c_int_type,
>      PyrexTypes.py_object_type], body=None)
>
> tempblock.body = SingleAssignmentNode(pos,
>      lhs=tempblock.new_ref_node(1, pos), rhs=node)
>
> i.e. tempblock.new_ref_node is used to construct a TempRefNode which
> magically refers to a temporary which was set up by the TempsBlockNode
> (this is done by sharing a simple handle). The argument to  
> new_ref_node
> is the index of the temporary (which is created by the type at the  
> same
> index in the list given to the constructor).
>
> TempRefNode can be used in roughly the same situations as a NameNode
> referring to a local typed variable (i.e as an expression and as an
> assignment target).
>
> See:
>
> http://hg.cython.org/cython-dagss/rev/28b0311d6bff

I think this is a nice approach that could clean up a lot of stuff.  
(In particular, I think we could get rid of almost every CloneNode  
and the (admittedly somewhat hackish) PersistentNode.) The one thing  
I would change is having to refer to these handles by index into a  
list passed at creation time. I would rather have an interface  
something like

     tempblock = TempsBlockNode(pos, body=None)
     foo = tempblock.new_temps(PyrexTypes.c_int_type)
     a, b = tempblock.new_temps(PyrexTypes.py_object_type,  
PyrexTypes.py_object_type)
     tempblock.body = SingleAssignmentNode(pos, lhs=foo.ref(), rhs=node)

Actually, it does feel a bit weird setting the body after it is  
created. What about

     foo = TempRefNode(PyrexTypes.c_int_type)
     body = SingleAssignmentNode(pos, lhs=foo.ref(), rhs=node)
     return TempsBlockNode(pos, body=body, temps=[foo])

- Robert

P.S. When I mentioned incremental temp migration,  
FunctionState.allocate_temp is exactly what I had in mind. Nice.

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

Reply via email to