prepare for ghost type

This commit is contained in:
ValKmjolnir 2023-05-09 00:09:15 +08:00
parent 666fb8b25f
commit a69d05233b
1 changed files with 29 additions and 0 deletions

View File

@ -175,6 +175,35 @@ struct nas_upval {
void clear() {onstk=true;elems.clear();size=0;} void clear() {onstk=true;elems.clear();size=0;}
}; };
struct ghost_info {
string name;
void (*destructor)(void*);
};
struct nas_ghost {
private:
static std::vector<ghost_info> 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 { struct nas_obj {
obj_type type; obj_type type;
void* ptr; void* ptr;