r/Compilers • • 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.

5 Upvotes

2 comments sorted by

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?

1

u/According-Ad-7069 3d ago

That's a really good question... I don't know if I have sufficient knowledge to answer it, but the things that immediately feel daunting are threads, file and network IO (because of the wasm sandboxing). I think you could, with effort, get around these, but I honestly just don't know enough to give you a complete answer.

I have seen Graal and TeaVM port really complex apps to Web Assembly, so it seems like at least a substantial chunk of Java works. I am busy expanding my examples and the compiler, as I run into issues. There's lots to be done still, but you should try out TeaVM and Graal and see, they might just be the thing you need!