Skip to main content

Value

Struct Value 

Source
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

Source

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.

Source

pub fn bool(b: bool) -> Value

box a bool. the data field is 0 for false, 1 for true.

Source

pub fn byte(b: u8) -> Value

box a byte. the data field carries the u8 value.

Source

pub fn void() -> Value

the singleton void value – the runtime shape of a void-typed expression’s result. the data field is unused.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn as_bool(self) -> Option<bool>

decode this value as a bool. returns None when the value is not a boxed bool.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more