pub struct ArithmeticHandler;Expand description
Handles arithmetic operations for the VM
Implementations§
Source§impl ArithmeticHandler
impl ArithmeticHandler
Sourcepub fn add<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn add<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Adds the top two values on the stack
Pops two values from the stack, adds them, and pushes the result. Supports numeric addition and string concatenation.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands
§Examples
let mut stack = MyStack::new();
stack.push(Value::Number(3.0));
stack.push(Value::Number(5.0));
ArithmeticHandler::add(&mut stack)?;
assert_eq!(stack.pop(), Some(Value::Number(8.0)));Sourcepub fn subtract<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn subtract<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn multiply<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn multiply<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn divide<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn divide<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Divides the first value by the second value on the stack
Pops two values from the stack, divides the first by the second, and pushes the result. Handles division by zero.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operandsErr(ExecutionError::RuntimeError)on division by zero
Sourcepub fn modulo<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn modulo<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn power<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn power<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn negate<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn negate<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn increment<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn increment<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn decrement<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn decrement<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Auto Trait Implementations§
impl Freeze for ArithmeticHandler
impl RefUnwindSafe for ArithmeticHandler
impl Send for ArithmeticHandler
impl Sync for ArithmeticHandler
impl Unpin for ArithmeticHandler
impl UnwindSafe for ArithmeticHandler
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