Expand description
The Mangle Driver.
This crate acts as the orchestrator for the Mangle compiler pipeline. It connects parsing, analysis, and execution components to provide a high-level API for running Mangle programs.
§Execution Architecture
Mangle supports multiple execution strategies:
-
Reference Implementation (Legacy): A naive bottom-up evaluator that operates directly on the AST. This is implemented in the
mangle-enginecrate and serves as a correctness baseline. It is not used by this driver. -
Interpreter (Default): A high-performance interpreter that executes the Mangle Intermediate Representation (IR). The driver compiles source code to IR and then executes it using
mangle-interpreter. -
WASM Compilation: The IR can be compiled to WebAssembly (WASM) for execution in browsers or WASM runtimes. This is handled by
mangle-codegen.
§Key Responsibilities
- Compilation: Parsing source code and lowering it to the Intermediate Representation (IR).
- Stratification: Analyzing dependencies between predicates to determine the correct
evaluation order (handling negation and recursion). This is implemented in
Program. - Execution: Running the compiled plan using the
mangle_interpreter. - Codegen: Generating WASM modules from the IR.
§Example
use mangle_ast::Arena;
use mangle_driver::{compile, execute};
let arena = Arena::new_with_global_interner();
let source = "p(1). q(X) :- p(X).";
// 1. Compile
let (mut ir, stratified) = compile(source, &arena).expect("compilation failed");
// 2. Execute
let store = Box::new(mangle_interpreter::MemStore::new());
let interpreter = execute(&mut ir, &stratified, store).expect("execution failed");Functions§
- compile
- Compiles source code into the Mangle Intermediate Representation (IR).
- compile_
to_ wasm - Compiles the Intermediate Representation (IR) into a WebAssembly (WASM) module.
- compile_
units - Compiles multiple source units into the Mangle Intermediate Representation (IR).
- execute
- Executes a compiled Mangle program using the pure Rust interpreter.