News for hackers. Stuff that matters.
Re:Want to Write a Compiler? Read These Two Papers (2008) by ky3 on Thursday December 24, 2015 @09:04AM (#10788162)
> Yes, I am using this approach exclusively.

Earlier you wrote that "And if you worry about performance, your compiler can fuse passes together in many cases."

What kind of fusion do you use in your approach?

In the last paragraph of Keep's thesis, he mentions pass fusion, citing Wadler's 1988 work on deforestation. Keep does not, however, give a working implementation.

I know of no-one doing nanopass fusion, but I'd love to be corrected.

Re:Want to Write a Compiler? Read These Two Papers (2008) by sklogic on Thursday December 24, 2015 @09:19AM (#10788209)
I'm not using Nanopass directly, I've got my own similar framework (developed independently).

It is using an IR which allows to easily compare the visitor shapes (i.e., source AST, target AST, traversing order, omitted nodes), and if they do match and the second pass is not using results of any of the collectors from the first pass (too long to explain what collectors are, treat them as a kind of a constrained side effect), corresponding visitor nodes are chained together.

Deforestation is supposed to work on much lower level, and I'm not sure it's possible to deduce the original visitor shapes and traversing order from an already lowered code.

A previous version of this framework is available on github, username 'combinatorylogic' (it does not provide fusion or any other optimisations, because it's dynamically typed; A glimpse of the IR of the next version can be seen in the recform AST library, see 'ast2-...'). The current version will be published soon.

Re:Want to Write a Compiler? Read These Two Papers (2008) by ky3 on Thursday December 24, 2015 @09:43AM (#10788291)
The repo looks to be here:

https://github.com/combinatorylogic/clike

Because you have a functional and also imperative language (pfront?) that your compiler is written in, you avoid memory churn by ensuring "visitor nodes are chained together", is that right?

So pass fusion for compiling clike does away with the destructive matching and rebuilding of untransformed subexpressions by linking pointers back to the original.