Skip to main content

codegen_program

Function codegen_program 

Source
pub fn codegen_program(
    stmts: &[Stmt<'_>],
    registry: &TypeRegistry,
    policies: &PolicyRegistry,
    interner: &Interner,
) -> String
Available on crate feature codegen only.
Expand description

Generate a complete Rust program from LOGOS statements.

This is the main entry point for code generation. It produces a complete, compilable Rust program including:

  1. Prelude imports (logicaffeine_data, logicaffeine_system)
  2. User-defined types in mod user_types
  3. Policy impl blocks with predicate/capability methods
  4. Function definitions
  5. fn main() with the program logic

§Arguments

  • stmts - The parsed LOGOS statements
  • registry - Type registry containing struct/enum definitions
  • policies - Policy registry containing security predicates and capabilities
  • interner - Symbol interner for name resolution

§Returns

A complete Rust source code string ready to compile.

§Generated Features

  • Wraps user types in mod user_types for visibility control
  • Emits function definitions before main
  • Handles CRDT field mutations with proper .set() calls
  • Generates policy predicate and capability methods
  • Adds #[tokio::main] async when needed
  • Injects VFS when file operations detected
  • Uses Distributed<T> when both Mount and Sync detected
  • Boxes recursive enum fields Generates a complete Rust program from LOGOS statements.

This is the main entry point for code generation. It produces a full Rust program including:

  • Prelude imports (use logicaffeine_data::*;)
  • Type definitions (structs, enums, inductive types)
  • Policy structs with capability methods
  • Main function with async runtime if needed
  • VFS initialization for file operations

§Arguments

  • stmts - The parsed LOGOS statements to compile
  • registry - Type definitions discovered during parsing
  • policies - Policy definitions for access control
  • interner - Symbol interner for resolving names

§Returns

A complete Rust source code string ready for compilation.