#[repr(C)]pub enum Value {
Int(i64),
Float(f64),
Bool(bool),
String(SeqString),
Symbol(SeqString),
Variant(Arc<VariantData>),
Map(Box<HashMap<MapKey, Value>>),
Quotation {
wrapper: usize,
impl_: usize,
},
Closure {
fn_ptr: usize,
env: Arc<[Value]>,
},
Channel(Arc<ChannelData>),
WeaveCtx {
yield_chan: Arc<WeaveChannelData>,
resume_chan: Arc<WeaveChannelData>,
},
}Expand description
Value: What the language talks about
This is pure data with no pointers to other values. Values can be pushed on the stack, stored in variants, etc. The key insight: Value is independent of Stack structure.
§Memory Layout
Using #[repr(C)] ensures a predictable C-compatible layout:
- Discriminant (tag) at offset 0
- Payload data follows at a fixed offset
This allows compiled code to write Values directly without FFI calls, enabling inline integer/boolean operations for better performance.
Variants§
Int(i64)
Integer value
Float(f64)
Floating-point value (IEEE 754 double precision)
Bool(bool)
Boolean value
String(SeqString)
String (arena or globally allocated via SeqString)
Symbol(SeqString)
Symbol (identifier for dynamic variant construction) Like Ruby/Clojure symbols - lightweight identifiers used for tags. Note: Currently NOT interned (each symbol allocates). Interning may be added in the future for O(1) equality comparison.
Variant(Arc<VariantData>)
Variant (sum type with tagged fields) Uses Arc for O(1) cloning - essential for recursive data structures
Map(Box<HashMap<MapKey, Value>>)
Map (key-value dictionary with O(1) lookup) Keys must be hashable types (Int, String, Bool)
Quotation
Quotation (stateless function with two entry points for calling convention compatibility)
- wrapper: C-convention entry point for calls from the runtime
- impl_: tailcc entry point for tail calls from compiled code (enables TCO)
Fields
Closure
Closure (quotation with captured environment) Contains function pointer and Arc-shared array of captured values. Arc enables TCO: no cleanup needed after tail call, ref-count handles it.
Fields
Channel(Arc<ChannelData>)
Channel (MPMC sender/receiver pair for CSP-style concurrency) Uses Arc for O(1) cloning - duplicating a channel shares the underlying handles. Send/receive operations use the handles directly with zero mutex overhead.
WeaveCtx
Weave context (generator/coroutine communication channels) Contains both yield and resume channels for bidirectional communication. Travels on the stack - no global registry needed. Uses WeaveChannelData with WeaveMessage for type-safe control flow.