back2dos/tinkerbell — pull request #8 by Simn (2012-03-30 22:43:04+00:00)
Title: Expression mapping with variable declaration context

Hey Juraj,

I just added ExprTools.map to my fork of tink. It serves two purposes:
1. Traditional top-bottom traversal of expressions as opposed to the inside-out approach of crawl.
2. Preservation of a variable declaration context.

The idea is that it calls the mapping function with the current expression and context as arguments and then, if the function didn't change the expression, recursively maps all sub expressions. This approach made it really easy to implement the transform function of overload-operator:
https://github.com/Simn/overload-operator/blob/tink/src/deep/macro/math/OverloadOperator.hx#L83

It just handles the expression types it cares about and leaves the rest to ExprTools.map, which includes handling of the declared variables so expressions using them can be properly typed.

I know the function is way too big to actually reside in ExprTools, but I couldn't really decide where to externalise it to and just kept it there for now. I'm also not entirely happy with the signature because providing an array after the function looks pretty strange, so this could be changed.

Hope you find this useful.