Minikotlin
4 hours ago
- #Kotlin Compiler
- #WASM-GC
- #WebAssembly
- minikotlin is a compiler written from scratch in C that directly outputs WebAssembly GC bytecode, without relying on JVM, LLVM, Binaryen, or Gradle.
- It compiles Kotlin source code (.kt files) into a running .wasm module entirely within the browser, with the compiler itself available as a WebAssembly module, eliminating the need for external toolchains.
- The compiler supports full Kotlin features including open/override methods, interfaces, data classes, enums, sealed hierarchies with exhaustive when, smart-casting, nullable types with safe calls, generics, extension functions, and coroutines with real suspension via CPS.
- Key compilation techniques include mapping each class to a WebAssembly GC struct type for property storage, implementing virtual dispatch via vtables and call_ref, compiling is checks to ref.test for smart-casting, and lowering coroutine suspension points into continuation closures without Asyncify or threads.
- The system allows writing, compiling, and running Kotlin projects directly in the browser, with features like coroutineScope managing concurrent launches and delay suspending operations handled through host mechanisms like setTimeout.