1 unstable release
| 0.1.0 | Oct 9, 2025 |
|---|
#136 in Visualization
213 downloads per month
140KB
3.5K
SLoC
ag - A Rust-Inspired Functional Language
ag is a Rust-inspired functional programming language that compiles to native machine code. The project emphasizes clarity, correctness, and learning through incremental development.
๐ฏ Project Goals
- Educational: Learn compiler construction through hands-on implementation
- Incremental: Build features phase-by-phase, achieving milestones along the way
- Observable: Every compilation stage produces human-readable visualizations
- Test-Driven: Comprehensive test coverage from day one
- Documented: Living documentation that evolves with the language
๐ Quick Start
# Build the compiler
cargo build --release
# Compile an ag program (once implemented)
./target/release/ag examples/hello.ag -o hello
# View compilation stages
./target/release/ag examples/hello.ag --stage 1 # Lexer
./target/release/ag examples/hello.ag --stage 2 # Parser
๐ Development Status
| Phase | Feature | Version | Status |
|---|---|---|---|
| 0 | Foundation & Tooling | - | โ Complete |
| 1 | Lexical Analysis | 0.1.0 | โ Complete |
| 2 | Parsing & AST | 0.2.0 | โ Complete |
| 3 | Semantic Analysis | 0.3.0 | โ Complete |
| 4 | Conditionals | 0.4.0 | ๐ โณ In-Progress |
| 5 | Loops (Turing-Complete!) | 0.5.0 | ๐ Locked |
| 6 | Intermediate Representation | 0.6.0 | ๐ Locked |
| 7 | Code Generation | 0.7.0 | ๐ Locked |
| 8 | Standard Library | 0.8.0 | ๐ Locked |
| 9 | Optimizations | 0.9.0 | ๐ Locked |
| 10 | Advanced Features | 1.0.0 | ๐ Locked |
See ROADMAP.md for the complete development plan.
๐ง What's Working Now
Phase 0: Foundation โ
- โ Project structure and build system
- โ CLI with argument parsing
- โ Error handling with beautiful diagnostics
- โ HTML/SVG visualization framework
- โ Test infrastructure and utilities
- โ Documentation generation system
Coming in Phase 1: Lexical Analysis
- Tokenization of source code
- Keywords, operators, identifiers, literals
- Syntax-highlighted token visualization
- Line/column error reporting
๐จ Language Preview
Here's what ag will look like (Phase 2+):
// Factorial function
fn factorial(n: i32) -> i32 {
let result = 1;
let i = 1;
while i <= n {
result = result * i;
i = i + 1;
}
return result;
}
fn main() -> i32 {
let x = factorial(5);
print_i32(x); // Phase 8: stdlib
return 0;
}
๐ Documentation
- ROADMAP.md - Complete development roadmap
- docs/ARCHITECTURE.md - Compiler design and architecture
- docs/current-spec.md - Language specification (generated)
- man/current-guide.md - User guide (generated)
- CHANGELOG.md - Version history
๐งช Testing
# Run all tests
cargo test
# Run tests for a specific phase
cargo test phase_01
# Run with verbose output
cargo test -- --nocapture
# Update snapshot tests
cargo insta review
๐ ๏ธ Development
Prerequisites
- Rust 1.70 or later
- Basic understanding of compilers (helpful but not required!)
Project Structure
ag-compiler/
โโโ src/ # Compiler implementation
โโโ tests/ # Test suites by phase
โโโ docs/ # Technical documentation
โโโ man/ # User manual
โโโ examples/ # Example programs
โโโ scripts/ # Build and documentation scripts
Building
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Run clippy (linter)
cargo clippy
# Format code
cargo fmt
Contributing
We welcome contributions! Please:
- Read the current phase in ROADMAP.md
- Check open issues for tasks
- Write tests for new features
- Update documentation
- Submit a pull request
๐ Learning Resources
The ag compiler is designed as a learning project. Here are resources that inspired it:
- Crafting Interpreters by Robert Nystrom
- Engineering a Compiler
- Rust Compiler Development Guide
- Writing an Interpreter in Go by Thorsten Ball
๐ Core Principles
Test-Driven Development
Every feature comes with comprehensive tests. Tests accumulate across phases to ensure backward compatibility.
Incremental Complexity
The language grows one feature at a time. Each phase is complete and working before moving forward.
Visualization First
Every compilation stage produces a human-readable visualization for debugging and learning.
Living Documentation
Documentation is written as features are implemented and locked at phase completion.
๐ฏ Milestones
- Phase 5 Complete: Language achieves Turing-completeness ๐
- Phase 7 Complete: First working compiler producing executables ๐
- Phase 10 Complete: Version 1.0 - Feature-complete language โญ
๐ License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
๐ค Acknowledgments
- The Rust community for excellent tooling and documentation
- Cranelift for providing a fantastic code generation backend
- All contributors who help build ag
Let's build a compiler together! ๐
For questions or discussions, open an issue on GitHub.
Dependencies
~7โ9.5MB
~171K SLoC