pub struct ModuleBindingRegistry { /* private fields */ }Expand description
Single source of truth for all module binding values.
Used by:
- Interpreter: name-based lookup
- VM: index-based lookup (after compilation resolves names)
- JIT: stable pointers for inlined access
Implementations§
Source§impl ModuleBindingRegistry
impl ModuleBindingRegistry
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with pre-allocated capacity
Sourcepub fn register(
&mut self,
name: &str,
value: KindedSlot,
is_const: bool,
) -> Result<u32>
pub fn register( &mut self, name: &str, value: KindedSlot, is_const: bool, ) -> Result<u32>
Register or update a module binding, returns its stable index.
If the module binding already exists:
- If it’s const and we’re re-registering with same constness, update value
- If it’s const and we’re trying to make it mutable, error
- If it’s mutable, always update
§Arguments
name- The module binding’s namevalue- The value to store as aKindedSlot(slot + NativeKind)is_const- Whether this module binding is constant (functions, imports)
§Returns
The stable index for this module binding
Sourcepub fn register_nb(
&mut self,
name: &str,
value: KindedSlot,
is_const: bool,
) -> Result<u32>
pub fn register_nb( &mut self, name: &str, value: KindedSlot, is_const: bool, ) -> Result<u32>
Register or update a module binding with a KindedSlot value, returns its stable index.
Sourcepub fn register_const(&mut self, name: &str, value: KindedSlot) -> Result<u32>
pub fn register_const(&mut self, name: &str, value: KindedSlot) -> Result<u32>
Register a constant module binding (convenience method)
Sourcepub fn register_mut(&mut self, name: &str, value: KindedSlot) -> Result<u32>
pub fn register_mut(&mut self, name: &str, value: KindedSlot) -> Result<u32>
Register a mutable module binding (convenience method)
Sourcepub fn get_by_name(&self, name: &str) -> Option<KindedSlot>
pub fn get_by_name(&self, name: &str) -> Option<KindedSlot>
Get by name as owned KindedSlot (interpreter, dynamic lookup).
Clone on KindedSlot retains the underlying refcount.
Sourcepub fn get_by_index(&self, idx: u32) -> Option<&KindedSlot>
pub fn get_by_index(&self, idx: u32) -> Option<&KindedSlot>
Get by index as KindedSlot reference (O(1))
Sourcepub fn set_by_index(&mut self, idx: u32, value: KindedSlot) -> Result<()>
pub fn set_by_index(&mut self, idx: u32, value: KindedSlot) -> Result<()>
Set by index from KindedSlot (for VM assignment).
The previous value is dropped via its Drop impl, retiring its
refcount cleanly.
Sourcepub fn is_const_by_index(&self, idx: u32) -> Option<bool>
pub fn is_const_by_index(&self, idx: u32) -> Option<bool>
Check if a module binding at index is const
Sourcepub fn names(&self) -> impl Iterator<Item = &str>
pub fn names(&self) -> impl Iterator<Item = &str>
Get all module binding names (for debugging/introspection)
Sourcepub fn get_ptr(&self, idx: u32) -> Option<*const KindedSlot>
pub fn get_ptr(&self, idx: u32) -> Option<*const KindedSlot>
Get stable pointer for JIT (address won’t change after registration)
§Safety
The pointer is valid as long as no new module bindings are registered. For JIT, call this after all module bindings are registered.
Sourcepub fn snapshot_constants(&self) -> Vec<(u32, KindedSlot)>
pub fn snapshot_constants(&self) -> Vec<(u32, KindedSlot)>
Snapshot constant module bindings for JIT constant folding.
Cloning each KindedSlot bumps its refcount via the explicit
Clone impl — no aliasing copies.