xo-gc stack: + gc-location-of() primitive

This commit is contained in:
Roland Conybeare 2026-03-29 19:47:15 -04:00
commit 97723415b1
3 changed files with 36 additions and 1 deletions

View file

@ -27,6 +27,10 @@ namespace xo {
static DPrimitive_gco_0 * make_report_gc_object_types_pm(obj<AAllocator> mm,
StringTable * stbl);
/** create primitive: report gc location of a value **/
static DPrimitive_gco_1_gco * make_gc_location_of_pm(obj<AAllocator> mm,
StringTable * stbl);
/** create primitive: request collection **/
static DPrimitive_gco_1_gco * make_request_gc_pm(obj<AAllocator> mm,
StringTable * stbl);

View file

@ -58,7 +58,6 @@ namespace xo {
obj<AGCObject> stats;
bool ok = rcx.collector().report_object_types(rcx.allocator(), rcx.error_allocator(), &stats);
if (ok && stats)
return stats;
}
@ -79,6 +78,33 @@ namespace xo {
}
// ----- gc-location-of -----
obj<AGCObject>
xfer_gc_location_of(obj<ARuntimeContext> rcx, obj<AGCObject> gco)
{
std::int32_t location_code = 0;
if (rcx.collector()) {
location_code = rcx.collector().locate_address(gco.data());
}
return DInteger::box(rcx.allocator(), location_code);
}
DPrimitive_gco_1_gco *
GcPrimitives::make_gc_location_of_pm(obj<AAllocator> mm,
StringTable * stbl)
{
(void)stbl;
auto int_ty = DAtomicType::make(mm, Metatype::t_integer());
auto any_ty = DAtomicType::make(mm, Metatype::t_any());
auto pm_ty = obj<AType,DFunctionType>(DFunctionType::_make(mm, int_ty, any_ty));
return DPrimitive_gco_1_gco::_make(mm, "gc-location-of", pm_ty, &xfer_gc_location_of);
}
// ----- request-gc -----
obj<AGCObject>

View file

@ -142,6 +142,11 @@ namespace xo {
GcPrimitives::make_report_gc_object_types_pm(mm, stbl),
flags & InstallFlags::f_generalpurpose));
ok = ok & (PrimitiveRegistry::install_aux
(sink,
GcPrimitives::make_gc_location_of_pm(mm, stbl),
flags & InstallFlags::f_generalpurpose));
ok = ok & (PrimitiveRegistry::install_aux
(sink,
GcPrimitives::make_request_gc_pm(mm, stbl),