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


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

Reply via email to