Skip to main content

marshal_value

Function marshal_value 

Source
pub fn marshal_value(
    v: &Value,
    registers: &RegisterFile,
    recursion_stack: &mut RegisterFile,
    objs: &mut ObjectPool,
    maps: &mut MapPool,
    strings: &mut StringPool,
    gc: &mut GcState,
) -> Data
Expand description

Allocates v into candela’s heap pools and returns the value to store.

Scalars become NaN-boxed values directly. A list or map takes its slot the way one the program builds does, reusing a freed slot when there is one, so building it can start or carry on a collection. Everything built so far therefore stays reachable from the roots a collection reads, registers and recursion_stack: the outermost container sits on top of recursion_stack while it is filled, and each entry goes into its parent before anything inside it is allocated. The caller keeps every other value the program still holds reachable from the roots too, and stores the result before it allocates again.

A string is interned: one the pool already holds by its text is shared, since a map finds a string key by its slot.