Module stack

Module stack 

Source
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.