Expand description
§logicaffeine_compile
The compilation pipeline for LOGOS, transforming natural language logic into executable Rust code.
§Architecture
LOGOS Source
│
▼
┌─────────┐ ┌───────────┐ ┌──────────┐
│ Lexer │ ──▶ │ Parser │ ──▶ │ AST │
└─────────┘ └───────────┘ └──────────┘
│
┌──────────────────────────────────┘
▼
┌─────────────────────────────────────────────┐
│ Analysis Passes │
│ ┌─────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Escape │ │ Ownership │ │ Z3 │ │
│ └─────────┘ └───────────┘ └───────────┘ │
└─────────────────────────────────────────────┘
│
▼
┌──────────┐ ┌────────────┐
│ CodeGen │ ──▶ │ Rust Code │
└──────────┘ └────────────┘§Feature Flags
| Feature | Description |
|---|---|
codegen | Rust code generation (default) |
verification | Z3-based static verification |
§Modules
compile: Top-level compilation functionscodegen: AST to Rust code generation (requirescodegenfeature)analysis: Static analysis passes (escape, ownership, discovery)extraction: Kernel term extraction to Rustinterpreter: Tree-walking AST interpreterdiagnostic: Rustc error translation to LOGOS-friendly messagessourcemap: Source location mapping for diagnosticsloader: Multi-file module loadingui_bridge: Web interface integrationverification: Z3-based static verification (requiresverificationfeature)
§Getting Started
§Basic Compilation
use logicaffeine_compile::compile::compile_to_rust;
let source = "## Main\nLet x be 5.\nShow x.";
let rust_code = compile_to_rust(source)?;§With Ownership Checking
use logicaffeine_compile::compile::compile_to_rust_checked;
let source = "## Main\nLet x be 5.\nGive x to y.\nShow x.";
// Returns error: use-after-move detected at check-time
let result = compile_to_rust_checked(source);§Interpretation
use logicaffeine_compile::interpret_for_ui;
let source = "## Main\nLet x be 5.\nShow x.";
let result = interpret_for_ui(source).await;
// result.lines contains ["5"]Re-exports§
pub use loader::Loader;pub use loader::ModuleSource;pub use compile::CompileOutput;pub use compile::CrateDependency;pub use compile::compile_program_full;pub use ui_bridge::compile_for_ui;pub use ui_bridge::compile_for_proof;pub use ui_bridge::compile_theorem_for_ui;pub use ui_bridge::verify_theorem;pub use ui_bridge::interpret_for_ui;pub use ui_bridge::interpret_for_ui_sync;pub use ui_bridge::interpret_streaming;pub use ui_bridge::CompileResult;pub use ui_bridge::ProofCompileResult;pub use ui_bridge::TheoremCompileResult;pub use ui_bridge::AstNode;pub use ui_bridge::TokenInfo;pub use ui_bridge::TokenCategory;pub use ui_bridge::generate_rust_code;codegenpub use logicaffeine_kernel as kernel;
Modules§
- analysis
- Compile-time analysis passes for the LOGOS compilation pipeline.
- arena
- arena_
ctx - ast
- Abstract Syntax Tree types for both logical expressions and imperative statements.
- codegen
codegen - Code generation from LOGOS AST to Rust source code.
- compile
- LOGOS Compilation Pipeline
- diagnostic
- Diagnostic bridge for translating Rust errors to LOGOS.
- drs
- Discourse Representation Structure (DRS) for anaphora resolution and scope tracking.
- error
- Error types and display formatting for parse errors.
- extraction
- Program extraction from kernel terms to Rust.
- formatter
- Output formatters for logical expressions.
- intern
- interpreter
- Tree-walking interpreter for LOGOS imperative code.
- lexer
- Two-stage lexer for LOGOS natural language input.
- loader
- Module loader for multi-file LOGOS projects.
- mwe
- Multi-Word Expression (MWE) processing.
- optimize
- parser
- Recursive descent parser for natural language to first-order logic.
- registry
- sourcemap
- Source map for the diagnostic bridge.
- style
- token
- Token types for the LOGOS lexer and parser.
- ui_
bridge - UI bridge for web interface integration.
Structs§
- Arena
- A bump allocator for stable, arena-allocated references.
- AstContext
- Collection of typed arenas for AST allocation during parsing.
- Discovery
Pass - Discovery pass that scans tokens before main parsing to build a TypeRegistry.
- Interner
- A string interner providing O(1) equality comparison via
Symbolhandles. - Lexer
- Parse
Error - A parse error with location information.
- Parser
- Recursive descent parser for natural language to first-order logic.
- Policy
Registry - Registry for security policies defined in
## Policyblocks. - Symbol
- A lightweight handle to an interned string.
- Symbol
Registry - Registry for mapping words to FOL variable names.
- Type
Registry
Enums§
- Policy
Condition - Condition in a policy definition. Represents the predicate logic for security rules.