Stefan Behnel wrote: > Stefan Behnel wrote: >> Dag Sverre Seljebotn wrote: >>> When it comes to FlattenInListTransform, I was thinking about something >>> along the lines of an "StatAsExprNode", which would be sort of the >>> inverse of ExprStatNode: It would contain a block which could contain >>> "ReturnFromStatAsExprNodeNode" (though a better name is needed :-)) >>> which would yield the value of the statement list, evaluated as an >>> expression. >> I thought about this, too. The main problems with TempsBlockNode are that >> it a) requires the type of a temp variable before hand (which is bad for >> transforms that run before type analysis), and b) is a block statement, not >> an expression. Making it an ExprNode and moving the current use into a >> ExprStatNode would fix that. > > I added a new node in UtilNodes that handles this. It's called > EvalWithTempExprNode - better name pending. > > The idea is that you wrap an ExprNode in a EvalWithTempExprNode and replace > the expression node that is used more than once inside the ExprNode with a > ResultRefNode. The ResultRefNode will copy its type from the original > expression during type analysis, so that it doesn't need to know it at > creation time. The TempBlockExprNode then sets the result_code of the > ResultRefNode after evaluating its expression and before evaluating the > original ExprNode that needs the result. That way, evaluation of the > expression and its use are separated by the EvalWithTempExprNode which can > handle the temp allocation as required.
Very nice! I don't have time to dive into the finer points of this yet, but some thoughts: - It took me some minutes to understand the concept. I definitely think another name (as you suggest) would help a lot and perhaps make the concept immediately graspable. How about "LetNode" for EvalWithTempExprNode? (I don't have a good suggestion for the reference node, "LetRefNode" or similar in lack of something better). - It seems to mostly be "TempsBlockNode" except with a different (better?) API and designed to work as an ExprNode. Is it redundant with both? I.e. "LetNode" could perhaps implement both interfaces and play the role both as ExprNode and StatNode. (No hurry though!) -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
