Expand description
Type-erased stack that carries values between function calls.
DataStack is the single place where Intuicio moves data. Native and
script functions both take their arguments off it and put their results
back on it, so neither side can tell the other apart.
§Layout
The stack is one flat byte buffer that grows upwards. Each pushed value is
stored as its bytes followed by its TypeHash, so a pop can check the
type before reading anything back. The stack also remembers a drop function
per type it has seen, so it can destroy values it no longer knows the Rust
type of.
Registers, the analogue of local variables, live on the same buffer. A
register is a slot with a fixed type that can be empty or full, and it is
addressed by index rather than by position. See DataStackRegisterAccess.
§Rules
Data is only ever moved, never copied or cloned. A pop takes the value off the stack. A move into a register empties the place the value came from. A type that wants copies has to provide a function that pushes a duplicate itself.
let mut stack = DataStack::new(1024, DataStackMode::Mixed);
stack.push(42_i32);
assert_eq!(stack.pop::<i32>().unwrap(), 42);Structs§
- Data
Stack - Type-erased stack of values and registers.
- Data
Stack Register Access - Handle to one register slot, taken with
DataStack::access_register. - Data
Stack Token - Marker of a stack position, taken with
DataStack::store.
Enums§
- Data
Stack Mode - What a
DataStackis allowed to hold. - Data
Stack Visited Item - One item seen by
DataStack::visit, reported from the top down.
Traits§
- Data
Stack Pack - Moves a tuple of values on and off a
DataStackin one step.