pub struct Program(pub Vec<Token>);Expand description
Parsed program representation
The program is represented using Reverse Polish Notation, which is lends to easy iterative translation into CLIF as well as to simple optimizations.
Tuple Fields§
§0: Vec<Token>Implementations§
Source§impl Program
impl Program
Sourcepub fn parse_from_infix(expr: &str) -> Result<Self, JitError>
pub fn parse_from_infix(expr: &str) -> Result<Self, JitError>
Parses an infix notation into RPN
Sourcepub fn propagate_constants(&mut self)
pub fn propagate_constants(&mut self)
Evaluate constant expressions
Optimizes binary and unary operations:
- replace
[const0, const1, op]with[op(const0, const1)] - replace
[const, op]with[op(const)]
This operation is repeated until no progress can be made. Token::Noop
is removed in the process.
Doesn’t support reordering of associative operations, so
[var, const0, add, const1, add] is not replaced with
[var, add(const0, const1), add] and so on.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Program
impl RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnwindSafe for Program
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