Expand description
Tagged Stack Implementation
Stack operations using 8-byte tagged values (tagged pointers).
Encoding:
- Odd (bit 0 = 1): Int — 63-bit signed integer, value = tagged >> 1
- 0x0: Bool false
- 0x2: Bool true
- Even > 2: Heap pointer to Arc
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)
Constants§
- DISC_
BOOL - DISC_
CHANNEL - DISC_
CLOSURE - DISC_
FLOAT - DISC_
INT - Discriminant constants — retained for API compatibility with codegen and runtime code that switches on type. In tagged-ptr mode, these values are NOT stored in the StackValue itself (the tag is in the pointer bits). They are used only when the runtime unpacks a Value (via pop()) and needs to identify its type. Phase 2 codegen will use bit-level tag checks instead of loading these discriminants from memory.
- DISC_
MAP - DISC_
QUOTATION - DISC_
STRING - DISC_
SYMBOL - DISC_
VARIANT - DISC_
WEAVECTX
Functions§
- alloc_
stack - alloc_
test_ stack - clone_
stack ⚠ - Safety
- clone_
stack_ ⚠segment - Clone a stack segment.
- clone_
stack_ ⚠value - Clone a tagged StackValue, handling heap types.
- clone_
stack_ ⚠with_ base - Safety
- drop_
stack_ ⚠value - Drop a tagged StackValue, freeing heap types.
- drop_
top ⚠ - Drop the top value: ( a – )
- dup⚠
- Duplicate the top value: ( a – a a )
- get_
stack_ base - heap_
value_ ⚠mut - Get a mutable reference to a heap Value at the given stack position without popping (no Arc alloc/dealloc cycle).
- nip⚠
- Remove the second value: ( a b – b )
- over⚠
- Copy the second value to the top: ( a b – a b a )
- patch_
seq_ ⚠2dup - Duplicate top two values: ( a b – a b a b )
- patch_
seq_ ⚠clone_ value - Clone a StackValue from LLVM IR.
- patch_
seq_ ⚠drop_ op - Safety
- patch_
seq_ ⚠dup - Duplicate the top value: ( 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.
- patch_
seq_ ⚠push_ value - Safety
- patch_
seq_ ⚠roll - Roll: Rotate n+1 items, bringing the item at depth n to the top.
- patch_
seq_ ⚠rot - Rotate the top three values: ( a b c – b c a )
- patch_
seq_ ⚠set_ stack_ base - Safety
- patch_
seq_ ⚠stack_ dump - Dump all values on the stack (for REPL debugging).
- patch_
seq_ ⚠swap - Swap the top two values: ( a b – b a )
- patch_
seq_ ⚠tuck - Copy top value below second: ( a b – b a b )
- peek⚠
- Peek at the top value without removing it.
- peek_
heap_ ⚠mut - Convenience: get a mutable reference to the heap Value at stack top (sp - 1).
- peek_
heap_ ⚠mut_ second - Convenience: get a mutable reference to the heap Value at sp - 2 (second from top).
- peek_sv⚠
- Peek at the raw StackValue without removing it.
- pick⚠
- Pick: Copy the nth value to the top.
- pop⚠
- Pop a value from the stack.
- pop_sv⚠
- Pop a StackValue directly from the stack.
- pop_
three ⚠ - Pop three values from the stack.
- pop_two⚠
- Pop two values from the stack.
- push⚠
- Push a value onto the stack.
- push_sv⚠
- Push a StackValue directly onto the stack.
- roll⚠
- Roll: Rotate n+1 items, bringing the item at depth n to the top.
- rot⚠
- Rotate the top three values: ( a b c – b c a )
- stack_
value_ size - Returns the size of a StackValue in bytes
- stack_
value_ ⚠to_ value - Convert a tagged StackValue back to a Value (takes ownership)
- swap⚠
- Swap the top two values: ( a b – b a )
- tuck⚠
- Copy top value below second: ( a b – b a b )
- two_dup⚠
- Duplicate top two values: ( a b – a b a b )
- value_
to_ stack_ value - Convert a Value to a tagged StackValue
Type Aliases§
- Stack
- Stack: A pointer to the current position in a contiguous array of u64.