pub struct Program<'src, State> { /* private fields */ }Expand description
Type-state program using Rust’s type system to enforce correct usage.
§Examples
use expr_solver::{num, Program, SymTable};
// Compile from source
let program = Program::new_from_source("x * 2 + 1").unwrap();
// Link with symbol table
let mut table = SymTable::new();
table.add_const("x", num!(5), false).unwrap();
let mut linked = program.link(table).unwrap();
// Execute
assert_eq!(linked.execute().unwrap(), num!(11));Implementations§
Source§impl<'src> Program<'src, Compiled>
impl<'src> Program<'src, Compiled>
Sourcepub fn new_from_source(source: &'src str) -> Result<Self, ProgramError>
pub fn new_from_source(source: &'src str) -> Result<Self, ProgramError>
Creates a compiled program from source code.
§Examples
use expr_solver::Program;
let program = Program::new_from_source("2 + 3 * 4").unwrap();Sourcepub fn link(
self,
table: SymTable,
) -> Result<Program<'src, Linked>, ProgramError>
pub fn link( self, table: SymTable, ) -> Result<Program<'src, Linked>, ProgramError>
Links the bytecode with a symbol table.
Validates that all required symbols are present and compatible.
§Examples
use expr_solver::{Program, SymTable};
let program = Program::new_from_source("sin(pi)").unwrap();
let linked = program.link(SymTable::stdlib()).unwrap();Source§impl<'src> Program<'src, Linked>
impl<'src> Program<'src, Linked>
Sourcepub fn execute(&mut self) -> Result<Number, VmError>
pub fn execute(&mut self) -> Result<Number, VmError>
Executes the program and returns the result.
Sourcepub fn symtable_mut(&mut self) -> &mut SymTable
pub fn symtable_mut(&mut self) -> &mut SymTable
Returns a mutable reference to the symbol table.
Sourcepub fn get_assembly(&self) -> String
pub fn get_assembly(&self) -> String
Returns a human-readable assembly representation of the program.
Trait Implementations§
Auto Trait Implementations§
impl<'src, State> Freeze for Program<'src, State>where
State: Freeze,
impl<'src, State> RefUnwindSafe for Program<'src, State>where
State: RefUnwindSafe,
impl<'src, State> Send for Program<'src, State>where
State: Send,
impl<'src, State> Sync for Program<'src, State>where
State: Sync,
impl<'src, State> Unpin for Program<'src, State>where
State: Unpin,
impl<'src, State> UnwindSafe for Program<'src, State>where
State: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more