Initial work on making AST more visitor-based

The current method of traversing the AST is way too chaotic and ad-hoc,
so I'm starting to rewrite into a visitor-based API.  This is largely
inspired by the 'ast' module in Python, and should allow for a more
reusable, less crazy method of transforming the AST.