« All posts

Minikotlin: A C-Written Compiler That Emits Kotlin as WASM-GC

Minikotlin compiles Kotlin directly to WebAssembly GC bytecode using a C-written compiler with no JVM, LLVM, or Binaryen dependency.

Minikotlin is a from-scratch compiler written in C that turns Kotlin source directly into WebAssembly GC bytecode. It skips the JVM, LLVM, Binaryen and Gradle entirely — the compiler itself is compiled to WASM, so it runs in a browser tab with nothing to install.

The pipeline runs its own frontend (mkf: lex/parse/sema) through two hand-built intermediate representations, HIR and MIR, before codegen emits WASM-GC bytecode by hand. Classes lower to struct.new, virtual calls go through call_ref via per-class vtables, type checks compile to ref.test, and coroutines are lowered to CPS closures without Asyncify or JSPI — genuine off-stack suspension.

Supported language features include inheritance, sealed classes with exhaustive when, null safety, generics, operator overloading, extension functions, and real coroutine suspension — backed by 366 end-to-end tests and 657 frontend tests. It's a properly lowered implementation onto the WASM-GC type system, not a stripped-down subset of the language.