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
impl Value
pub fn new_str(s: String) -> Self
pub fn new_array(items: Vec<Value>) -> Self
pub fn new_dict(entries: Vec<(String, Value)>) -> Self
Sourcepub fn new_struct(
module_path: String,
type_name: String,
fields: Vec<(String, Value)>,
) -> Self
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.
Sourcepub fn new_array_iter(items: Vec<Value>) -> Self
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.
Sourcepub fn new_string_iter(chars: Vec<char>) -> Self
pub fn new_string_iter(chars: Vec<char>) -> Self
Build a built-in iterator over a string’s Unicode code points.
Sourcepub fn new_dict_iter(keys: Vec<String>) -> Self
pub fn new_dict_iter(keys: Vec<String>) -> Self
Build a built-in iterator over a dict’s keys (declaration order).
pub fn new_enum_unit( module_path: String, type_name: String, variant: String, ) -> Self
pub fn new_enum_tuple( module_path: String, type_name: String, variant: String, items: Vec<Value>, ) -> Self
pub fn new_enum_struct( module_path: String, type_name: String, variant: String, fields: Vec<(String, Value)>, ) -> Self
Sourcepub fn new_fn(
params: Vec<String>,
captures: Vec<(String, Value)>,
body: Vec<Stmt>,
self_name: Option<String>,
) -> Self
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.
Sourcepub fn new_compiled_fn(
params: Vec<String>,
captures: Vec<(String, Value)>,
body: Rc<dyn Any + 'static>,
self_name: Option<String>,
) -> Self
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
impl Value
pub fn inspect(&self) -> String
pub fn type_name(&self) -> &'static str
Sourcepub fn display_type_name(&self) -> String
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.