@@ -154,6 +154,10 @@ struct type;
|
|||||||
|
|
||||||
using type_p = std::shared_ptr<type>;
|
using type_p = std::shared_ptr<type>;
|
||||||
|
|
||||||
|
using type_id = std::uint32_t;
|
||||||
|
|
||||||
|
using type_h = handle<type_p, generic_header<type_id>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class bad_thing_access
|
* @class bad_thing_access
|
||||||
* @brief Bad thing access exception.
|
* @brief Bad thing access exception.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "furvm/function.hpp"
|
#include "furvm/function.hpp"
|
||||||
#include "furvm/fwd.hpp"
|
#include "furvm/fwd.hpp"
|
||||||
#include "furvm/handle.hpp"
|
#include "furvm/handle.hpp"
|
||||||
|
#include "furvm/type.hpp" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@@ -187,6 +188,49 @@ public:
|
|||||||
native_function get_native_function(NameFwd&& name) const {
|
native_function get_native_function(NameFwd&& name) const {
|
||||||
return m_nativeFunctions.at(std::forward<NameFwd>(name));
|
return m_nativeFunctions.at(std::forward<NameFwd>(name));
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Emplaces a type in the context.
|
||||||
|
*
|
||||||
|
* @param args Arguments forwarded to the type constructor.
|
||||||
|
* @return The emplaced type.
|
||||||
|
*/
|
||||||
|
template <typename... Args>
|
||||||
|
auto emplace_type(Args&&... args) {
|
||||||
|
return m_types.emplace_back(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a type from the context.
|
||||||
|
*
|
||||||
|
* @param args type's id.
|
||||||
|
* @return A handle to the type.
|
||||||
|
*/
|
||||||
|
template <typename... Args>
|
||||||
|
auto type_at(Args&&... args) {
|
||||||
|
return m_types.at(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns a type from the context.
|
||||||
|
*
|
||||||
|
* @param args type's id.
|
||||||
|
* @return A handle to the type.
|
||||||
|
*/
|
||||||
|
template <typename... Args>
|
||||||
|
auto type_at(Args&&... args) const {
|
||||||
|
return m_types.at(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Erases a type from the context.
|
||||||
|
*
|
||||||
|
* @param args type's id.
|
||||||
|
*/
|
||||||
|
template <typename... Args>
|
||||||
|
void erase_type(Args&&... args) {
|
||||||
|
m_types.erase(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Prints the module in a bytecode form to an output stream.
|
* @brief Prints the module in a bytecode form to an output stream.
|
||||||
@@ -202,6 +246,8 @@ private:
|
|||||||
std::unordered_map<std::string, function_id> m_publicFunctions;
|
std::unordered_map<std::string, function_id> m_publicFunctions;
|
||||||
handle_container<function_h> m_functions;
|
handle_container<function_h> m_functions;
|
||||||
|
|
||||||
|
handle_container<type_h> m_types;
|
||||||
|
|
||||||
std::unordered_map<std::string, native_function> m_nativeFunctions;
|
std::unordered_map<std::string, native_function> m_nativeFunctions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user