Expand description
Joule Compiler Library
Provides the programmatic API for invoking the Joule compiler pipeline. This allows other tools (LSP, REPL, test harness, documentation generator) to compile Joule source code without spawning a subprocess.
§Pipeline Stages
The compilation pipeline proceeds through these stages:
- Lexing — Source text → token stream
- Parsing — Token stream → AST
- Type checking — AST → HIR (with type resolution and energy budget verification)
- MIR lowering — HIR → MIR (control flow graph with ownership info)
- Borrow checking — MIR validation (ownership, lifetimes, initialization)
- Code generation — MIR → target code (Cranelift, LLVM, MLIR, or C)
§Example
use joulec::{CompileOptions, compile_source};
let source = r#"
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
"#;
let options = CompileOptions::default();
let result = compile_source(source, "example.joule", &options);Structs§
- Compile
Options - Options controlling the compilation pipeline.
- Compile
Output - The result of a successful compilation through the full pipeline.
Functions§
- compile_
multi_ file - Compile multiple source files together (multi-file compilation).
- compile_
source - Compile a single source string through the full pipeline (lex → parse → typecheck → MIR → borrowck).
- compile_
to_ c - Compile source and emit C code (the bootstrap self-hosting path).
- parse_
source - Parse source code into an AST without type checking.
- type_
check_ source - Type check source code and return the HIR.