Add typed heap allocation and reads to Value
Summary
Extract two helpers from #1024 so the caller cleanup can land on its own. Both work with the existing Value::Ref(HeapId) representation.
Value::allocate(payload, heap)wraps the new allocation's initial reference in aValue. Callers pass the payload directly, for exampleValue::allocate(range, vm.heap).value.read_as::<T>(heap)returns a typed reader for a matching heap payload. Immediate values returnNonebefore accessing the heap. For references,HeapReader::read_aschecks the payload type.
The migrations cover allocations that produce a Value and reads that select one payload type. Callers that dispatch on several heap variants can still match on read_heap.
Tests
Added a unit test that allocates bytes, reads them back, and checks both a mismatched heap type and an immediate value. Ran the Monty test suite and interpreter fixtures with memory-model-checks, Clippy with all Monty features, and a wasm32-wasip1 build check.
Summary by cubic
Adds Value::allocate and Value::read_as to centralize heap allocations and typed reads, then migrates all call sites across Monty to these helpers. Also adds tests covering the helpers at previously untested call sites.
Value::allocate(payload, heap)wraps a new allocation's initial reference in aValue.value.read_as::<T>(heap)returns a typed reader; immediate values returnNone, and references check the payload type.- No behavior changes. Call sites that dispatch on multiple heap variants still match on
read_heap. - New tests cover datetime deserialization, binary file buffer reads, set/frozenset inputs, and closure equality.