Expand description
Tagged Stack Implementation
This module implements the stack using a contiguous array of 40-byte StackValue entries. Each StackValue has the layout: { slot0: discriminant, slot1-4: payload }
The Stack type is a pointer to the “current position” (where next push goes).
- Push: store at *sp, return sp + 1
- Pop: return sp - 1, read from *(sp - 1)
Re-exports§
pub use patch_seq_2dup as two_dup;pub use patch_seq_3drop as three_drop;pub use patch_seq_dup as dup;pub use patch_seq_nip as nip;pub use patch_seq_over as over;pub use patch_seq_pick_op as pick;pub use patch_seq_roll as roll;pub use patch_seq_rot as rot;pub use patch_seq_swap as swap;pub use patch_seq_tuck as tuck;
Constants§
- DISC_
BOOL - DISC_
CHANNEL - DISC_
CLOSURE - DISC_
FLOAT - DISC_
INT - Discriminant values matching codegen
- DISC_
MAP - DISC_
QUOTATION - DISC_
STRING - DISC_
VARIANT
Functions§
- alloc_
stack - Allocate a new stack with default capacity. Returns a pointer to the base of the stack (where first push goes).
- clone_
stack ⚠ - Clone the current stack for spawning a child strand
- clone_
stack_ ⚠segment - Clone a stack segment
- clone_
stack_ ⚠value - Clone a StackValue, handling reference counting for heap types.
- clone_
stack_ ⚠with_ base - Clone the current stack for spawning, returning both base and sp.
- drop_
stack_ ⚠value - Drop a StackValue, decrementing refcounts for heap types
- drop_
top ⚠ - Drop the top value from the stack: ( a – )
- get_
stack_ base - Get the current strand’s stack base
- is_
empty - Check if stack is empty (at base pointer) Note: With tagged stack, we need to compare against base, not null
- patch_
seq_ ⚠2dup - Duplicate top two values: ( a b – a b a b )
- patch_
seq_ ⚠3drop - Drop top three values: ( a b c – )
- patch_
seq_ ⚠clone_ value - Clone a StackValue from LLVM IR - reads from src pointer, writes to dst pointer. This is the FFI-callable version for inline codegen that avoids ABI issues with passing large structs by value.
- patch_
seq_ ⚠drop_ op - Alias for drop to avoid LLVM keyword conflicts
- patch_
seq_ ⚠dup - Duplicate the top value on the stack: ( a – a a )
- patch_
seq_ ⚠nip - Remove the second value: ( a b – b )
- patch_
seq_ ⚠over - Copy the second value to the top: ( a b – a b a )
- patch_
seq_ ⚠pick_ op - Pick: Copy the nth value to the top ( … xn … x1 x0 n – … xn … x1 x0 xn )
- patch_
seq_ ⚠push_ value - Push an arbitrary Value onto the stack (for LLVM codegen)
- patch_
seq_ ⚠roll - Roll: Rotate n+1 items, bringing the item at depth n to the top ( x_n x_(n-1) … x_1 x_0 n – x_(n-1) … x_1 x_0 x_n )
- patch_
seq_ ⚠rot - Rotate the top three values: ( a b c – b c a )
- patch_
seq_ ⚠set_ stack_ base - Set the current strand’s stack base (called at strand entry)
- patch_
seq_ ⚠swap - Swap the top two values: ( a b – b a )
- patch_
seq_ ⚠tuck - Copy top value below second value: ( a b – b a b )
- peek⚠
- Peek at the top value without removing it
- peek_sv⚠
- Peek at the raw StackValue without removing it
- pop⚠
- Pop a value from the stack
- pop_sv⚠
- Pop a StackValue directly from the stack
- pop_
three ⚠ - Pop three values from the stack (for ternary operations)
- pop_two⚠
- Pop two values from the stack (for binary operations)
- push⚠
- Push a value onto the stack
- push_sv⚠
- Push a StackValue directly onto the stack
- stack_
value_ ⚠to_ value - Convert a StackValue back to a Value
- value_
to_ stack_ value - Convert a Value to a StackValue for pushing onto the tagged stack
Type Aliases§
- Stack
- Stack: A pointer to the current position in a contiguous array of StackValue.