feat: update PLAN.md and add end to end test of the compiler

This commit is contained in:
2026-04-20 23:39:47 +02:00
parent 35255a924a
commit bad6b9e116
4 changed files with 80 additions and 16 deletions
+18 -16
View File
@@ -3,7 +3,7 @@
A Rust-flavored, C-targeting language - built pipeline-first.
**Implementation language:** Rust
**Code generation target:** x86-64 (AT&T / Intel syntax `.s` → assembled via GAS or NASM)
**Code generation target:** Native object files (`.o`) via Cranelift JIT/AOT
## Phase 1 - Lexer
@@ -25,23 +25,25 @@ A Rust-flavored, C-targeting language - built pipeline-first.
## Phase 3 - Semantic Analysis
- [ ] Implement scope-aware symbol table
- [ ] Name resolution pass - resolve all `Ident` nodes to their declarations
- [ ] Type inference / checking for `int` and `bool`
- [ ] Validate function return types match declared signature
- [ ] Error on use-before-declaration and undeclared symbols
- [ ] Unit-test: ill-typed programs produce correct diagnostics
- [x] Implement scope-aware symbol table (environment)
- [x] Name resolution pass - resolve all `Ident` nodes to their declarations
- [x] Hindley-Milner type inference (unification, type variables, occurs check)
- [x] Integer literal sizing and unary minus type promotion logic
- [x] Translate untyped AST directly into a fully-typed AST (Typed AST)
- [x] Validate function return types match declared signature
- [x] Error on use-before-declaration, undeclared symbols, and type mismatches
- [x] Unit-test: HM unification, type mappings, and ill-typed program diagnostics
## Phase 4 - x86-64 Code Generation
## Phase 4 - Code Generation via Cranelift
- [ ] Design a simple intermediate representation (linear IR, or use AST directly)
- [ ] Implement stack-frame layout for local variables
- [ ] Emit System V AMD64 ABI-compliant function prologues / epilogues
- [ ] Codegen for arithmetic & comparison expressions
- [ ] Codegen for function calls (argument passing via registers)
- [ ] Codegen for `return` statements
- [ ] Output `.s` file, assemble with NASM / GAS
- [ ] End-to-end test: compile a simple `fn` → run → correct exit code
- [x] Integrate `cranelift-codegen`, `cranelift-frontend`, and `cranelift-object`
- [x] Implement CLI with `clap` (`--emit-ir` flag, input/output files)
- [x] Map Typed AST types (`Ty`) to Cranelift IR types
- [x] Lower functions, parameters, and variable definitions to Cranelift IR
- [x] Codegen for arithmetic, unary operations, and `return` statements
- [x] Run built-in optimization passes (constant folding, e-graphs, DCE)
- [x] Output System V AMD64 ABI-compliant `.o` machine code files
- [x] End-to-end test: compile a simple `fn` link via `gcc` run → correct exit code
## Planned Features (Backlog)