forked from KPGPMC/furlang
feat(furvm): add collect function to context
This commit is contained in:
@@ -93,6 +93,11 @@ public:
|
|||||||
* @return The module count.
|
* @return The module count.
|
||||||
*/
|
*/
|
||||||
constexpr size_t size() const { return m_modules.size(); }
|
constexpr size_t size() const { return m_modules.size(); }
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Removes unreferenced things from the thing list.
|
||||||
|
*/
|
||||||
|
void collect();
|
||||||
private:
|
private:
|
||||||
std::vector<mod_p> m_modules;
|
std::vector<mod_p> m_modules;
|
||||||
std::vector<thing_p> m_things;
|
std::vector<thing_p> m_things;
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
#include "furvm/context.hpp"
|
#include "furvm/context.hpp"
|
||||||
|
|
||||||
|
#include "furvm/thing.hpp" // IWYU pragma: keep
|
||||||
|
|
||||||
namespace furvm {
|
namespace furvm {
|
||||||
|
|
||||||
context::context() {}
|
context::context() {}
|
||||||
|
|
||||||
|
void context::collect() {
|
||||||
|
for (auto& ref : m_things) {
|
||||||
|
if (ref->reference_count() != 0) continue;
|
||||||
|
ref = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace furvm
|
} // namespace furvm
|
||||||
@@ -25,8 +25,12 @@ int main(void) {
|
|||||||
auto executor = furvm::executor::create(context);
|
auto executor = furvm::executor::create(context);
|
||||||
executor->push_frame(mainModule, 0);
|
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) {
|
while ((executor->flags() & furvm::executor_flags::Done) != furvm::executor_flags::Done) {
|
||||||
executor->step();
|
executor->step();
|
||||||
|
if ((++count % FPC) == 0) context->collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user