On 2010-06-27, at 11:47 PM, chevalma@iro.umontreal.ca wrote:
Marc, I saw you made some commits on git, one with the comment:
"Implement AST walker and free-variable analysis (for closures)"
Is the actual closure conversion done? Is your code ready for me to work on the AST->IR conversion.
I'm just asking because I assumed this wasn't the case and have been working on other things instead.
Yes it is ready for you. There is no closure conversion per se. Each FunctionExpr node has a free_vars field which contains a hash map of all the free variables of the function (the variables from the enclosing scope which are referred to by the function). Those are the variables that need to be stored in the closure object. Depending on the implementation strategy, you may want to remove the top level variables from the free_vars (if there is only one global object... note that this may not be the case in a multi-thread JavaScript). For now just remove them... but keep in mind if tachyon ever goes multi-thread.
You'll probably want to do a mutation analysis also. The reason this is not done at the AST level is that you have said you want to do optimizations at the IR level. Some optimizations (such as dead-code elimination) may remove some mutations, and thus, some variables are no longer mutable after optimization. Also, some variables may not be free anymore either. This is why I feel that doing optimizations at both the AST and IR levels is pointless (redundant/incomplete). But because the IR representation is low-level, it will be hard to do some optimizations (we've had this discussion before... I remain skeptical about the depth of transformations/optimizations we can do at the IR level).
Marc