C And MoonBit To WASM
C And MoonBit To WASM
Section titled “C And MoonBit To WASM”sigMAX lowers validated pseudocode to a canonical AST, then generates C or MoonBit deterministically. The selected compiler backend produces WebAssembly, and the validation pipeline checks the artifact against the Binary Contract.
The LLM-backed binary stage generates controlled pseudocode. It does not produce the final C or MoonBit source through a fallback when deterministic compilation fails.
Compilation Path
Section titled “Compilation Path”This diagram describes the Studio toolchain. COS2000’s Radjae compiler is a separate path that emits WASM directly.
The amber hexagons mark checks before lowering and after compilation. The final check reads the WASM artifact and its agreement; it is separate from creating that agreement.
The Rust tools live in studio/tools/pseudocode-compiler. The compiler worker selects the C or MoonBit backend carried by the generation job. Separate queues and images allow the backends to run concurrently.
Toolchain Roles
Section titled “Toolchain Roles”| Tool or format | Role in sigMAX |
|---|---|
| Rust pseudocode compiler | Validates the closed grammar and generates source from the canonical AST. |
| C subset | Bounded generated source using runtime/C/sigma.h. |
| Clang and LLVM | Compile C for the wasm32 target. |
| MoonBit | Alternative generated source and linear-WASM compiler path. |
| WebAssembly | Executable artifact with explicit imports, exports and linear memory. |
| WASI | Not part of the allowed business-handler import surface. |
The shared primitive catalogue is runtime/functions.toon. C headers and the MoonBit runtime library implement its language projections; the Rust host supplies the permitted host imports.
C Compile Shape
Section titled “C Compile Shape”The compiler worker uses --target=wasm32, -nostdlib, hidden symbol visibility and explicit linker exports. It exports linear memory and the handle_<name> entrypoint, while leaving declared primitives as imports.
| Compilation choice | Purpose |
|---|---|
--target=wasm32 | Emit WebAssembly rather than a native host executable. |
-nostdlib | Avoid an implicit native C runtime dependency. |
--no-entry | Build callable handlers rather than a process entrypoint. |
--export=memory | Expose guest memory for controlled host exchange. |
--export=handle_<name> | Export the handler expected by generated routes. |
--allow-undefined | Leave host functions unresolved until runtime linking. |
Allowing undefined symbols at link time does not authorize arbitrary imports. The worker reads the compiled WASM import table and rejects functions outside the catalogue allowlist, as well as forbidden non-function imports.
A missing WASM linker fails compilation with a diagnostic. Successfully compiling an object file is not reported as a runnable WASM result.
ABI And Host Access
Section titled “ABI And Host Access”The module calls explicit imports in the sigmax namespace. Typed values cross the boundary using the contract’s c_repr layout. ObjectIR builds structured JSON output, while DocIR describes documents rendered by the host.
Generated code uses bounded helpers and controlled primitives instead of direct SQL, filesystem access, raw sockets, process APIs or host secret reads. The host checks capabilities and bindings before performing an external effect.
Validation And Agreements
Section titled “Validation And Agreements”Binary validation rereads artifact bytes, checks recorded digests, parses imports and exports, requires the contracted entrypoint and rejects undeclared imports and WASI. The binary agreement links the contract, generation trace, compact and expanded pseudocode, AST, selected source and WASM artifact.
- Compile ·
wasm.compileProduce the WASM artifact. - Record ·
binary.agreementCreate the agreement with validation pending. - Validate ·
binary.validateWrite the separate report; recorded artifacts are not yet successful acceptance.
A successful compiler exit only proves compilation. It does not prove that business behavior satisfies the contract; declared API scenarios and validation reports provide additional evidence.
Execution By Edition
Section titled “Execution By Edition”Core uses the containerized Rust/Wasmtime execution path with Host and Config on the same machine. Pro uses the COS2000 executor in a KubeVirt VM under Kubernetes.
A portable WASM binary still depends on its imports, ABI and supported WebAssembly features. The current Wasmtime path and the COS2000 executor must not be assumed interchangeable without compatibility validation. The inspected runtime checkout does not contain the complete Pro integration.
See Pseudocode DSL and WASM execution boundaries.