Skip to main content

RtObject

Struct RtObject 

Source
pub struct RtObject { /* private fields */ }
Expand description

The core runtime value representation.

RtObject uses a tagged encoding to store small values inline (in the u64 itself) and reference heap-allocated objects for larger values. This avoids allocation for common cases like small naturals, booleans, and unit.

Implementations§

Source§

impl RtObject

Source

pub fn bool_val(b: bool) -> Self

Create a boolean value.

Source§

impl RtObject

Source

pub fn char_val(c: char) -> Self

Create a character value.

Source§

impl RtObject

Source

pub fn float_bits(bits: u64) -> Self

Create a float from reduced-precision bits.

Source§

impl RtObject

Source

pub fn from_raw_bits(bits: u64) -> Self

Create from raw bits (used for deserialization).

Source§

impl RtObject

Source

pub fn payload(&self) -> u64

Get the 56-bit payload.

Source§

impl RtObject

Source

pub fn tag(&self) -> u8

Get the tag byte.

Source

pub fn is_inline(&self) -> bool

Check if this is an inline (non-heap) value.

Source

pub fn is_nat(&self) -> bool

Check if this is a natural number (small or big).

Source

pub fn is_bool(&self) -> bool

Check if this is a boolean.

Source

pub fn is_unit(&self) -> bool

Check if this is the unit value.

Source

pub fn is_char(&self) -> bool

Check if this is a character.

Source

pub fn is_small_ctor(&self) -> bool

Check if this is a small constructor.

Source

pub fn is_closure(&self) -> bool

Check if this is a closure reference.

Source

pub fn is_string_ref(&self) -> bool

Check if this is a string reference.

Source

pub fn is_array_ref(&self) -> bool

Check if this is an array reference.

Source

pub fn is_thunk_ref(&self) -> bool

Check if this is a thunk reference.

Source

pub fn is_io_action(&self) -> bool

Check if this is an IO action reference.

Source

pub fn is_task_ref(&self) -> bool

Check if this is a task reference.

Source

pub fn is_external_ref(&self) -> bool

Check if this is an external object reference.

Source

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

Extract a boolean value.

Source

pub fn as_small_nat(&self) -> Option<u64>

Extract a small natural number.

Source

pub fn as_char(&self) -> Option<char>

Extract a character value.

Source

pub fn as_small_ctor(&self) -> Option<u32>

Extract a small constructor index.

Source

pub fn as_small_int(&self) -> Option<i64>

Extract a small signed integer.

Source

pub fn as_float_bits(&self) -> Option<u64>

Extract float bits.

Source§

impl RtObject

Source

pub fn is_heap(&self) -> bool

Check if this is a heap-allocated object.

Source§

impl RtObject

Source

pub fn raw_bits(&self) -> u64

Get the raw bits.

Source§

impl RtObject

Source

pub fn small_ctor(index: u32) -> Self

Create a small constructor tag.

For inductives with no fields and a small number of constructors, we can encode the constructor index inline.

Source§

impl RtObject

Source

pub fn small_int(n: i64) -> Option<Self>

Create a small signed integer.

Source§

impl RtObject

Source

pub fn small_nat(n: u64) -> Option<Self>

Create a small natural number (inline).

Returns None if the value exceeds 56 bits.

Source

pub fn nat(n: u64) -> Self

Create a natural number, using small representation if possible.

Source§

impl RtObject

Source

pub fn with_heap<R>(&self, f: impl FnOnce(&HeapObject) -> R) -> Option<R>

Access the heap object for this reference (if heap-allocated).

Source

pub fn with_heap_mut<R>( &self, f: impl FnOnce(&mut HeapObject) -> R, ) -> Option<R>

Access the heap object mutably.

Source

pub fn string(s: String) -> Self

Create a string object.

Source

pub fn array(elements: Vec<RtObject>) -> Self

Create an array object.

Source

pub fn constructor(ctor_index: u32, fields: Vec<RtObject>) -> Self

Create a constructor object with fields.

Source

pub fn named_constructor( name: Name, ctor_index: u32, fields: Vec<RtObject>, ) -> Self

Create a named constructor object.

Source

pub fn thunk(closure: RtObject) -> Self

Create a thunk (lazy value).

Source

pub fn io_pure(value: RtObject) -> Self

Create an IO action.

Source

pub fn task(task_id: u64) -> Self

Create a task object.

Source

pub fn external(type_name: String, payload: Vec<u8>) -> Self

Create an external object.

Source

pub fn boxed_float(value: f64) -> Self

Create a boxed float.

Source

pub fn byte_array(bytes: Vec<u8>) -> Self

Create a byte array.

Source§

impl RtObject

Source

pub fn unit() -> Self

Create a unit value.

Trait Implementations§

Source§

impl Clone for RtObject

Source§

fn clone(&self) -> RtObject

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RtObject

Source§

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

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

impl Display for RtObject

Source§

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

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

impl Hash for RtObject

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RtObject

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for RtObject

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.