Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Int(i64),
    Number(f64),
    Str(BopStr),
    Bool(bool),
    None,
    Array(BopArray),
    Dict(BopDict),
    Fn(Rc<BopFn>),
    Struct(Box<BopStruct>),
    EnumVariant(Box<BopEnumVariant>),
    Module(Rc<BopModule>),
    Iter(Rc<RefCell<BopIter>>),
}

Variants§

§

Int(i64)

64-bit signed integer. The go-to type for counts, indices, and any arithmetic that wants exactness. Added in phase 6; produced by integer literals (42), the int() builtin, len, range elements, and the new // integer-division operator.

§

Number(f64)

64-bit IEEE-754 float. Produced by decimal literals (3.14, 4.0), the float() builtin, and by / on any numeric pair (Python-style: / always floats).

§

Str(BopStr)

§

Bool(bool)

§

None

§

Array(BopArray)

§

Dict(BopDict)

§

Fn(Rc<BopFn>)

§

Struct(Box<BopStruct>)

§

EnumVariant(Box<BopEnumVariant>)

§

Module(Rc<BopModule>)

Namespace value produced by an aliased use statement (use std.math as m binds m as a Module). Field access dispatches to the module’s exported let / fn bindings; the runtime also consults the type list for m.Type { ... } / m.Type::Variant(...) forms so those namespaced constructors find the right declared type.

§

Iter(Rc<RefCell<BopIter>>)

Lazy iterator. Cloning shares state (like Value::Fn) — let b = a; a.next(); b.next() advances the same underlying position, matching iterator semantics in Python / Rust / JS. See BopIter for the built-in variants; user-defined iterators are ordinary struct values that happen to implement .next().

Implementations§

Source§

impl Value

Source

pub fn new_str(s: String) -> Self

Source

pub fn new_array(items: Vec<Value>) -> Self

Source

pub fn new_dict(entries: Vec<(String, Value)>) -> Self

Source

pub fn new_struct( module_path: String, type_name: String, fields: Vec<(String, Value)>, ) -> Self

Build a user-defined struct value. module_path is the module in which the type was declared (<root> at the top level, <builtin> for engine-registered shapes like RuntimeError, or the dot-joined use path for user modules). Two structs are only the same type when both the module path and the type name match — so a struct Color { ... } declared in two separate modules produces genuinely distinct values.

Source

pub fn new_array_iter(items: Vec<Value>) -> Self

Build a built-in iterator that yields each item of items in order. Cloning the returned Value::Iter shares the iteration cursor, so let b = a; a.next() advances b too.

Source

pub fn new_string_iter(chars: Vec<char>) -> Self

Build a built-in iterator over a string’s Unicode code points.

Source

pub fn new_dict_iter(keys: Vec<String>) -> Self

Build a built-in iterator over a dict’s keys (declaration order).

Source

pub fn new_enum_unit( module_path: String, type_name: String, variant: String, ) -> Self

Source

pub fn new_enum_tuple( module_path: String, type_name: String, variant: String, items: Vec<Value>, ) -> Self

Source

pub fn new_enum_struct( module_path: String, type_name: String, variant: String, fields: Vec<(String, Value)>, ) -> Self

Source

pub fn new_fn( params: Vec<String>, captures: Vec<(String, Value)>, body: Vec<Stmt>, self_name: Option<String>, ) -> Self

Build a tree-walker-ready closure value. The AST body moves into a shared BopFn behind an Rc; subsequent clones of the resulting Value::Fn just bump the refcount.

Source

pub fn new_compiled_fn( params: Vec<String>, captures: Vec<(String, Value)>, body: Rc<dyn Any + 'static>, self_name: Option<String>, ) -> Self

Build a closure value with an engine-opaque compiled body. Used by the bytecode VM (and any future engine) to carry its pre-compiled form inside a Value::Fn without bop-lang depending on the engine crate.

Source§

impl Value

Source

pub fn inspect(&self) -> String

Source

pub fn type_name(&self) -> &'static str

Source

pub fn display_type_name(&self) -> String

The user-facing name for this value’s type. For struct values it’s the declared type ("Point"); for enum variants it’s the enum’s type name; for built-in variants it matches Self::type_name.

Source

pub fn is_truthy(&self) -> bool

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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 Value

Source§

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

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

impl Display for Value

Source§

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

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

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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.