pub trait HeapOperations {
// Required methods
fn alloc_object(&mut self) -> HeapHandleId;
fn alloc_array(&mut self) -> HeapHandleId;
fn alloc_function(
&mut self,
bytecode: Bytecode,
arg_count: ArgIndex,
local_count: LocalIndex,
) -> HeapHandleId;
fn get_object_property(
&self,
handle: HeapHandleId,
key: &str,
) -> Option<&Value>;
fn set_object_property(
&mut self,
handle: HeapHandleId,
key: String,
value: Value,
);
fn set_array_element(
&mut self,
handle: HeapHandleId,
index: ArraySize,
value: Value,
);
fn get_heap(&self) -> &Heap;
// Provided methods
fn get_array_element(
&self,
_handle: HeapHandleId,
_index: ArraySize,
) -> Option<&Value> { ... }
fn has_object_property(&self, handle: HeapHandleId, key: &str) -> bool { ... }
fn get_array_length(&self, _handle: HeapHandleId) -> usize { ... }
}Expand description
Defines operations for managing the VM’s heap memory
This trait provides the interface for all heap operations including object allocation, property access, and memory management.
Required Methods§
Sourcefn alloc_object(&mut self) -> HeapHandleId
fn alloc_object(&mut self) -> HeapHandleId
Sourcefn alloc_array(&mut self) -> HeapHandleId
fn alloc_array(&mut self) -> HeapHandleId
Sourcefn alloc_function(
&mut self,
bytecode: Bytecode,
arg_count: ArgIndex,
local_count: LocalIndex,
) -> HeapHandleId
fn alloc_function( &mut self, bytecode: Bytecode, arg_count: ArgIndex, local_count: LocalIndex, ) -> HeapHandleId
Sourcefn get_object_property(&self, handle: HeapHandleId, key: &str) -> Option<&Value>
fn get_object_property(&self, handle: HeapHandleId, key: &str) -> Option<&Value>
Sourcefn set_object_property(
&mut self,
handle: HeapHandleId,
key: String,
value: Value,
)
fn set_object_property( &mut self, handle: HeapHandleId, key: String, value: Value, )
Sets a property value on an object
§Arguments
handle- The handle to the objectkey- The name of the property to setvalue- The value to assign to the property
Sourcefn set_array_element(
&mut self,
handle: HeapHandleId,
index: ArraySize,
value: Value,
)
fn set_array_element( &mut self, handle: HeapHandleId, index: ArraySize, value: Value, )
Sets an element in an array
§Arguments
handle- The handle to the arrayindex- The index where to set the elementvalue- The value to assign to the array element