In earlier articles, we implemented a
tokenizer and parser to convert Wasm’s WAT syntax into an S-expression abstract
syntax tree and started to implement a transformer to convert that AST into one more
suitable for generating Wasm bytecode.
Now that the boilerplate is in place, this article will continue to implement
recursive transformer functions, getting into some of the more complicated
expressions in the “hello world” WAT example.
I should mention that the code in this article gets long and repetitive. I’m
including all the code we’ll need for the hello world example, but if you feel
like it’s getting a bit boring, feel free to skim bits of it! I now understand
why most “introduction to compiler” articles focus on such a tiny amount of
syntax! I feel committed now, though, so if you’re willing to bear with me,
we’ll see this through to the end.
Continue reading