@@ -104,9 +104,9 @@ private:
|
||||
std::vector<thing_p> m_things;
|
||||
std::vector<executor_p> m_executors;
|
||||
|
||||
std::queue<thing_handle> m_deadThings;
|
||||
std::vector<void*> m_deadThingData;
|
||||
furlang::arena m_thingArena;
|
||||
std::queue<thing_id> m_deadThings;
|
||||
std::vector<void*> m_deadThingData;
|
||||
furlang::arena m_thingArena;
|
||||
};
|
||||
|
||||
} // namespace furvm
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
* @param mod Module.
|
||||
* @param function Function handle.
|
||||
*/
|
||||
void push_frame(const mod_p& mod, function_handle function);
|
||||
void push_frame(const mod_p& mod, function_id function);
|
||||
|
||||
/**
|
||||
* @brief Pops the top frame.
|
||||
|
||||
@@ -35,13 +35,13 @@ public:
|
||||
: m_name(name), m_type(function_t::Native), m_value(native) {}
|
||||
|
||||
template <typename Name, typename ModuleName>
|
||||
function(Name&& name, ModuleName&& moduleName, function_handle function)
|
||||
function(Name&& name, ModuleName&& moduleName, function_id function)
|
||||
: m_name(std::forward<Name>(name)),
|
||||
m_type(function_t::Import),
|
||||
m_value(std::forward<ModuleName>(moduleName), function) {}
|
||||
|
||||
template <typename ModuleName>
|
||||
function(const char* name, ModuleName&& moduleName, function_handle function)
|
||||
function(const char* name, ModuleName&& moduleName, function_id function)
|
||||
: m_name(name), m_type(function_t::Import), m_value(std::forward<ModuleName>(moduleName), function) {}
|
||||
|
||||
~function();
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
*
|
||||
* @return A handle to the module.
|
||||
*/
|
||||
function_handle imported_function() const {
|
||||
function_id imported_function() const {
|
||||
if (m_type != function_t::Import) throw std::runtime_error("function type mismatch");
|
||||
return m_value.imp.function;
|
||||
}
|
||||
@@ -120,8 +120,8 @@ private:
|
||||
std::size_t position = 0;
|
||||
native_function native;
|
||||
struct {
|
||||
std::string moduleName;
|
||||
function_handle function;
|
||||
std::string moduleName;
|
||||
function_id function;
|
||||
} imp;
|
||||
|
||||
value() = default;
|
||||
@@ -133,7 +133,7 @@ private:
|
||||
: native(native) {}
|
||||
|
||||
template <typename Name>
|
||||
value(Name&& moduleName, function_handle function)
|
||||
value(Name&& moduleName, function_id function)
|
||||
: imp({ std::forward<Name>(moduleName), function }) {}
|
||||
|
||||
~value() {}
|
||||
|
||||
@@ -81,7 +81,7 @@ using function_p = std::shared_ptr<function>;
|
||||
/**
|
||||
* @brief Furvm function's index.
|
||||
*/
|
||||
using function_handle = std::uint16_t;
|
||||
using function_id = std::uint16_t;
|
||||
|
||||
// module.hpp
|
||||
|
||||
@@ -128,7 +128,7 @@ using thing_p = std::shared_ptr<thing>;
|
||||
/**
|
||||
* @brief Furvm thing's index.
|
||||
*/
|
||||
using thing_handle = std::uint32_t;
|
||||
using thing_id = std::uint32_t;
|
||||
|
||||
// executor.hpp
|
||||
|
||||
@@ -159,7 +159,7 @@ using executor_p = std::shared_ptr<executor>;
|
||||
/**
|
||||
* @brief Furvm executor's index.
|
||||
*/
|
||||
using executor_handle = std::uint32_t;
|
||||
using executor_id = std::uint32_t;
|
||||
|
||||
// context.hpp
|
||||
|
||||
|
||||
@@ -103,25 +103,13 @@ public:
|
||||
* @param id Id of the function.
|
||||
* @return The function.
|
||||
*/
|
||||
constexpr const function_p& function_at(function_handle id) const { return m_functions.at(id); }
|
||||
|
||||
/**
|
||||
* @brief Returns an id of a function.
|
||||
*
|
||||
* @param function Function to get the id of.
|
||||
* @return The function's id.
|
||||
*/
|
||||
function_handle function_id(const function_p& function) const {
|
||||
if (auto it = std::find(m_functions.begin(), m_functions.end(), function); it != m_functions.end())
|
||||
return it - m_functions.begin();
|
||||
throw std::runtime_error("function not in the module");
|
||||
}
|
||||
constexpr const function_p& function_at(function_id id) const { return m_functions.at(id); }
|
||||
|
||||
template <typename... Args>
|
||||
function_handle emplace_function(Args&&... args) {
|
||||
function_id emplace_function(Args&&... args) {
|
||||
function_p function = std::make_shared<class function>(std::forward<Args>(args)...);
|
||||
m_functionMap.emplace(function->name(), function);
|
||||
function_handle id = m_functions.size();
|
||||
function_id id = m_functions.size();
|
||||
m_functions.emplace_back(std::move(function));
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class thing final {
|
||||
public:
|
||||
using nref_t = std::size_t; /**< Type of reference count. */
|
||||
|
||||
static constexpr thing_handle GENERATION_SIZE = 12; /**< Bit size of generation part in thing_handle. */
|
||||
static constexpr thing_id GENERATION_SIZE = 12; /**< Bit size of generation part in thing_handle. */
|
||||
public:
|
||||
thing(const context_p& context, thing_t type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user