Risks and alternatives
Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.
13 notes
Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.
Testing strategy: differential testing against vm3, BG corpus, fuzzing, sanitiser matrix (ASan/UBSan/TSan/MSan/LeakSan), property tests, reproducibility check, 16 phased CI gates.
Build pipeline: `mochi build` command surface, output layout, amalgamated runtime, cross-compilation via bundled zig cc, APE via cosmocc, WASM via wasi-sdk, content-addressed caching, reproducibility.
Lowering Mochi `stream<T>`, stream definitions, `on`-handlers, agent records, and `intent` methods, plus the M:N work-stealing scheduler over minicoro fibers that runs them.
Lowering the Mochi query DSL (LINQ-style from/where/select/join/group by/order/limit/union/intersect/except) to C with arena allocation, operator fusion, and load/save adapters.
The C target itself: C23 features used, compiler matrix (clang, gcc, msvc, zig cc, cosmocc, tcc), tier-1/2/3 architectures and OSes, ABI per arch, libc matrix, sanitisers, reproducibility, hardening, style guide for emitted C.
Type-system lowering details: generics/monomorphisation, records, sum types with niche optimisation, closures with fat pointer, strings with SSO, lists, maps with Swiss-table, sets, time/duration, error values with built-in code table.
Codegen pipeline, why a C IR, name mangling rules, type-lowering table, value representation with `mochi_value` boxed type, expression lowering, statement lowering, for-loop lowering, try/catch via setjmp, Maranget pattern matching, modules, amalgamation.
Inventory of the third-party and home-grown components the C runtime can stand on: GC (BDWGC, MMTk, Perceus), allocator (mimalloc, scudo), coroutines (minicoro), I/O (libuv, libxev), strings, hash tables, JSON/YAML/CSV, HTTP, LLM, FFI.
Survey of transpilers and AOT compilers that emit C or behave like a C-target system: Nim, Crystal, Vala, OCaml, Roc, Koka, MLton, Cosmopolitan, zig cc, Cython, ATS, Soufflé. Twelve distilled lessons.
The five guiding principles behind the Mochi-to-C transpiler (spec-first, boring C, no ABI surprises, portability over performance, verifiable output), plus the runtime shape and a sample C output.
Every Mochi construct the MEP-45 codegen must lower: value core, function core, collection core, ADT core, query DSL, stream/agent core, logic, AI/FFI, tests, modules, error model, concurrency semantics.
Research substrate for Mochi MEP-45 (May 2026). A 12-file deep dive into ahead-of-time transpilation from Mochi to ISO C23: language surface, design philosophy, prior-art transpilers, runtime building blocks, codegen design, type-system lowering, C-target portability, dataset pipeline, streams and agents, build system, testing gates, and risks.