Struct Memory

Source
pub struct Memory {
    pub stack_memory_size: usize,
    pub stack_offset: usize,
    pub stack_start: usize,
    pub heap_start: usize,
    pub heap_alloc_offset: usize,
    pub constant_memory_size: usize,
    pub execution_mode: ExecutionMode,
    pub debug: MemoryDebug,
    /* private fields */
}
Expand description

VM Memory Layout (from lower to higher addresses):

  1. Constant Memory: Pre-compiled constant data (read-only)
  2. Constant Heap Allocations: Strings and other heap data allocated during constant evaluation
    • These allocations must be preserved between function calls as they contain constant string data
    • String pointers in constant memory reference this area
  3. Preserved Structs: Data structures that need to persist between engine ticks
    • Currently unused but reserved for future use
  4. Stack Space: Frame-placed variables and function call frames
    • Grows upward with each function call
    • Reset on function entry/exit
  5. Heap: Dynamic allocations during program execution
    • Reset after each tick to prevent memory leaks
    • Starts after the preserved area to avoid corrupting constant data

Fields§

§stack_memory_size: usize§stack_offset: usize§stack_start: usize§heap_start: usize§heap_alloc_offset: usize§constant_memory_size: usize§execution_mode: ExecutionMode§debug: MemoryDebug

Implementations§

Source§

impl Memory

Source

pub fn new( constant_memory: &[u8], stack_memory_size: usize, heap_memory_size: usize, ) -> Self

Source

pub fn reset_offset(&mut self)

Source

pub fn reset(&mut self)

Source

pub fn reset_allocator(&mut self)

Source

pub fn reset_stack_and_fp(&mut self)

Source

pub fn set_heap_directly_after_constant_area(&mut self)

Source

pub fn incorporate_heap_into_constant_area(&mut self)

Source

pub fn alloc_before_stack( &mut self, size: &MemorySize, alignment: &MemoryAlignment, ) -> HeapMemoryRegion

Source

pub fn get_heap_ptr(&self, offset: usize) -> *mut u8

Source

pub fn get_heap_const_ptr(&self, offset: usize) -> *const u8

Source

pub unsafe fn get_heap_offset(&self, ptr: *const u8) -> u32

Source

pub fn heap_allocate_secret(&mut self, size: usize) -> u32

Source

pub fn heap_allocate_with_data(&mut self, data: &[u8]) -> u32

Source

pub fn frame_offset(&self) -> usize

Source

pub const fn set_fp_from_sp(&mut self)

Usually called on a call It sets the FP to the current SP. The stack pointer includes the current function frame size but doesn’t include return values and arguments.

Source

pub fn frame_ptr(&self) -> *mut u8

Source

pub fn get_frame_ptr_as_u32(&self, offset: u32) -> *mut u32

Source

pub fn get_frame_ptr_as_u16(&self, offset: u32) -> *mut u16

Source

pub fn get_frame_ptr(&self, fp_offset: u32) -> *mut u8

Source

pub fn get_frame_const_ptr(&self, fp_offset: u32) -> *mut u8

Source

pub fn get_frame_ptr_as_i32(&self, some_addressing: u32) -> *mut i32

Source

pub fn get_frame_const_ptr_as_i32(&self, addressing: u32) -> *const i32

Source

pub fn get_frame_const_ptr_as_u32(&self, offset: u32) -> *const u32

Source

pub fn get_frame_const_ptr_as_u16(&self, addressing: u32) -> *const u16

Source

pub fn read_frame_i32(&self, offset: u32) -> i32

Source

pub fn read_frame_u8(&self, offset: u32) -> u8

Source

pub fn read_frame_bool(&self, offset: u32) -> bool

Source

pub fn read_frame_u16(&self, offset: u32) -> u16

Source

pub fn read_frame_u32(&self, offset: u32) -> u32

Source

pub const fn get_stack_const_ptr(&self, stack_offset: usize) -> *const u8

Source

pub fn read_heap_offset_via_frame(&self, frame_offset: u32) -> u32

Source

pub fn get_heap_ptr_via_frame(&self, frame_offset: u32) -> *mut u8

Source

pub fn get_heap_u32_ptr_via_frame(&self, frame_offset: u32) -> *mut u32

Source

pub fn get_heap_ptr_via_frame_with_offset( &self, frame_offset: u32, heap_ptr_offset: u32, ) -> *mut u8

Trait Implementations§

Source§

impl Drop for Memory

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Memory

§

impl RefUnwindSafe for Memory

§

impl !Send for Memory

§

impl !Sync for Memory

§

impl Unpin for Memory

§

impl UnwindSafe for Memory

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.