Struct ComparisonHandler

Source
pub struct ComparisonHandler;
Expand description

Handles comparison and logical operations for the VM

Implementations§

Source§

impl ComparisonHandler

Source

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 success
  • Err(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)));
Source

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 success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn strict_equal<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Checks if two values are strictly equal

Pops two values from the stack, compares them without type coercion, and pushes the boolean result.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn strict_not_equal<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Checks if two values are strictly not equal

Pops two values from the stack, compares them without type coercion, and pushes the boolean result.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

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 success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

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 success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

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 success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

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 success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn logical_and<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs logical AND operation

Pops two values from the stack, performs logical AND, and pushes the result. Uses JavaScript-like truthy/falsy conversion.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn logical_or<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs logical OR operation

Pops two values from the stack, performs logical OR, and pushes the result. Uses JavaScript-like truthy/falsy conversion.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn logical_not<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs logical NOT operation

Pops one value from the stack, performs logical NOT, and pushes the result. Uses JavaScript-like truthy/falsy conversion.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if stack is empty
Source

pub fn bitwise_and<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs bitwise AND operation

Pops two values from the stack, performs bitwise AND, and pushes the result. Converts values to integers before operation.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn bitwise_or<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs bitwise OR operation

Pops two values from the stack, performs bitwise OR, and pushes the result. Converts values to integers before operation.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn bitwise_xor<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs bitwise XOR operation

Pops two values from the stack, performs bitwise XOR, and pushes the result. Converts values to integers before operation.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if insufficient operands
Source

pub fn bitwise_not<S>(stack: &mut S) -> Result<(), ExecutionError>
where S: StackOperations,

Performs bitwise NOT operation

Pops one value from the stack, performs bitwise NOT, and pushes the result. Converts value to integer before operation.

§Arguments
  • stack - The stack to operate on
§Returns
  • Ok(()) on success
  • Err(ExecutionError::StackUnderflow) if stack is empty

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.