Compiler Pipeline
Phase 1 — Bootstrap Compiler (Rust → C)
Source (.nyx) → Lexer → Parser → AST → Type Checker → Region Analysis → C Codegen → GCC → Native Binary
| Phase | Output | Status |
|---|---|---|
| Lexer | Token stream (identifiers, strings, chars, byte literals, numeric suffixes) | ✅ Complete |
| Parser (Pratt) | AST (structs, enums, generics, closures, match, for, while, slices, type aliases, byte literals) | ✅ Complete |
| Type Checker | Typed AST (generic inference, method dispatch, pattern coverage, type casts) | ✅ Complete |
| Region Analysis | Simplified escape detection + arena allocation | ⚠️ Basic |
| C Codegen | C source files with runtime linkage | ✅ Complete |
Parser Features (v0.11.0)
- Slice syntax:
s[start..end],s[start..],s[..end],s[..]— generates inline C with pointer arithmetic - Inline extern blocks:
extern "C" { fn ... }inside function bodies for localized FFI declarations - Type aliases:
type Name = Target;at module level - Byte literals:
b'0',b'A'— for binary/string processing - Nested generics:
>>token correctly split into>> - Deref-assign:
*ptr = valwith proper implicit semicolons - Prefix precedence:
&mut out[0]correctly binds postfix[before prefix&mut - Type casts:
expr as u64returns the target type - String/Ptr compatibility: string literals compatible with
*const u8for FFI - Null pointer checks:
ptr == nullworks across pointer and integer types
Module System
Status: ✅ Full import pipeline + peer resolution + perf + caching (v0.6.2)
Import resolution, parsing, type-checking, C codegen, forward declarations, and multi-file GCC linking all work. import std.* uses parse-level symbol extraction (stdlib backed by C runtime). import mymod fully compiles and links with auto-injected forward declarations. Peer-module resolution (import token.* from nyxc/lexer.nyx) discovers siblings via parent-directory search path push. Typecheck skipped for large dependency trees (O(n²) perf deferred to self-hosted compiler). Module caching (v0.6.2): source hashes stored in .nyx_cache/ — recompiles skip unchanged modules, GCC linking cached when .exe is newer than all .c files.
Stdlib Status
std/crypto.nyx — compiles successfully through full pipeline (parse → typecheck → codegen).
std/fs.nyx — compiles successfully through full pipeline. Uses local basename() helper and inline getenv() extern (bootstrap compiler doesn't support std.module qualified paths at expression level).
Phase 2 — Self-Hosted Compiler (Nyx → MLIR/LLVM)
Source (.nyx) → Lexer → Parser → AST → Type Checker → Region Inference → MLIR Dialects → LLVM IR → Native/WASM
| Phase | Output | Status |
|---|---|---|
| Lexer (Nyx) | Token stream | ⚠️ Partial |
| Parser (Nyx) | AST | ⚠️ Partial |
| Type Checker | Typed AST (TIR) — Bidirectional + Hindley-Milner | ❌ Stub |
| Region Inference | Ownership-annotated IR — full lifetime analysis | ❌ Stub |
| MLIR Lowering | MLIR dialects (nyx.async, nyx.region, nyx.struct) | ❌ Stub |
| LLVM Codegen | LLVM IR → .o / .wasm — LLVM 18+ with LTO | ❌ Stub |