Trait VariableManager

Source
pub trait VariableManager {
    // Required methods
    fn get_local(&self, idx: usize) -> Option<&Value>;
    fn set_local(&mut self, idx: usize, value: Value);
    fn get_global(&self, idx: usize) -> Option<&Value>;
    fn set_global(&mut self, idx: usize, value: Value);
    fn get_local_mut(&mut self, idx: usize) -> Option<&mut Value>;
    fn get_global_mut(&mut self, idx: usize) -> Option<&mut Value>;

    // Provided methods
    fn get_argument(&self, idx: usize) -> Option<&Value> { ... }
    fn set_argument(&mut self, idx: usize, value: Value) { ... }
}
Expand description

Defines operations for managing VM variables

This trait provides the interface for all variable operations including local variables, global variables, and function arguments.

Required Methods§

Source

fn get_local(&self, idx: usize) -> Option<&Value>

Gets a local variable by index

§Arguments
  • idx - The index of the local variable
§Returns
  • Some(&value) if the variable exists
  • None if the variable does not exist
Source

fn set_local(&mut self, idx: usize, value: Value)

Sets a local variable by index

§Arguments
  • idx - The index of the local variable
  • value - The value to assign to the variable
Source

fn get_global(&self, idx: usize) -> Option<&Value>

Gets a global variable by index

§Arguments
  • idx - The index of the global variable
§Returns
  • Some(&value) if the variable exists
  • None if the variable does not exist
Source

fn set_global(&mut self, idx: usize, value: Value)

Sets a global variable by index

§Arguments
  • idx - The index of the global variable
  • value - The value to assign to the variable
Source

fn get_local_mut(&mut self, idx: usize) -> Option<&mut Value>

Gets a mutable reference to a local variable by index

§Arguments
  • idx - The index of the local variable
§Returns
  • Some(&mut value) if the variable exists
  • None if the variable does not exist
Source

fn get_global_mut(&mut self, idx: usize) -> Option<&mut Value>

Gets a mutable reference to a global variable by index

§Arguments
  • idx - The index of the global variable
§Returns
  • Some(&mut value) if the variable exists
  • None if the variable does not exist

Provided Methods§

Source

fn get_argument(&self, idx: usize) -> Option<&Value>

Gets a function argument by index

This is a convenience method that delegates to get_local().

§Arguments
  • idx - The index of the argument
§Returns
  • Some(&value) if the argument exists
  • None if the argument does not exist
Source

fn set_argument(&mut self, idx: usize, value: Value)

Sets a function argument by index

This is a convenience method that delegates to set_local().

§Arguments
  • idx - The index of the argument
  • value - The value to assign to the argument

Implementors§