feat(furvm): add collect function to context

This commit is contained in:
2026-06-10 20:35:05 +02:00
parent 4d935ef75f
commit 9021ae0089
3 changed files with 18 additions and 0 deletions
+9
View File
@@ -1,7 +1,16 @@
#include "furvm/context.hpp"
#include "furvm/thing.hpp" // IWYU pragma: keep
namespace furvm {
context::context() {}
void context::collect() {
for (auto& ref : m_things) {
if (ref->reference_count() != 0) continue;
ref = nullptr;
}
}
} // namespace furvm
+4
View File
@@ -25,8 +25,12 @@ int main(void) {
auto executor = furvm::executor::create(context);
executor->push_frame(mainModule, 0);
static constexpr std::size_t FPC = 3; // Frames per collection
std::size_t count = 0;
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) {
executor->step();
if ((++count % FPC) == 0) context->collect();
}
return 0;