I'm designing a Minecraft mod that adds programmable computers and other devices, somewhat differently from ComputerCraft or CC:Tweaked. I'd like to use WebAssembly as the execution format, but I also need players to edit and compile code inside the game. That means the compiler itself must be able to run inside a WebAssembly runtime. Are there relatively simple languages with usable, maintained compilers available as .wasm modules? I'm aware of projects such as clang.wasm, but I'd like to know what other options exist.
3 Answers
A WebAssembly compiler is rarely completely self-contained. It may need filesystem access, environment APIs, or other host functions to read source files, produce output, and manage temporary files. In a game mod, those APIs would need to be provided by Java or by the WebAssembly runtime. In principle, any compiler written in a language that can target WebAssembly could itself be compiled to .wasm, but making it practical may require substantial shims and runtime support.
TinyGo is one possibility, and there are several other language toolchains that can target WebAssembly. However, there doesn’t seem to be a single complete, well-maintained catalog of compilers that are themselves distributed as .wasm files. You’ll probably need to check each project’s build setup and determine whether its compiler can be built for WebAssembly.
If you’re using the Java edition of the game, Endive may help with the runtime side. It’s a WebAssembly runtime and compiler implementation written in Java, so it can potentially be embedded directly into a mod. It doesn’t answer which source languages you can compile, though—you still need a compiler for the language you want players to use.
I’m already using that runtime. The part I’m still trying to solve is finding a language compiler that can run inside it.

That also means a compiler written in Java might be easier to integrate with the mod than a large native compiler ported to WebAssembly, depending on how much host functionality it expects.