Skip to main content

Value

Enum Value 

Source
pub enum Value {
Show 16 variants Nil, True, Empty, Int(i32), Obj(ObjId), Prop(PropId), SString(u32), DString(u32), List(u32), CodeOfs(u32), FuncPtr(u32), Enum(u32), BifPtr { set: u16, index: u16, }, ObjX(ObjId), BifPtrX { set: u16, index: u16, }, NativeCode(NativeDesc),
}
Expand description

A value, as the virtual machine holds one.

The variants mirror the reference VM’s value types. Strings and lists appear twice: as constants (an offset into the image’s constant pool) and as objects (an ObjId of a string or list object).

Variants§

§

Nil

nil: false, and the absence of a value.

§

True

true.

§

Empty

No value at all. Marks unused slots; programs never see it.

§

Int(i32)

A 32-bit integer.

§

Obj(ObjId)

An object reference.

§

Prop(PropId)

A property ID.

§

SString(u32)

A constant string, by constant pool offset.

§

DString(u32)

A constant string that displays itself when evaluated as a property.

§

List(u32)

A constant list, by constant pool offset.

§

CodeOfs(u32)

Method code, by code pool offset. Only property values have this type; evaluating the property calls the code.

§

FuncPtr(u32)

A function pointer, by code pool offset.

§

Enum(u32)

An enumerator.

§

BifPtr

A pointer to a function the VM implements.

Fields

§set: u16

Index of the function set in the image’s dependency list.

§index: u16

Index of the function within the set.

§

ObjX(ObjId)

An object to invoke when the property holding it is evaluated.

§

BifPtrX

A VM function to call when the property holding it is evaluated.

Fields

§set: u16

Index of the function set in the image’s dependency list.

§index: u16

Index of the function within the set.

§

NativeCode(NativeDesc)

A method the VM implements, as found by a property lookup that asked not to call it.

Implementations§

Source§

impl Value

Source

pub const HOLDER_SIZE: usize = 5

Size of a value as images encode it: a type byte and four data bytes.

Source

pub const fn logical(condition: bool) -> Self

true or nil.

Source

pub const fn obj_or_nil(id: ObjId) -> Self

An object reference, or nil for the invalid ID.

Source

pub const fn as_obj(self) -> Option<ObjId>

The object ID, if this is an object reference.

Source

pub const fn obj_id(self) -> ObjId

The object ID, or the invalid ID for anything but an object.

Source

pub const fn is_nil(self) -> bool

Whether this is nil.

Source

pub const fn is_invocable_prop(self) -> bool

Whether evaluating a property with this value runs code.

Source

pub const fn type_code(self) -> i32

The type code of this value.

Source

pub fn to_holder(self) -> [u8; 5]

Encode a value in the five-byte form images and saved states use.

Source

pub fn from_holder(b: &[u8]) -> Self

Decode a value from the five-byte form images use.

Type codes that cannot appear in an image decode as nil.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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 Copy for Value

Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Value

Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.