Skip to main content

Module value_word

Module value_word 

Source
Expand description

ValueWord: 8-byte NaN-boxed value representation for the VM stack.

Uses IEEE 754 quiet NaN space to pack type tags and payloads into 8 bytes. Simple types (f64, i48, bool, None, Unit, Function) are stored inline. Complex types are heap-allocated as Arc<HeapValue> with the raw pointer in the payload.

§NaN-boxing scheme

All tagged values use sign bit = 1 with a quiet NaN exponent, giving us 51 bits for tag + payload. Normal f64 values (including NaN, which is canonicalized to a positive quiet NaN) are stored directly and never collide with our tagged range.

Tagged: 0xFFF[C-F]_XXXX_XXXX_XXXX
  Bit 63    = 1 (sign, marks as tagged)
  Bits 62-52 = 0x7FF (NaN exponent)
  Bit 51    = 1 (quiet NaN bit)
  Bits 50-48 = tag (3 bits)
  Bits 47-0  = payload (48 bits)
TagMeaning
0b000Heap pointer to Arc<HeapValue> (48-bit ptr)
0b001i48 (48-bit signed integer, sign-extended)
0b010Bool (payload bit 0)
0b011None
0b100Unit
0b101Function(u16) (payload = function_id)
0b110ModuleFunction(u32) (payload = index)
0b111Ref (absolute stack slot index, 48 bits)

Structs§

ValueWord
An 8-byte value word for the VM stack (NaN-boxed encoding).

Enums§

ArrayView
Unified read-only view over all array variants (generic, int, float, bool, width-specific).
ArrayViewMut
Mutable view over all array variants. Uses Arc::make_mut for COW semantics.
NanTag
Tag discriminator for ValueWord values.
RefTarget