module scheme import arena struct GoopsWeakValue { value Value lifetime ?arena.LifetimeToken } fn goops_weak(value Value) GoopsWeakValue { return GoopsWeakValue{ value: value, lifetime: arena.lifetime_token(value.pointer()) } } // Resolve once and retain the returned Value throughout its use. Arena reset // and free still require the host's synchronization; a lifetime token is not a pin. @[inline] fn (reference &GoopsWeakValue) get() ?Value { if lifetime := reference.lifetime { if !lifetime.matches(reference.value.pointer()) { return none } } return reference.value } @[inline] fn (mut vm VM) goops_note_weak_reference(_reference &GoopsWeakValue) { if v_arena_current() != vm.allocation_owner { vm.goops.temporary_references++ if vm.goops.temporary_references >= 256 { vm.goops_prune_references() } } }