AST to WebAssembly, Writing a Code Generator
- Author
- Paul Bone
- Conference
- Compose :: Melbourne
- Date
- August 27th, 2018
- Slides
- Slides
- Video
- YouTube
Abstract
Ever wonder how your compiler translates your program into machine code but worried that this was some eldritch knowledge, lurking in the depths of compilers where undergraduates fear to tread? Well it's not, and although it's a deep topic, the basics are fairly basic.
The WebAssembly MVP is now available in almost all browsers (except IE) providing a fast virtual machine right in your browser. Opening up the web for strong & statically typed functional programming languages*. This presentation will show a simple and elegant code generator that generates WebAssembly from an abstract syntax tree (AST) for a ML-like language. Furthermore the basic algorithm is so straightforward you'll be filing PRs against your favourite compiler next week!*
* Almost: The WebAssembly MVP leaves a couple of really awesome features unimplemented, but it won't be long and these problems will be solved too. We just want to make sure you're ready.
Video
Resources
- My WebAssembly code generator as presented in this talk
- Web Assembly website
- WebAssembly Specification
- Wasm text format examples
- API docs (MDN)
- Wasm Assembler
- I also found, but didn't use the Wasm Haskell package