FerroPhase is a meta-compilation toolkit that lets you write Rust-adjacent code with first-class structural metaprogramming, rich const-eval introspection, and multiple compilation targets from a single, shared AST pipeline.
- Structural metaprogramming: generate fields, methods, and whole types with hygienic transformations.
- Multi-mode toolchain: interpret, compile to native backends, or emit AST targets without changing source.
- Compile-time intelligence: query layouts, traits, and type metadata during const evaluation to shape emitted code.
- Install Rust (stable) and build the CLI:
cargo build --release export PATH="$(pwd)/target/release:$PATH"
- Scaffold a project:
magnet init my-project --template basic cd my-project - Compile and run:
# Quick iteration (interpreter) fp run src/main.fp # Or generate Rust via the backend pipeline fp compile src/main.fp --backend rust --output src/main.rs
- Const evaluation with intrinsics like
sizeof!,hasfield!, andclone_struct!, plus structural editors built on strictstd::intrinsiclang items. - Declarative type creation (
type T = { ... }) with conditionals and loops embedded in compile-time blocks. - Unified pipeline: CST → LAST → AST → ASTᵗ (typed) → ASTᶜ (const-evaluated) → HIRᵗ → MIR (Mid-level Intermediate Representation; SSA CFG) → LIR, shared by all execution modes.
- Multi-target outputs: native/LLVM, custom bytecode + VM, high-level Rust transpilation with optional type annotations.
- Shared frontend normalizes surface languages before const evaluation.
- Language-specific intrinsic helpers are imported at the LAST layer and immediately re-railed into canonical
stdsymbols. Strict intrinsics live understd::intrinsicas#[lang]items, and std wrappers call them so downstream stages see a consistent vocabulary. - Deterministic comptime interpreter produces a canonical EAST snapshot that every backend consumes.
- Type system phases:
Ty: canonical AST-level descriptors populated by Algorithm W.hir::Ty: lowered, layout-aware types shared with MIR/LIR.- Optional backend-specific intermediate types.
# Inspect the AST
fp parse examples/05_struct_generation.fp
# Interpret
fp run examples/09_metaprogramming_patterns.fp
# Compile to Rust backend source
fp compile src/service.fp --backend rust --output service.rs
# Emit AST target output (e.g. TypeScript)
fp compile src/service.fp --target typescript --output service.ts- ✅ Core AST infrastructure, const evaluation intrinsics, Rust target emission, CLI templates.
- 🚧 Parser upgrades for advanced macros, side-effect tracking, refinements to three-phase const evaluation.
- 📋 Planned: LLVM/WASM backends, language server integration, richer bytecode tooling.
docs/Design.md– pipeline and execution modesdocs/Types.md– phased type systemdocs/ConstEval.md– const evaluation semanticsdocs/Intrinsics.md– intrinsic normalisation across languagesdocs/QualityAssurance.md– QA framework for AI-generated codeexamples/– end-to-end scenarios (flat, renumbered catalog)