Value

Enum Value 

Source
pub enum Value {
Show 16 variants Nil, Bool(bool), Integer(i64), Real(f64), Char(char), String(Gc<String>), Symbol(Rc<str>), Keyword(Rc<str>), Pair(Gc<GcCell<PairData>>), Vector(Gc<GcCell<Vec<Value>>>), Procedure(Gc<Procedure>), Node(Rc<Box<dyn Node>>), NodeList(Rc<Box<dyn NodeList>>), Sosofo, Unspecified, Error,
}
Expand description

A Scheme value

Corresponds to OpenJade’s ELObj base class.

Memory management: Uses Gc<T> for heap-allocated values. The gc crate provides conservative garbage collection similar to OpenJade’s Collector.

Note: We manually implement Trace/Finalize because Node and NodeList variants use Rc (not Gc) and contain trait objects.

Variants§

§

Nil

The empty list ()

OpenJade: NilObj

§

Bool(bool)

Boolean: #t or #f

OpenJade: TrueObj / FalseObj

§

Integer(i64)

Exact integer

OpenJade: IntegerObj (long n_)

§

Real(f64)

Inexact real number

OpenJade: RealObj (double n_)

§

Char(char)

Unicode character

OpenJade: CharObj (Char ch_)

§

String(Gc<String>)

Immutable string

OpenJade: StringObj (extends StringC)

Using Gc<String> for garbage collection.

§

Symbol(Rc<str>)

Interned symbol

OpenJade: SymbolObj (StringObj* name_)

Symbols are interned (shared) for efficiency. Using Rc<str> since symbols are immutable and shared.

§

Keyword(Rc<str>)

Keyword (DSSSL extension)

OpenJade: KeywordObj

Keywords are like symbols but in a separate namespace.

§

Pair(Gc<GcCell<PairData>>)

Cons cell (pair)

OpenJade: PairObj (ELObj* car_, ELObj* cdr_)

Using Gc<PairData> for garbage-collected pairs. GcCell allows mutation (for set-car!/set-cdr!).

§

Vector(Gc<GcCell<Vec<Value>>>)

Vector (array)

OpenJade: VectorObj (Vector<ELObj*>)

Using Gc<GcCell<Vec<Value>>> for mutable vectors.

§

Procedure(Gc<Procedure>)

Procedure (function)

OpenJade: FunctionObj (various subclasses)

Can be:

  • Built-in primitive (Rust function)
  • User-defined lambda (compiled bytecode or AST)
§

Node(Rc<Box<dyn Node>>)

A node in the document grove

Represents a node from the XML document tree. Corresponds to OpenJade’s node objects in the grove.

Phase 3: Now fully implemented with libxml2 grove.

Uses Rc<Box<dyn Node>> instead of Gc because:

  • Nodes are owned by the grove, not the Scheme GC
  • Grove lifetime is managed separately
  • Trait objects can’t derive Trace automatically

NOTE: Managed by Rc, not GC - see manual Trace impl below

§

NodeList(Rc<Box<dyn NodeList>>)

Node list (grove query result)

Represents a collection of nodes from grove queries. Corresponds to DSSSL node-list objects.

Phase 3: Now fully implemented with libxml2 grove.

Uses Rc<Box<dyn NodeList>> for same reasons as Node.

NOTE: Managed by Rc, not GC - see manual Trace impl below

§

Sosofo

Sosofo (flow object sequence)

Placeholder - will be properly implemented in Phase 4.

§

Unspecified

Unspecified value

Returned by expressions with unspecified results (like set!).

OpenJade: UnspecifiedObj

§

Error

Error marker

Used internally for error propagation.

OpenJade: ErrorObj

Implementations§

Source§

impl Value

Source

pub fn bool(b: bool) -> Self

Create a boolean value

Source

pub fn integer(n: i64) -> Self

Create an integer value

Source

pub fn real(n: f64) -> Self

Create a real value

Source

pub fn char(ch: char) -> Self

Create a character value

Source

pub fn string(s: String) -> Self

Create a string value

Source

pub fn symbol(s: &str) -> Self

Create a symbol value

Source

pub fn keyword(s: &str) -> Self

Create a keyword value

Source

pub fn cons(car: Value, cdr: Value) -> Self

Create a cons cell (pair)

Source

pub fn cons_with_pos(car: Value, cdr: Value, pos: Position) -> Self

Create a cons cell with source position

Source

pub fn vector(elements: Vec<Value>) -> Self

Create a vector

Source

pub fn primitive( name: &'static str, func: fn(&[Value]) -> Result<Value, String>, ) -> Self

Create a built-in primitive procedure

Source

pub fn lambda(params: Vec<String>, body: Value, env: Gc<Environment>) -> Self

Create a user-defined lambda procedure

Source

pub fn lambda_with_source( params: Vec<String>, body: Value, env: Gc<Environment>, source: Option<SourceInfo>, name: Option<String>, ) -> Self

Create a user-defined lambda procedure with source location

Source

pub fn node(node: Box<dyn Node>) -> Self

Create a node value

Source

pub fn node_list(node_list: Box<dyn NodeList>) -> Self

Create a node list value

Source§

impl Value

Source

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

Scheme equal? - Deep structural equality

Corresponds to OpenJade’s ELObj::equal()

Recursively compares:

  • Lists and vectors: Element-wise comparison
  • Strings: Content comparison
  • Numbers: Numeric equality
  • Everything else: Same as eqv?
Source

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

Scheme eqv? - Equivalence (same value, not necessarily same object)

Corresponds to OpenJade’s ELObj::eqv()

Returns true if:

  • Both are the same boolean value
  • Both are the same number (integer or real)
  • Both are the same character
  • Both are the same symbol (symbols are interned)
  • Both are the same keyword
  • Both refer to the same pair/vector/procedure object
  • Both are nil
Source

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

Scheme eq? - Object identity (same object in memory)

For most types, same as eqv?. Symbols and keywords are interned, so eq? and eqv? are equivalent for them.

Source§

impl Value

Source

pub fn is_nil(&self) -> bool

Is this the nil value?

Source

pub fn is_bool(&self) -> bool

Is this a boolean?

Source

pub fn is_true(&self) -> bool

Is this true? (for conditionals)

In Scheme, only #f is false; everything else (including nil) is true.

Source

pub fn is_integer(&self) -> bool

Is this an integer?

Source

pub fn is_real(&self) -> bool

Is this a real number?

Source

pub fn is_number(&self) -> bool

Is this a number (integer or real)?

Source

pub fn is_char(&self) -> bool

Is this a character?

Source

pub fn is_string(&self) -> bool

Is this a string?

Source

pub fn is_symbol(&self) -> bool

Is this a symbol?

Source

pub fn is_pair(&self) -> bool

Is this a pair?

Source

pub fn is_list(&self) -> bool

Is this a list? (nil or pair)

Source

pub fn is_vector(&self) -> bool

Is this a vector?

Source

pub fn is_procedure(&self) -> bool

Is this a procedure?

Source

pub fn is_node(&self) -> bool

Is this a node?

Source

pub fn is_node_list(&self) -> bool

Is this a node list?

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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

Manual implementation of Finalize for Value

No finalization needed - all cleanup is handled by Drop impls

Source§

impl Trace for Value

Manual implementation of Trace for Value

We implement this manually because:

  • Node and NodeList use Rc<Box>, which doesn’t implement Trace
  • These are managed by Rc, not the GC
  • All other variants use Gc and need proper tracing
Source§

unsafe fn trace(&self)

Marks all contained Gcs.
Source§

unsafe fn root(&self)

Increments the root-count of all contained Gcs.
Source§

unsafe fn unroot(&self)

Decrements the root-count of all contained Gcs.
Source§

fn finalize_glue(&self)

Runs Finalize::finalize() on this object and all contained subobjects

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl !RefUnwindSafe for Value

§

impl !Send for Value

§

impl !Sync for Value

§

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