Vacation is over! I've been back for about three days now.
I ended up writing a WASM text format (or "WAT") parser in Rust over vacation, in between watching movies projected on the side of my garage, replaying Zelda: BOTW, and barbequeing. My intention was to build a tiny language runtime targeting WASM, as frequent readers will recall. I didn't quite get the parser done in that time, but I got pretty close: I finished up fixing the last known bugs tonight.
Writing a parser against a language spec is a nice, meditative experience. It involves repetitive work interleaved with research, leaving your mind free to wander inbetween reading Backus-Naur Form notation. You get the discipline of balancing letting your focus drift to the implications of your present technical decisions in the near future while reining it in to take the next smallest step in the right direction. Maybe I let my mind wander too far while writing it -- after all, I didn't get done until today, ha.
All in all, it's really not unlike the experience of drawing: a nice mix of flow state, low-commitment strategic planning, and constant tactical feedback. (I'm starting to feel the itch to illustrate again, to be honest.)
I'm working in a private repo right now; once I clean up the code a bit I'll open source it on GitHub. I think the next steps are:
- Move the parser combinators and their tests into separate files.
- Pull the AST node types up into a separate package workspace so they can be used without having to pull in the parser. (Useful if you want to compile to WASM but parse a different language.)
- Add a canonicalization method to the nodes, to handle the "abbreviations" present in WAT. (A sidenote: WAT had way more abbreviations than I expected.)
- Emit WASM from canonicalized nodes. This should be suitable for running in Node's WASI module.
- Pull in
uvwasito make a standalone runtime.
I'm starting to get a bit of RSI in my right ring finger knuckle, so it's likely that I'm going to have to take some time to let that heal. Karma for foolishly claiming that not mousing helps prevent RSI, I suppose.