pub struct HeapOpsHandler;Expand description
Handles heap operations for the VM
Implementations§
Source§impl HeapOpsHandler
impl HeapOpsHandler
Sourcepub fn alloc_object<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn alloc_object<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap to allocate the object in
§Returns
Ok(())on successErr(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(_)));Sourcepub fn alloc_array<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn alloc_array<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn alloc_function<S, H>(
stack: &mut S,
heap: &mut H,
bytecode: Bytecode,
arg_count: ArgIndex,
local_count: LocalIndex,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn alloc_function<S, H>(
stack: &mut S,
heap: &mut H,
bytecode: Bytecode,
arg_count: ArgIndex,
local_count: LocalIndex,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap to allocate the function inbytecode- The function’s bytecodearg_count- The number of arguments the function acceptslocal_count- The number of local variables the function uses
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn alloc_string<S, H>(
stack: &mut S,
_heap: &mut H,
value: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn alloc_string<S, H>(
stack: &mut S,
_heap: &mut H,
value: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 successErr(ExecutionError)on failure
Sourcepub fn get_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn get_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap containing the objectobject_handle- The handle to the objectproperty_key- The name of the property to retrieve
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn set_object_property<S, H>(
_stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn set_object_property<S, H>(
_stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 objectobject_handle- The handle to the objectproperty_key- The name of the property to setvalue- The value to assign to the property
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn get_array_element<S, H>(
stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
index: ArraySize,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn get_array_element<S, H>(
stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
index: ArraySize,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap containing the arrayarray_handle- The handle to the arrayindex- The index of the element to retrieve
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn set_array_element<S, H>(
_stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
index: ArraySize,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn set_array_element<S, H>(
_stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
index: ArraySize,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 arrayarray_handle- The handle to the arrayindex- The index where to set the elementvalue- The value to assign to the array element
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn push_array_element<S, H>(
_stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn push_array_element<S, H>(
_stack: &mut S,
heap: &mut H,
array_handle: HeapHandle<ArrayEntry>,
value: Value,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 arrayarray_handle- The handle to the arrayvalue- The value to add to the array
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn remove_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn remove_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap containing the objectobject_handle- The handle to the objectproperty_key- The name of the property to remove
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn has_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn has_object_property<S, H>(
stack: &mut S,
heap: &mut H,
object_handle: HeapHandle<ObjectEntry>,
property_key: String,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap containing the objectobject_handle- The handle to the objectproperty_key- The name of the property to check
§Returns
Ok(())on successErr(ExecutionError)on failure
Sourcepub fn get_heap_size<S, H>(
stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn get_heap_size<S, H>(
stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn is_heap_empty<S, H>(
stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn is_heap_empty<S, H>(
stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn clear_heap<S, H>(
_stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn clear_heap<S, H>(
_stack: &mut S,
_heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn collect_garbage<S, H>(
stack: &mut S,
_heap: &mut H,
_roots: Vec<HeapHandle<ObjectEntry>>,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn collect_garbage<S, H>(
stack: &mut S,
_heap: &mut H,
_roots: Vec<HeapHandle<ObjectEntry>>,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn get_heap_stats<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn get_heap_stats<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn get_heap_metrics<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn get_heap_metrics<S, H>(
stack: &mut S,
heap: &mut H,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
Sourcepub fn clone_heap_entry<S, H>(
stack: &mut S,
heap: &mut H,
_handle: HeapHandle<ObjectEntry>,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
pub fn clone_heap_entry<S, H>(
stack: &mut S,
heap: &mut H,
_handle: HeapHandle<ObjectEntry>,
) -> Result<(), ExecutionError>where
S: StackOperations,
H: HeapOperations,
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 ontoheap- The heap to allocate the clone in_handle- The handle to clone (unused in this implementation)
§Returns
Ok(())on successErr(ExecutionError)on failure