refactor(furvm): cleanup some bugs
Or we could just pretend that there were no bugs clueless
This commit is contained in:
@@ -68,11 +68,21 @@ public:
|
|||||||
const std::vector<executor>& executors() const { return m_executors; }
|
const std::vector<executor>& executors() const { return m_executors; }
|
||||||
public:
|
public:
|
||||||
thing_type_store& tt_store() { return m_thingTypeStore; }
|
thing_type_store& tt_store() { return m_thingTypeStore; }
|
||||||
|
public:
|
||||||
|
template <typename... Args>
|
||||||
|
thing<> allocate_thing(Args&&... args) {
|
||||||
|
thing<> thing = { std::forward<Args>(args)... };
|
||||||
|
m_heap.push_back(thing.raw());
|
||||||
|
return std::move(thing);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
handle_container<mod_h> m_modules;
|
handle_container<mod_h> m_modules;
|
||||||
std::vector<executor> m_executors;
|
std::vector<executor> m_executors;
|
||||||
|
|
||||||
class thing_type_store m_thingTypeStore;
|
class thing_type_store m_thingTypeStore;
|
||||||
|
|
||||||
|
// A list of things on the heap
|
||||||
|
std::vector<std::byte*> m_heap;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace furvm
|
} // namespace furvm
|
||||||
|
|||||||
@@ -242,29 +242,19 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Destructs a thing.
|
* @brief Destructs a thing.
|
||||||
*/
|
*/
|
||||||
~thing() {
|
~thing() { free(); }
|
||||||
if (!m_reference && m_data != nullptr) m_allocator.deallocate(m_data - sizeof(header), m_size + sizeof(header));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move constructor.
|
* @brief Move constructor.
|
||||||
*/
|
*/
|
||||||
thing(thing&& other) noexcept
|
thing(thing&& other) noexcept { *this = std::move(other); }
|
||||||
: m_reference(other.m_reference),
|
|
||||||
m_type(other.m_type),
|
|
||||||
m_data(other.m_data),
|
|
||||||
m_size(other.m_size),
|
|
||||||
m_allocator(std::move(other.m_allocator)) {
|
|
||||||
other.m_type = nullptr;
|
|
||||||
other.m_data = nullptr;
|
|
||||||
other.m_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move constructor.
|
* @brief Move constructor.
|
||||||
*/
|
*/
|
||||||
thing& operator=(thing&& other) noexcept {
|
thing& operator=(thing&& other) noexcept {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
|
free();
|
||||||
m_reference = other.m_reference;
|
m_reference = other.m_reference;
|
||||||
m_type = other.m_type;
|
m_type = other.m_type;
|
||||||
m_size = other.m_size;
|
m_size = other.m_size;
|
||||||
@@ -276,16 +266,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
thing(const thing& other)
|
thing(const thing& other) { *this = other; }
|
||||||
: m_reference(other.m_reference), m_size(other.m_size), m_allocator(other.m_allocator) {
|
|
||||||
if (m_reference) {
|
|
||||||
m_type = other.m_type;
|
|
||||||
m_data = other.m_data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
allocate(other.type());
|
|
||||||
other.copy(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
thing& operator=(const thing& other) {
|
thing& operator=(const thing& other) {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
@@ -299,6 +280,7 @@ public:
|
|||||||
m_data = other.m_data;
|
m_data = other.m_data;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
free();
|
||||||
allocate(other.type());
|
allocate(other.type());
|
||||||
other.copy(*this);
|
other.copy(*this);
|
||||||
|
|
||||||
@@ -313,6 +295,7 @@ public:
|
|||||||
thing clone() const {
|
thing clone() const {
|
||||||
thing res(m_type, m_allocator);
|
thing res(m_type, m_allocator);
|
||||||
copy(res);
|
copy(res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void copy(thing<>& dst) const {
|
void copy(thing<>& dst) const {
|
||||||
@@ -348,7 +331,12 @@ public:
|
|||||||
* @param type Type to compare.
|
* @param type Type to compare.
|
||||||
* @return true if the types match.
|
* @return true if the types match.
|
||||||
*/
|
*/
|
||||||
constexpr bool is(enum thing_type::type type) const { return m_type->type == type; }
|
constexpr bool is(enum thing_type::type type) const {
|
||||||
|
if (type == thing_type::Ref) return m_reference;
|
||||||
|
return m_type->type == type;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool is_reference() const { return m_reference; }
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Returns a raw data pointer.
|
* @brief Returns a raw data pointer.
|
||||||
@@ -779,6 +767,12 @@ private:
|
|||||||
m_data += sizeof(header);
|
m_data += sizeof(header);
|
||||||
std::memset(m_data, 0, m_size);
|
std::memset(m_data, 0, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free() {
|
||||||
|
if (!m_reference && m_data != nullptr) m_allocator.deallocate(m_data - sizeof(header), m_size + sizeof(header));
|
||||||
|
m_data = nullptr;
|
||||||
|
m_type = nullptr;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
// A flag indicating whether the thing instance owns the data, or not.
|
// A flag indicating whether the thing instance owns the data, or not.
|
||||||
bool m_reference = false;
|
bool m_reference = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user