Skip to content
Ridgun
English

Ridgun

The language itself: a compiler that compiles itself, the stable project tool, the specification and the book

FR-COMP-004-native-elf64-codegen-x86-64-and-arm64.md35 lines · 3.4 KBRaw
1---
2id: FR-COMP-004
3title: 100% Pure-Ridgun Native ELF64 Code Generation for x86_64 and ARM64 Without Rust or rustc
4status: implemented
5priority: must
6created: 2026-10-21
7updated: 2026-10-25
8depends_on:
9 - FR-COMP-001
10 - FR-COMP-002
11 - FR-COMP-003
12verified_by: []
13---
14# FR-COMP-004 — 100% Pure-Ridgun Native ELF64 Code Generation for `x86_64` and `ARM64` Without Rust or `rustc`
15
16## Statement
17The `ridgunc` compiler and the Ridgun repository SHALL be 100% self-contained in pure Ridgun (`.rg`) with zero Rust or C source files (`.rs`, `.c`), zero `Cargo.toml`/`Cargo.lock` manifests, and zero invocations of `rustc`, `clang`, or `gcc`:
181. **Native ELF64 Binary Emission (`src/main/ridgun/lib/llvm.rg` and `src/main/ridgun/lib/elf64.rg`)**:
19 - `ridgunc build` and `ridgunc run` SHALL emit standalone Linux ELF64 executables without invoking `rustc`, `clang`, or `gcc` (using pure LLVM IR `.ll` compiled via `llc -O2 -filetype=obj` and linked via `ld` on `x86_64` per `ADR-0002`, and direct `elf64.rg` emission on `ARM64`).
20 - The native backend SHALL support both Linux `x86_64` (`e_machine = EM_X86_64 = 62`) and Linux `ARM64` / `AArch64` (`e_machine = EM_AARCH64 = 183`, Raspberry Pi 3/4/5).
212. **Native Codegen Backends (`src/main/ridgun/lib/llvm.rg`, `src/main/ridgun/lib/x86_64.rg`, and `src/main/ridgun/lib/arm64.rg`)**:
22 - All reachable Ridgun functions (`fn ::` and `op ::`), pattern matches, guards (`|`, `|.`), parallel DAG `where` blocks (`||`, `||.`), mutable bindings (`mut`), tail-call loops (TCO), and `RMM1`/`RMM2` memory management operations SHALL be compiled directly into native `x86_64` or `ARM64` machine instructions.
23 - All runtime primitives (`Int`, `Real`, `String`, `Bool`, `List`, `Tuple`, `Adt`, `Tensor`, `einsum`, Hadamard `@+`/`@-`/`@*`/`@/`, `map`, `||map`, `filter`, `||filter`, `fold`, channels/mailboxes, `context`/`shared`/`atomic`, `with region`, and POSIX/Linux OS built-ins) SHALL be embedded directly as native machine code inside the ELF64 binary.
243. **Complete Elimination of Legacy Rust Code**:
25 - The legacy `src/main/rust/` directory, `Cargo.toml`, and `Cargo.lock` SHALL be removed from the repository.
26 - `src/main/ridgun/lib/compiler.rg` SHALL contain zero embedded Rust source code and zero `rustc` shell commands.
27
28## Rationale
29- Eliminating the intermediate Rust transpilation step and `rustc` dependency makes Ridgun a 100% self-hosted native compiler, reduces executable link/emission time from ~30s to milliseconds, supports cross-compilation to `ARM64` (Raspberry Pi) out of the box, and removes all non-Ridgun source code from the project.
30
31## Acceptance Criteria
321. **AC-1 (Zero Rust / Zero `rustc`)**: No `.rs` files, `Cargo.toml`, or `rustc` invocations remain anywhere in `src/` or the repository root.
332. **AC-2 (Self-Hosting Stage 1 & Stage 2)**: `target/ridgunc` compiles `src/main/ridgun/ridgunc/main.rg` and `src/main/ridgun/stable/main.rg` into native ELF64 executables (`Stage 1`), and `Stage 1` recompiles them into identical `Stage 2` native ELF64 executables without `rustc`.
343. **AC-3 (Full Language & Test Suite Parity)**: `./target/stable check`, `./target/stable test` (all 4 test suites: `test_basics.rg`, `test_core_language.rg`, `test_parallel_and_tensors.rg`, `test_strings.rg`), and `./target/stable format` pass with 0 errors.
354. **AC-4 (`x86_64` and `ARM64` ELF64 Target Support)**: `ridgunc build` supports emitting both `x86_64` (`EM_X86_64 = 62`) and `ARM64` (`EM_AARCH64 = 183`) ELF64 binaries.