Which Programming Languages Have Compilers That Can Run as WebAssembly?
Asked by
VelvetKite42
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.
Answers
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.
Reply to this answer
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.
Reply to this answer
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.
BriskLemon8: 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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
VelvetKite42: Iโm already using that runtime. The part Iโm still trying to solve is finding a language compiler that can run inside it.