Expand description
Tagged Stack Implementation
A contiguous array of 40-byte values for high-performance stack operations.
The 40-byte size matches Rust’s Value enum with #[repr(C)] and the LLVM
%Value = type { i64, i64, i64, i64, i64 } layout, enabling interoperability
between inline IR and FFI operations.
§Stack Value Layout (40 bytes)
┌─────────────────────────────────────────────────────────────────────────────┐
│ slot0 (8 bytes) │ slot1 │ slot2 │ slot3 │ slot4 │
├───────────────────┼─────────┼─────────┼─────────┼─────────┤
│ Discriminant │ Payload │ data │ data │ data │
└─────────────────────────────────────────────────────────────────────────────┘
Value discriminants:
- 0 = Int: slot1 contains i64 value
- 1 = Float: slot1 contains f64 bits
- 2 = Bool: slot1 contains 0 or 1
- 3 = String, 4 = Variant, 5 = Map, 6 = Quotation, 7 = Closure§Stack Layout
Stack: contiguous array of 40-byte StackValue slots
┌──────────┬──────────┬──────────┬──────────┬─────────┐
│ v0 │ v1 │ v2 │ v3 │ ... │
│ (40 B) │ (40 B) │ (40 B) │ (40 B) │ │
└──────────┴──────────┴──────────┴──────────┴─────────┘
↑ SP
- Grows upward
- SP points to next free slot
- Push: store at SP, increment SP
- Pop: decrement SP, load from SP§Performance Considerations
The 40-byte size enables:
- Direct compatibility with Rust’s Value enum (#[repr(C)])
- No conversion overhead when calling runtime functions
- Simple inline integer/boolean operations in compiled code
Modules§
- heap_
flags - Flags for HeapObject
Structs§
- Bool
Object - Bool heap object
- Float
Object - Float heap object
- Heap
Object - Heap object header (8 bytes)
- Quotation
Object - Quotation heap object (stateless function)
- Stack
Value - A 40-byte stack value, layout-compatible with LLVM’s %Value type.
- Tagged
Stack - Stack state for the tagged value stack
Enums§
- HeapTag
- Heap object type tags
Constants§
- DEFAULT_
STACK_ CAPACITY - Default stack capacity (number of stack values)
- STACK_
VALUE_ SIZE - Size of StackValue in bytes (should be 40)
- TAG_
HEAP - Heap pointer tag (low bit clear)
- TAG_INT
- Integer tag (low bit set)
- TAG_
MASK - Tag bit mask
Functions§
- is_
tagged_ heap - Check if a tagged value is a heap pointer
- is_
tagged_ int - Check if a tagged value is an integer
- seq_
alloc_ bool - Allocate a bool heap object
- seq_
alloc_ float - Allocate a float heap object
- seq_
alloc_ quotation - Allocate a quotation heap object
- seq_
free_ ⚠heap_ object - Free a heap object based on its type tag
- seq_
get_ ⚠bool - Get the bool value from a BoolObject
- seq_
get_ ⚠float - Get the float value from a FloatObject
- seq_
heap_ ⚠decref - Decrement the reference count of a heap object, freeing if zero
- seq_
heap_ ⚠incref - Increment the reference count of a heap object
- seq_
stack_ ⚠base - Get the base pointer of a tagged stack
- seq_
stack_ ⚠capacity - Get the capacity of a tagged stack
- seq_
stack_ ⚠clone - Clone a tagged stack (for spawn)
- seq_
stack_ ⚠free - Free a tagged stack
- seq_
stack_ ⚠grow - Grow a tagged stack to at least the given capacity
- seq_
stack_ new - Allocate a new tagged stack
- seq_
stack_ new_ default - Allocate a new tagged stack with default capacity
- seq_
stack_ ⚠set_ sp - Set the current stack pointer (as index)
- seq_
stack_ ⚠sp - Get the current stack pointer (as index)
- tag_
heap_ ptr - Create a tagged heap pointer from a raw pointer
- tag_int
- Create a tagged integer from an i64
- untag_
heap_ ptr - Extract a heap pointer from a tagged value
- untag_
int - Extract an i64 from a tagged integer
Type Aliases§
- Tagged
Value - Legacy type alias for backward compatibility