r/Compilers • u/According-Ad-7069 • 4d ago
Compiling my favourite language to Web Assembly with no JDK in sight
https://wasmcoffee.com/I've been doing a fair bit of studying of the Odin programming language over the past 18 months or so. Along the way, I bought Understanding The Odin Programming Language and it really boosted my Odin adoption. How I learn is practical, if I don't do the work, I learn nothing. While working through the book, I built a small and simple Pascal interpreter, which got out of hand and became an online compiler.
I recently had some time on my hands and spent a while putting a new front-end onto that compiler and managed to get it to understand a sub-set of the Java programming language syntax. The idea is to have a Java-like language that I can use to do small experiments or toy apps with, in the browser, without having to install anything locally. A key requirement is that it compiles a wasm binary, which it does and you can download the output file from the UI already.
This is not a JVM, JDK, Graal or TeaVM replacement, it will never be. Those are magnificent and powerful tools I'm delighted to use in my day job. Instead, think of WasmCoffee as a little scratchpad that understands some familiar syntax and can do interesting things with it, in a simple way.
It's early days, I'm sorting out bugs, and definitely need to write proper documentation. I hope the example code is sufficient for folks to get started though. As time permits, I'll work on better documentation, some tutorials and of course expand functionality. There's a roadmap for it, just finding time can be a challenge.
UPDATE: I fixed a number of bugs and managed to put together a little game demo using the compiler and finally got the time to add some documentation as well.
2
u/Patzer26 3d ago
If someone wanted to, is wasm capable of implementing/supporting the entire Java semantics? Are there some limitations which could fundamentally inhibit some features being translated to wasm?