pub struct Value(/* private fields */);Expand description
the NaN-boxed 8-byte runtime value.
Value is a u64 newtype. a real IEEE 754 f64 is stored verbatim via
f64::to_bits; every non-float kind is a quiet NaN whose reserved top
16 bits select the kind and whose low 48 bits carry the data. derives
Clone, Copy, PartialEq – one machine word, cheaper to copy than to
reference. NOT Eq: two Values wrapping f64::NAN are not equal, the
same IEEE 754 rule the ConstValue enum follows.
there is no i64 kind. every i64 value is a heap object and a Value
holding one is a Value::pointer; value.rs carries no integer
encoding. this keeps the codec a single clean match and every arithmetic
opcode a single path (the uniform-heap-box decision – see the module
research notes).
Implementations§
Source§impl Value
impl Value
Sourcepub fn from_f64(x: f64) -> Value
pub fn from_f64(x: f64) -> Value
box an f64, storing its bits verbatim. a finite value, inf,
-inf, -0.0, and a genuine NaN all round-trip: Value::as_f64
returns Some for every one of them, because a computed NaN’s tag
bits (0x7FF8) are not in the reserved tagged range.
Sourcepub fn void() -> Value
pub fn void() -> Value
the singleton void value – the runtime shape of a void-typed
expression’s result. the data field is unused.
Sourcepub fn pointer(slot: u32) -> Value
pub fn pointer(slot: u32) -> Value
box a heap pointer. slot is the index of a crate::vm heap
object; the 48-bit data field holds a u32 slot with room to spare.
Sourcepub fn function(id: u16) -> Value
pub fn function(id: u16) -> Value
box a function value. id is the function’s index into
Program.chunks (a CALL operand). a function value is a tagged scalar,
NOT a heap object: the u16 id rides directly in the data field. the
VM’s CONST handler builds one of these for a ConstValue::Function,
and the higher-order stdlib functions (map / filter / reduce)
recover the id via Value::as_function.
Sourcepub fn bits(self) -> u64
pub fn bits(self) -> u64
the raw 64-bit pattern. exposed for the VM’s get_state rendering and
for tests that need to inspect the encoding directly.
Sourcepub fn is_tagged(self) -> bool
pub fn is_tagged(self) -> bool
true when this value is a tagged box (a function, bool, byte,
void, or pointer), false when it is a real f64.
the test masks the top 16 bits and range-checks 0x7FFB..=0x7FFF. a
genuine computed NaN has top bits 0x7FF8 and is therefore NOT
tagged – it correctly reads back as an f64. never use
f64::is_nan for this test: a real NaN and a boxed value share the
exponent and quiet-bit pattern, only the reserved tag bits separate
them.
Sourcepub fn as_f64(self) -> Option<f64>
pub fn as_f64(self) -> Option<f64>
decode this value as an f64. returns Some for any value that is
not a tagged box – a finite float, inf, -inf, -0.0, and a
genuine NaN all decode here. returns None for a bool / byte /
void / pointer.
Sourcepub fn as_bool(self) -> Option<bool>
pub fn as_bool(self) -> Option<bool>
decode this value as a bool. returns None when the value is not a
boxed bool.
Sourcepub fn as_byte(self) -> Option<u8>
pub fn as_byte(self) -> Option<u8>
decode this value as a byte. returns None when the value is not a
boxed byte. the data field is masked to 8 bits so a stray high bit
cannot widen the result.
Sourcepub fn as_void(self) -> bool
pub fn as_void(self) -> bool
true when this value is the singleton void. returns a bool
rather than Option<()> – void carries no data, so the only
question is whether the value is void at all.
Sourcepub fn as_pointer(self) -> Option<u32>
pub fn as_pointer(self) -> Option<u32>
decode this value as a heap pointer slot index. returns None when
the value is not a boxed pointer. the data field is masked to 32 bits
so the result is exactly the u32 slot Value::pointer stored.
Sourcepub fn as_function(self) -> Option<u16>
pub fn as_function(self) -> Option<u16>
decode this value as a function id. returns None when the value is
not a boxed function. the data field is masked to 16 bits so the
result is exactly the u16 id Value::function stored.