Internals · 01

Language Architecture

Overview of Ochre's 8-crate Rust compiler workspace, compilation pipeline from source text to VM bytecode, Cranelift machine code, LSP, and WebAssembly.

Ochre is organized as a modular 8-crate Rust Cargo workspace. Every stage has a narrow responsibility and clean public boundaries, allowing the exact same frontend (ochre-syntax + ochre-types) to power the CLI, Bytecode VM, Cranelift AOT compiler, Language Server, and WebAssembly browser playground.

Compilation Pipeline

Source (.och)
   │
   ▼
ochre-syntax   ──► Lexer (tokens + comments) ──► Pratt Parser (AST) ──► Formatter
   │
   ▼
ochre-types    ──► 3-Pass Static Type Checker + Exhaustiveness + SymbolTable
   │
   ├──► ochre-vm       ──► Bytecode Compiler ──► Stack VM (CoW Arc + OS Threads)
   ├──► ochre-codegen  ──► Cranelift IR ──► Native .o Object ──► cc Linker
   ├──► ochre-lsp      ──► stdio LSP Server (Diagnostics, Hover, Completion, Format)
   └──► ochre-wasm     ──► wasm-bindgen Playground Bundle (VM + Formatter)

Workspace Crate Map

CrateResponsibility
ochre-diagnosticsByte Spans, Diagnostic builder, and ariadne terminal rendering
ochre-syntaxHand-written lexer, comment collector, Pratt parser, AST, and idempotent formatter
ochre-types3-pass static type checker, polymorphic built-ins, Task<T> inference, exhaustiveness, SymbolTable
ochre-vmStack-based bytecode compiler, VM execution loop, Arc CoW Value, stdlib, HTTP/1.1 server
ochre-codegenCranelift 0.116 IR lowering, cranelift-object emission, and C runtime shim linking
ochre-lsplsp-server + lsp-types stdio Language Server
ochre-wasmwasm-bindgen wrapper exposing run_ochre and format_ochre to browsers
ochre-cliSingle user-facing ochre binary integrating all subcommands and REPL

Design Trade-offs

  • Zero LLVM dependency: Using pure-Rust cranelift-codegen keeps compile times fast and cross-platform builds clean.
  • Shared frontend: Fixes to parsing, type checking, or formatting automatically apply across ochre run, ochre build, ochre fmt, ochre lsp, and the browser playground.