Struct HeapOpsHandler

Source
pub struct HeapOpsHandler;
Expand description

Handles heap operations for the VM

Implementations§

Source§

impl HeapOpsHandler

Source

pub fn alloc_object<S, H>( stack: &mut S, heap: &mut H, ) -> Result<(), ExecutionError>

Allocates a new object on the heap

Creates a new empty object and pushes its handle onto the stack.

§Arguments
  • stack - The stack to push the object handle onto
  • heap - The heap to allocate the object in
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
§Examples
let mut stack = MyStack::new();
let mut heap = MyHeap::new();
HeapOpsHandler::alloc_object(&mut stack, &mut heap)?;
let handle = stack.pop().unwrap();
assert!(matches!(handle, Value::Object(_)));
Source

pub fn alloc_array<S, H>( stack: &mut S, heap: &mut H, ) -> Result<(), ExecutionError>

Allocates a new array on the heap

Creates a new empty array and pushes its handle onto the stack.

§Arguments
  • stack - The stack to push the array handle onto
  • heap - The heap to allocate the array in
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn alloc_function<S, H>( stack: &mut S, heap: &mut H, bytecode: Bytecode, arg_count: ArgIndex, local_count: LocalIndex, ) -> Result<(), ExecutionError>

Allocates a new function on the heap

Creates a new function with the specified bytecode and metadata.

§Arguments
  • stack - The stack to push the function handle onto
  • heap - The heap to allocate the function in
  • bytecode - The function’s bytecode
  • arg_count - The number of arguments the function accepts
  • local_count - The number of local variables the function uses
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn alloc_string<S, H>( stack: &mut S, _heap: &mut H, value: String, ) -> Result<(), ExecutionError>

Allocates a string value

Creates a new string value and pushes it onto the stack. Note: This is a simplified implementation that directly pushes the string.

§Arguments
  • stack - The stack to push the string onto
  • _heap - The heap (unused in this implementation)
  • value - The string value to allocate
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn get_object_property<S, H>( stack: &mut S, heap: &mut H, object_handle: HeapHandle<ObjectEntry>, property_key: String, ) -> Result<(), ExecutionError>

Gets a property from an object

Retrieves the value of a property from an object and pushes it onto the stack.

§Arguments
  • stack - The stack to push the property value onto
  • heap - The heap containing the object
  • object_handle - The handle to the object
  • property_key - The name of the property to retrieve
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn set_object_property<S, H>( _stack: &mut S, heap: &mut H, object_handle: HeapHandle<ObjectEntry>, property_key: String, value: Value, ) -> Result<(), ExecutionError>

Sets a property on an object

Sets the value of a property on an object.

§Arguments
  • stack - The stack (unused in this operation)
  • heap - The heap containing the object
  • object_handle - The handle to the object
  • property_key - The name of the property to set
  • value - The value to assign to the property
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn get_array_element<S, H>( stack: &mut S, heap: &mut H, array_handle: HeapHandle<ArrayEntry>, index: ArraySize, ) -> Result<(), ExecutionError>

Gets an element from an array

Retrieves the value at a specific index in an array and pushes it onto the stack.

§Arguments
  • stack - The stack to push the array element onto
  • heap - The heap containing the array
  • array_handle - The handle to the array
  • index - The index of the element to retrieve
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn set_array_element<S, H>( _stack: &mut S, heap: &mut H, array_handle: HeapHandle<ArrayEntry>, index: ArraySize, value: Value, ) -> Result<(), ExecutionError>

Sets an element in an array

Sets the value at a specific index in an array.

§Arguments
  • stack - The stack (unused in this operation)
  • heap - The heap containing the array
  • array_handle - The handle to the array
  • index - The index where to set the element
  • value - The value to assign to the array element
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn push_array_element<S, H>( _stack: &mut S, heap: &mut H, array_handle: HeapHandle<ArrayEntry>, value: Value, ) -> Result<(), ExecutionError>

Pushes an element to the end of an array

Adds a new element to the end of an array.

§Arguments
  • _stack - The stack (unused in this operation)
  • heap - The heap containing the array
  • array_handle - The handle to the array
  • value - The value to add to the array
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn remove_object_property<S, H>( stack: &mut S, heap: &mut H, object_handle: HeapHandle<ObjectEntry>, property_key: String, ) -> Result<(), ExecutionError>

Removes a property from an object

Removes a property from an object and pushes a boolean indicating success.

§Arguments
  • stack - The stack to push the result onto
  • heap - The heap containing the object
  • object_handle - The handle to the object
  • property_key - The name of the property to remove
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn has_object_property<S, H>( stack: &mut S, heap: &mut H, object_handle: HeapHandle<ObjectEntry>, property_key: String, ) -> Result<(), ExecutionError>

Checks if an object has a specific property

Determines whether an object has a property with the given name.

§Arguments
  • stack - The stack to push the result onto
  • heap - The heap containing the object
  • object_handle - The handle to the object
  • property_key - The name of the property to check
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn get_heap_size<S, H>( stack: &mut S, _heap: &mut H, ) -> Result<(), ExecutionError>

Gets the current size of the heap

Pushes the current heap size onto the stack.

§Arguments
  • stack - The stack to push the heap size onto
  • _heap - The heap (unused in this implementation)
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn is_heap_empty<S, H>( stack: &mut S, _heap: &mut H, ) -> Result<(), ExecutionError>

Checks if the heap is empty

Pushes a boolean indicating whether the heap is empty.

§Arguments
  • stack - The stack to push the result onto
  • _heap - The heap (unused in this implementation)
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn clear_heap<S, H>( _stack: &mut S, _heap: &mut H, ) -> Result<(), ExecutionError>

Clears all objects from the heap

Removes all objects from the heap, freeing all memory.

§Arguments
  • _stack - The stack (unused in this operation)
  • _heap - The heap to clear
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn collect_garbage<S, H>( stack: &mut S, _heap: &mut H, _roots: Vec<HeapHandle<ObjectEntry>>, ) -> Result<(), ExecutionError>

Triggers garbage collection

Initiates garbage collection to free unused memory.

§Arguments
  • stack - The stack to push the result onto
  • _heap - The heap to collect garbage from
  • _roots - The root objects to preserve during collection
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn get_heap_stats<S, H>( stack: &mut S, heap: &mut H, ) -> Result<(), ExecutionError>

Gets heap statistics

Creates an object containing various heap statistics and pushes it onto the stack.

§Arguments
  • stack - The stack to push the stats object onto
  • heap - The heap to get statistics from
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn get_heap_metrics<S, H>( stack: &mut S, heap: &mut H, ) -> Result<(), ExecutionError>

Gets heap performance metrics

Creates an object containing various heap performance metrics and pushes it onto the stack.

§Arguments
  • stack - The stack to push the metrics object onto
  • heap - The heap to get metrics from
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn clone_heap_entry<S, H>( stack: &mut S, heap: &mut H, _handle: HeapHandle<ObjectEntry>, ) -> Result<(), ExecutionError>

Clones a heap entry

Creates a copy of a heap entry and pushes the new handle onto the stack.

§Arguments
  • stack - The stack to push the cloned handle onto
  • heap - The heap to allocate the clone in
  • _handle - The handle to clone (unused in this implementation)
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure
Source

pub fn deallocate<S, H>( _stack: &mut S, _heap: &mut H, _handle: HeapHandle<ObjectEntry>, ) -> Result<(), ExecutionError>

Deallocates a heap entry

Frees the memory associated with a heap entry.

§Arguments
  • _stack - The stack (unused in this operation)
  • _heap - The heap containing the entry
  • _handle - The handle to deallocate
§Returns
  • Ok(()) on success
  • Err(ExecutionError) on failure

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.