Lua to WebAssembly Compiler

In the first term of my Master’s, I took the course CS 842: Advanced Topics in Language Design and Implementation. The course was broken down into 3 components: 20% participation, 40% a presentation, and 40% a project. The project specification was to implement a significant programming project of our own devising, with approximately 1 day of work per week for up to 2 months. Example projects included:

My project, that I negotiated with the professor Stephen Watt, was to build a compiler for a subset of Lua to WebAssembly. I was interested in doing something with WebAssembly, since I have professional experience in web development but never had the opportunity to experiment with WASM before. I chose Lua because it is a relatively small language, and one that I have a decent amount of experience with thanks to lots of game development I did as a teen in the Löve framework.

A short demo video I created for the project follows:

I had a few goals with the project:

  1. Write a compiler for a dynamically typed language. My previous experiences in writing compilers consisted of implementing statically typed languages.

  2. Write a garbage collector. My experience in compilers so far came from course work, which always allowed us to assume an infinite amount of memory.

  3. Learn the intricacies of the WebAssembly platform and its virtual machine.

Overall, I would say I achieved each of these goals. I was able to implement the following features in my compiler and associated runtime:

A full description of the inner workings are available in this documentation PDF

And all of the source code is available in the following Github Repo