Self contained toy language -> wasm compiler in Rust?

Is there any good example of a "self contained" "toy language" -> wasm compiler written in Rust ? I'm mainly looking for a starting point to play with.

By "toy language", I mean something atleast as high level as C (i.e. not assembly).
by "self contained", I mean: does not rely on LLVM or Cranelift for optimization passes.

I don't know of any such thing. As a staring point you could read "Let's Build a Compiler, by Jack Crenshaw": Let's Build a Compiler and devise your own simple compiler that generates WASM.

I don't know what level of sophistication you are starting from. Crenshaw's exposition is very basic but at lest detailed and complete enough to make something actually work.

Suited me just fine a few years back when I work through it and ended up generating code for x86 and the Parallax Inc. Propeller micro-controller.

If nothing it's a nice discussion of language design choices.

1 Like

This is valid, but not what I'm looking for. I've taken compiler courses before in College going through the parsing, (minimal) type checking, Static single assignment form - Wikipedia , simple optimization (evaluate constants), and emitting some basic assembly code ( MIPS architecture - Wikipedia ? I forgot).

The main thing I'm looking for is not compiler theory, but a minimalist end to end working system, so instead of figuring out how to do foo with library bar, there's already existing code doing that work. In particular, I suspect there is a lot of 'boiler plate' code involved for any self contained "toy language -> wasm" compiler.

Something like Tiny C Compiler - Wikipedia , but written in Rust, and outuptting wasm, would be ideal.