pub struct ComparisonHandler;Expand description
Handles comparison and logical operations for the VM
Implementations§
Source§impl ComparisonHandler
impl ComparisonHandler
Sourcepub fn equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if two values are equal using loose equality
Pops two values from the stack, compares them using JavaScript-like type coercion, and pushes the boolean result.
§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(5.0));
stack.push(Value::String("5".to_string()));
ComparisonHandler::equal(&mut stack)?;
assert_eq!(stack.pop(), Some(Value::Boolean(true)));Sourcepub fn not_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn not_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if two values are not equal using loose equality
Pops two values from the stack, compares them using JavaScript-like type coercion, and pushes the boolean result.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands
Sourcepub fn strict_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn strict_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn strict_not_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn strict_not_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Sourcepub fn less_than<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn less_than<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if the first value is less than the second
Pops two values from the stack, compares them, and pushes the boolean result. Supports numeric comparison with type coercion.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands
Sourcepub fn less_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn less_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if the first value is less than or equal to the second
Pops two values from the stack, compares them, and pushes the boolean result. Supports numeric comparison with type coercion.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands
Sourcepub fn greater_than<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn greater_than<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if the first value is greater than the second
Pops two values from the stack, compares them, and pushes the boolean result. Supports numeric comparison with type coercion.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands
Sourcepub fn greater_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
pub fn greater_equal<S>(stack: &mut S) -> Result<(), ExecutionError>where
S: StackOperations,
Checks if the first value is greater than or equal to the second
Pops two values from the stack, compares them, and pushes the boolean result. Supports numeric comparison with type coercion.
§Arguments
stack- The stack to operate on
§Returns
Ok(())on successErr(ExecutionError::StackUnderflow)if insufficient operands