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

3

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!!

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series ๐Ÿ“บ

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series ๐Ÿ‘€

Watch the Youtube series

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay