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):
- Constant Memory: Pre-compiled constant data (read-only)
- 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
- Preserved Structs: Data structures that need to persist between engine ticks
- Currently unused but reserved for future use
- Stack Space: Frame-placed variables and function call frames
- Grows upward with each function call
- Reset on function entry/exit
- 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: MemoryDebugImplementations§
Source§impl Memory
impl Memory
pub fn new( constant_memory: &[u8], stack_memory_size: usize, heap_memory_size: usize, ) -> Self
pub fn reset_offset(&mut self)
pub fn reset(&mut self)
pub fn reset_allocator(&mut self)
pub fn reset_stack_and_fp(&mut self)
pub fn set_heap_directly_after_constant_area(&mut self)
pub fn incorporate_heap_into_constant_area(&mut self)
pub fn alloc_before_stack( &mut self, size: &MemorySize, alignment: &MemoryAlignment, ) -> HeapMemoryRegion
pub fn get_heap_ptr(&self, offset: usize) -> *mut u8
pub fn get_heap_const_ptr(&self, offset: usize) -> *const u8
pub unsafe fn get_heap_offset(&self, ptr: *const u8) -> u32
pub fn heap_allocate_secret(&mut self, size: usize) -> u32
pub fn heap_allocate_with_data(&mut self, data: &[u8]) -> u32
pub fn frame_offset(&self) -> usize
Sourcepub const fn set_fp_from_sp(&mut self)
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.
pub fn frame_ptr(&self) -> *mut u8
pub fn get_frame_ptr_as_u32(&self, offset: u32) -> *mut u32
pub fn get_frame_ptr_as_u16(&self, offset: u32) -> *mut u16
pub fn get_frame_ptr(&self, fp_offset: u32) -> *mut u8
pub fn get_frame_const_ptr(&self, fp_offset: u32) -> *mut u8
pub fn get_frame_ptr_as_i32(&self, some_addressing: u32) -> *mut i32
pub fn get_frame_const_ptr_as_i32(&self, addressing: u32) -> *const i32
pub fn get_frame_const_ptr_as_u32(&self, offset: u32) -> *const u32
pub fn get_frame_const_ptr_as_u16(&self, addressing: u32) -> *const u16
pub fn read_frame_i32(&self, offset: u32) -> i32
pub fn read_frame_u8(&self, offset: u32) -> u8
pub fn read_frame_bool(&self, offset: u32) -> bool
pub fn read_frame_u16(&self, offset: u32) -> u16
pub fn read_frame_u32(&self, offset: u32) -> u32
pub const fn get_stack_const_ptr(&self, stack_offset: usize) -> *const u8
pub fn read_heap_offset_via_frame(&self, frame_offset: u32) -> u32
pub fn get_heap_ptr_via_frame(&self, frame_offset: u32) -> *mut u8
pub fn get_heap_u32_ptr_via_frame(&self, frame_offset: u32) -> *mut u32
pub fn get_heap_ptr_via_frame_with_offset( &self, frame_offset: u32, heap_ptr_offset: u32, ) -> *mut u8
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);