This guide walks through compiling a FerroPhase project to a native target using
the intended scheduler-based compiler design. See docs/Design.md,
docs/Compiler.md, and docs/ConstEval.md for the architecture.
- Rust toolchain (stable) for building
fpbinaries - LLVM toolchain (llc + clang or compatible) available on PATH
fpCLI built fromcrates/fp-cli
Check availability:
$ fp --version
$ fp compile --helpA project is a directory containing a Magnet.toml package manifest and its
src/ sources:
$ mkdir my_project && cd my_projectProject layout:
my_project/
├── src/
│ └── main.fp
├── FerroPhase.toml
└── README.md
Example src/main.fp demonstrating comptime generation, quoting, and a simple
entry point:
const API_NAME: str = "FerroPhase";
const GREETING = quote item {
fn message() -> str {
"Hello from quote/splice!"
}
};
const GENERATED: () = splice GREETING;
fn main() {
println!("Welcome to {}", API_NAME);
println!("{}", message());
}
Highlights:
API_NAMEis answered by comptime work.quote/splicedemonstrate structured metaprogramming (seedocs/Quoting.md).quoteyields an AST token whose type is inferred by the compiler.mainis a standard entry point.
To inspect scheduler-produced AST and typed artefacts, run:
$ fp compile src/main.fp --package demo --emit ast --emit ast-typed --emit hirArtifacts (paths depend on your configuration):
target/ast/src_main.ast- canonical AST state after applied answerstarget/ast/src_main.ast-typed- typed AST annotationstarget/hir/src_main.hir- HIR for requested lowered scopes
The same compile command can emit native binaries, LLVM, Cranelift, and
bytecode, or run through the interpreter. Select a backend with --backend;
select a source printer with --target.
Common flags:
--opt-level {0|1|2|3}– Optimisation level (default: 2)--debug– Include debug info--emit {ast,ast-typed,hir,mir,lir}- Persist intermediates for inspection--save-intermediates– Shortcut to emit all intermediates
For example:
$ fp compile src/main.fp --package demo --backend binary --output main
$ fp compile src/main.fp --package demo --backend bytecode --output main.fbc
$ fp compile src/main.fp --package demo --target rust --output main.rs$ fp compile src/main.fp --package demo --emit ast-typed --emit hir
$ cat target/ast/src_main.ast-typed
$ cat target/hir/src_main.hir- The typed AST shows annotations applied to canonical AST state.
- HIR shows requested scopes after comptime answers needed by lowering were applied.
Use the inspect command to read compiled artifacts back out of their binary form:
$ fp inspect target/main.fbc
$ fp inspect target/main.fbc --export-text-bytecode target/main.ftbc
$ fp inspect target/main --hex --max-bytes 128.fbcfiles are decoded as FerroPhase binary bytecode and summarised by entrypoint, constants, and functions.--export-text-bytecodeconverts.fbcinto the stable textual.ftbcrepresentation for review and diffing.- Native/object binaries are summarised by file kind, architecture, sections, symbols, and code sections.
--hexprints a bounded raw byte preview for any inspected artifact.- Auto-detection is header-based across these families: FerroPhase binary bytecode, FerroPhase text bytecode, JVM class files, Unix archives, WebAssembly modules, and native/object containers (
ELF,Mach-O,PE,COFF,XCOFF, dyld cache). Unknown files fall back to raw bytes.
Current scope:
- FerroPhase can inspect and transcode its own bytecode representation.
- Native executables can be inspected structurally, but there is not yet a reverse compiler path from machine code back into MIR/AST, so high-level decompilation is intentionally out of scope for now.
Production builds must emit the release artifacts defined in
docs/ReleaseArtifacts.md. When --release is enabled, record:
- Toolchain and build options (see
docs/BuildOptions.md). - Output paths (
target/or--outputoverrides). - Backend-specific intermediates saved with
--save-intermediates.
The release record is required for reproducibility audits.
- Missing LLVM tools:
fp compilereports ifllc/clangare unavailable. Install via your package manager or setFP_LLVM_PATH. - Comptime errors: Review diagnostics by
RequestIdand original span. - Target mismatch: Ensure
docs/Design.mdconsistency rules hold; quoted and spliced code should be applied to canonical AST before affected scopes are lowered or emitted.
- Explore bytecode mode:
fp compile src/main.fp --package demo --backend bytecode - Generate Rust output with
fp compile --target rust - Extend the project with modules and custom targets; update
FerroPhase.tomlaccordingly.