From a69d05233b3c4f0b8668be2e385c2ef3ec351dcb Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Tue, 9 May 2023 00:09:15 +0800 Subject: [PATCH] :sparkles: prepare for ghost type --- nasal_gc.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/nasal_gc.h b/nasal_gc.h index 36bcde0..0374e6b 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -175,6 +175,35 @@ struct nas_upval { void clear() {onstk=true;elems.clear();size=0;} }; +struct ghost_info { + string name; + void (*destructor)(void*); +}; + +struct nas_ghost { +private: + static std::vector ghost_register_table; + usize type; + void* ptr; + +public: + nas_ghost(): type(0), ptr(nullptr) {} + ~nas_ghost() { + if (!ptr) { return; } + ghost_register_table[type].destructor(ptr); + } + + static usize regist_ghost_type(ghost_info i) { + auto res=ghost_register_table.size(); + ghost_register_table.push_back(i); + return res; + } + + const std::string& name() { + return ghost_register_table[type].name; + } +}; + struct nas_obj { obj_type type; void* ptr;