How cod-e-codes/ion-lang works
Purpose and binaries
Ion is a Rust-built systems-language toolchain that enforces move ownership, non-escaping references, and channel-based concurrency, then emits C for GCC/Clang compilation. The compiler executable is rooted at src/main.rs; project build orchestration and language-server binaries are src/bin/ion-build.rs and src/bin/ion-lsp.rs. Shared library wiring is in src/lib.rs.
Front-end: source to checked program
The compiler pipeline tokenizes Ion, constructs its AST, resolves modules/imports, and type-checks semantic and safety rules:
• Lexer: src/lexer/mod.rs
• Parser and AST: src/parser/mod.rs, src/ast/mod.rs
• Module/import compilation: src/compiler/mod.rs
• Type checking: src/tc/mod.rs, src/tc/ownership.rs, src/tc/trait_bounds.rs
The type-checking boundary is architecture-critical: it validates ownership/borrowing, structural Send, visibility, generics, and trait bounds before lowering/code generation.
Lowering and C backend
Checked programs lower through an intermediate representation and generate readable C, including type definitions, builtins, and destruction/drop behavior:
• IR: src/ir/mod.rs
• C generation: src/cgen/mod.rs, src/cgen/types.rs, src/cgen/drop.rs
The generated C is the interoperability boundary: Ion FFI uses C-compatible declarations/raw pointers and requires unsafe contexts. Generated programs compile outside Rust using a platform C toolchain.
Build driver and native linking
ion-build discovers and reads ion.toml, chooses single- or multi-module compilation, invokes the compiler, and calls GCC or Clang to compile/link generated C:
• Build driver: src/build/driver.rs
• Manifest and path discovery: src/build/manifest.rs, src/build/paths.rs
• C toolchain integration: src/build/c_toolchain.rs
Artifacts normally go to target/. Multi-file projects produce C/header units and native objects before final linking. Material dependencies are Rust 1.96, GCC or Clang, and pthread-compatible native threading; Windows uses MinGW as the primary target.
Runtime and standard library
Generated C links the Ion C runtime, which provides runtime-level facilities needed by emitted code, including lifecycle and concurrency support:
• Runtime ABI/source: runtime/ion_runtime.h, runtime/ion_runtime.c
• Ion standard-library modules: stdlib/io.ion, stdlib/fmt.ion, stdlib/fs.ion, stdlib/result.ion
• ABI contract: docs/ABI.md
The stdlib is Ion source consumed through module resolution; the runtime is C linked into each executable. OS-level threads underpin Ion spawn and channels.
Editor protocol integration
The LSP reuses compiler-facing analysis to serve diagnostics and language intelligence over the Language Server Protocol:
• Server: src/lsp/server.rs, src/lsp/mod.rs
• LSP binary: src/bin/ion-lsp.rs
• VS Code/Cursor client: ion-vscode/src/extension.ts, ion-vscode/package.json
The TypeScript extension launches/configures the Rust LSP, provides syntax configuration, and watches workspace Ion dependencies.
Primary execution flows
1. Direct compile: ion-compiler takes an Ion entry file, runs front-end checking → IR → C generation; users manually compile generated C with the runtime.
2. Project build: ion-build discovers ion.toml → plans sources/output → invokes compiler generation → invokes C compiler/linker with runtime, flags, and platform libraries → writes executable.
3. IDE analysis: editor extension starts ion-lsp → LSP parses/checks workspace documents and imports → returns diagnostics, symbols, navigation, completion, and hover data.
Language semantics are specified in ION_SPEC.md; project-level build behavior and the primary sample manifest are represented by ion.toml.
Main entry points: mod.rs Module resolver · c_toolchain.rs GCC / Clang integration · driver.rs Build driver · server.rs LSP server
Components 20
Compiler pipeline
Rust compiler transforms checked Ion into C.
- ion-compiler · Direct compiler entry point.
src/main.rs - Lexer
src/lexer/mod.rs - Parser & AST
src/parser/mod.rs - Module resolver · Resolves imports and compiles modules.
src/compiler/mod.rs - Type & safety checker · Enforces ownership, borrowing, Send, visibility, generics, and trait bounds.
src/tc/mod.rs - Intermediate representation
src/ir/mod.rs - C generator · Emits C types, builtins, and drop behavior.
src/cgen/mod.rs
Project build & native output
Build driver coordinates manifests, compiler output, and native linking.
- ion-build · Project build orchestration entry point.
src/bin/ion-build.rs - Manifest & path discovery · Reads ion.toml and selects project sources and outputs.
src/build/manifest.rs - Build driver · Chooses single- or multi-module compilation and native build steps.
src/build/driver.rs - GCC / Clang integration · Compiles generated C and links platform libraries.
src/build/c_toolchain.rs - Native executable · Written under target/.
Runtime & language libraries
Generated programs use the C runtime while source imports consume the Ion stdlib.
- Ion standard library · Imported through module resolution.
stdlib/io.ion - Ion C runtime · Lifecycle and concurrency support linked into generated executables.
runtime/ion_runtime.c - Native threads · pthread-compatible threads underpin spawn and channels.
Editor integration
VS Code/Cursor launches the Rust language server.
- ion-lsp · Language Server Protocol binary.
src/bin/ion-lsp.rs - LSP server · Reuses compiler-facing parsing and checking for language intelligence.
src/lsp/server.rs - VS Code/Cursor extension · Launches and configures ion-lsp and watches workspace dependencies.
ion-vscode/src/extension.ts - Editor diagnostics & navigation · Diagnostics, symbols, navigation, completion, and hover.
Other components
- Ion entry & modules
Connections 20
- Ion entry & modules → ion-compiler: direct compile
- ion-compiler → Lexer: tokenizes
- Lexer → Parser & AST: tokens
- Parser & AST → Module resolver: AST
- Module resolver → Ion standard library: resolves imports
- Module resolver → Type & safety checker: resolved program
- Type & safety checker → Intermediate representation: checked program
- Intermediate representation → C generator: lowers
- ion-build → Manifest & path discovery: discovers
- Manifest & path discovery → Build driver: project plan
- Build driver → ion-compiler: invokes C generation
- C generator → GCC / Clang integration: generated C units
- Build driver → GCC / Clang integration: link plan and flags
- GCC / Clang integration → Ion C runtime: links
- GCC / Clang integration → Native executable: compiles and links
- Ion C runtime → Native threads: uses
- VS Code/Cursor extension → ion-lsp: starts
- ion-lsp → LSP server: hosts
- LSP server → Module resolver: analyzes documents and imports
- LSP server → Editor diagnostics & navigation: returns