xo-interpreter: + toplevel env in VSM

This commit is contained in:
Roland Conybeare 2025-11-23 21:41:14 -05:00
commit 56a1c3bc75
11 changed files with 218 additions and 18 deletions

View file

@ -7,6 +7,7 @@
#include "ArenaAlloc.hpp"
#include "GcStatistics.hpp"
#include "Object.hpp"
#include "xo/callback/UpCallbackSet.hpp"
#include "xo/indentlog/print/array.hpp"
#include <vector>
@ -154,6 +155,9 @@ namespace xo {
**/
static up<GC> make(const Config & config);
/** runtime downcast **/
static GC * from(IAlloc * mm);
const Config & config() const { return config_; }
std::uint8_t nursery_polarity() const { return nursery_polarity_; }
std::uint8_t tenured_polarity() const { return tenured_polarity_; }
@ -230,6 +234,15 @@ namespace xo {
* from @c *addr
**/
void add_gc_root(Object ** addr);
/** reverse the effect of previous call to @ref add_gc_root **/
void remove_gc_root(Object ** addr);
/** convenience wrapper **/
template <typename T>
void add_gc_root_dwim(gp<T> * p) { this->add_gc_root(reinterpret_cast<Object**>(p->ptr_address())); }
template <typename T>
void remove_gc_root_dwim(gp<T> * p) { this->remove_gc_root(reinterpret_cast<Object**>(p->ptr_address())); }
/** may optionally use this to observe GC copy phase.
* Will be invoked once _per surviving object_, so not cheap.
* Intended for GC visualization.

View file

@ -132,11 +132,15 @@ namespace xo {
up<GC>
GC::make(const Config & config)
{
//GC * gc = new GC(config);
return std::make_unique<GC>(config);
}
GC *
GC::from(IAlloc * mm)
{
return dynamic_cast<GC *>(mm);
}
const std::string &
GC::name() const
{
@ -390,6 +394,19 @@ namespace xo {
gc_root_v_.push_back(addr);
}
void
GC::remove_gc_root(Object ** addr)
{
/* Multithreaded GC not supported */
assert(!this->gc_in_progress());
auto new_end_ix = std::remove(gc_root_v_.begin(), gc_root_v_.end(), addr);
/* erase now-unused slots */
gc_root_v_.erase(new_end_ix, gc_root_v_.end());
}
auto
GC::add_gc_copy_callback(up<GcCopyCallback> fn) -> CallbackId
{