DEV Community

Cover image for Luna πŸŒ™ - Wrote a tiny WebAssembly compiler, that also runs in browser, built for demonstrative and educational purposes.
Thomas Albertini
Thomas Albertini

Posted on

Luna πŸŒ™ - Wrote a tiny WebAssembly compiler, that also runs in browser, built for demonstrative and educational purposes.

I've been wanting to learn how to make my own programming language for a really long time, but I could not find the road in the hard theory behind compilers, parsers, ASTs etc... I found the tutorials hard and my attention was not lasting for more than 5 minutes before completely shut down the project.

Some days ago, though something changed.
I'm currently in love with WebAssembly and had this absurd idea of developing a programming language that compiles to WebAssembly.

I didn't know how WebAssembly internals worked so it was the perfect stage to learn something new and make a cool project.

Sold!

Started doing some researches and I found no tutorials except two amazing articles, one was how to build a compile for a custom programming language that compiles to WebAssembly (exactly what i was looking for), the other was a series of articles on how to build a Web assembly compiler (exactly what i was looking for, again!)

But here come the problems: the first was written in Typescript and the second in Rust.

I wanted to practice Go and I don't know anything about Rust.

So long story short I studied the theory behind those two amazing articles, WebAssembly specification etc... and I started writing a compiler in Go (i love Go).

I've really found no articles about writing WebAssembly compilers with Go, so I decided to document the building of Luna so future Gophers that will have my same idea won't have to struggle as much as I did to find resources.

Luna screenshot

Luna mainly compiles WebAssembly Text Format to Wasm, but with small modifications in the tokenizer and parser, it could also serve as a blueprint for developing custom programming languages in the browser that compile to WebAssembly.

So this is Luna and in this series of articles I will explain EXACTLY how I built it.

Meanwhile you can have a look at:

Luna is really tiny and it's in early stage, feel free to contribute (update docs, open PR, issues, leaving feedback or suggestions etc...), anything is welcomed!!

Top comments (0)