Skip to content

Architecture

This document outlines the architecture of the Chuks programming language, covering the Compiler Pipeline, Runtime Environment, and Core Subsystems (Memory, Concurrency, OOP).

User Space & Tooling
📄
Source .chuks
CLI Tool
🧠
Language Server
(LSP)
Compiler Pipeline (AOT)
Lexer
Parser
Type Checker
IR Generator

🔧 Optimizer

Bytecode
Emitter → .ckb
Go Backend
→ Native Binary
WASM
.wasm
Runtime Environment
Execution Engine
🖥️ Bytecode VM
(Stack-based)
🚀 Native Execution
(AOT compiled)
🧱 Memory Model
  • ◈ Stack
  • ◈ Heap (GC / ARC)
  • ◈ Go-style Pointers
  • ◈ VMT — O(1) dispatch
⚙️ Hybrid Concurrency
  • ◈ Event Loop (I/O)
  • ◈ Coroutine Scheduler
  • ◈ OS Thread Pool
🔗 Interop
C / Go / Rust FFI
  • CLI / Build Tool — The entry point for developers. Handles compilation, formatting, and project management (chuks run, chuks build, chuks new).
  • Language Server (LSP) — Provides IDE support (autocomplete, go-to definition, hover info) using the static analysis engine.

A multi-stage pipeline designed for speed and safety.

The Lexer tokenizes source code, the Parser produces an AST, and the Type Checker performs rigorous static analysis including generics resolution and type safety.

The AST is converted to Chuks IR (Intermediate Representation). The Optimizer performs:

  • Monomorphization of generics
  • Function inlining
  • Dead code elimination (DCE)
  • Constant folding
TargetDescription
Bytecode EmitterFast compilation for dev/debug cycles. Outputs .ckb files.
Go BackendTranspiles to Go and compiles to optimized native binaries.
WASMWebAssembly output for browser and edge deployment.

Designed for predictability and high concurrency.

ComponentDescription
StackFast storage for primitives and call frames
HeapManaged storage for escaping objects. Supports pluggable GC or ARC strategies.
Go-style PointersStructs and primitives are values by default. Explicit *T and &x operators for sharing/mutation.
VMTVirtual Method Tables ensure O(1) dynamic dispatch for class methods

Escape Analysis determines whether variables stay on the Stack (fast) or move to the Heap (GC managed).

Chuks uses a three-layer concurrency model:

LayerRole
Event LoopHandles non-blocking I/O (network, file) efficiently
Coroutine SchedulerManages lightweight “green threads” for massive concurrency (10k+ tasks) using M:N threading
OS Thread PoolDistributes CPU-bound work across OS threads for multi-core utilization

The Scheduler coordinates between the Event Loop (for I/O) and the Thread Pool (for CPU), allowing async/await and spawn to work seamlessly together.

Direct bindings to C/Rust libraries for ecosystem compatibility through the FFI layer.