refcount: globals, modules and stdlib own their values

Extend the ownership discipline to the VM's global table and the
non-container value producers:

- cat_vm_set_global_owned: takes ownership of a freshly-created value
  (used for the native-registered globals and the `module` table).
- cat_vm_free releases the saved `module` stack entries and the globals
  table (which cascades: each stored value drops its reference).
- module enter/leave retains the saved `module` while it is off-global.
- stdlib/ffi/file build their tables with owned values and drop the
  transient reference after a store.

Suite stays 130 green.
This commit is contained in:
Minus committed 2026-11-17 22:43:29 +00:00
1 parent ee5861a25c
commit a73600e221
6 files changed
+73 -29

No files matched your search

+6
View File
@@ -88,6 +88,12 @@ int cat_vm_frame_run(CAT_VM_State *vm, CAT_VM_Frame *f, CAT_VALUE_Value **out);
CAT_VALUE_Value *cat_vm_get_global(CAT_VM_State *vm, const char *name);
int cat_vm_set_global(CAT_VM_State *vm, const char *name, CAT_VALUE_Value *v);
/* Like cat_vm_set_global, but the caller hands over its reference: the
* globals table takes ownership and the caller's ref is dropped. Use
* with an inline-created value. */
int cat_vm_set_global_owned(CAT_VM_State *vm, const char *name,
CAT_VALUE_Value *v);
void cat_vm_free(CAT_VM_State *vm);
#endif /* CAT_VM_H */