@@ -13,7 +13,7 @@
|
||||
|
||||
namespace furvm {
|
||||
|
||||
class context {
|
||||
class context : public handle_container<mod_h> {
|
||||
public:
|
||||
friend class executor;
|
||||
public:
|
||||
@@ -36,49 +36,6 @@ public:
|
||||
|
||||
context(const context&) = delete;
|
||||
context& operator=(const context&) = delete;
|
||||
public:
|
||||
/**
|
||||
* @brief Emplaces a module in the context.
|
||||
*
|
||||
* @param args Arguments forwarded to the module constructor.
|
||||
* @return The emplaced module.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto emplace_module(Args&&... args) {
|
||||
return m_modules.emplace(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a module from the context.
|
||||
*
|
||||
* @param args Module's id.
|
||||
* @return A handle to the module.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto module_at(Args&&... args) {
|
||||
return m_modules.at(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a module from the context.
|
||||
*
|
||||
* @param args Module's id.
|
||||
* @return A handle to the module.
|
||||
*/
|
||||
template <typename... Args>
|
||||
auto module_at(Args&&... args) const {
|
||||
return m_modules.at(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erases a module from the context.
|
||||
*
|
||||
* @param args Module's id.
|
||||
*/
|
||||
template <typename... Args>
|
||||
void erase_module(Args&&... args) {
|
||||
m_modules.erase(std::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Emplaces an executor in the context.
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace furvm {
|
||||
void executor::push_frame(const mod_h& mod, function function) {
|
||||
mod_h modInst = mod;
|
||||
while (function.type() == function_t::Import) {
|
||||
modInst = m_context->module_at(function.imp().mod);
|
||||
modInst = m_context->at(function.imp().mod);
|
||||
function = *modInst->function_at(function.imp().function);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -23,12 +23,12 @@ static constexpr std::array<furvm::byte, 9> s_bytecode = {
|
||||
int main(void) {
|
||||
auto context = std::make_shared<furvm::context>();
|
||||
|
||||
furvm::mod_h furlangModule = context->emplace_module("furlang");
|
||||
furvm::mod_h furlangModule = context->emplace("furlang");
|
||||
furvm::function_h printFunc = furlangModule->emplace_function("print", 1, "print");
|
||||
furlangModule->set_native_function("print",
|
||||
[](furvm::executor& executor) { std::cout << executor.load_thing(0)->integer() << '\n'; });
|
||||
|
||||
furvm::mod_h mainModule = context->emplace_module("main", s_bytecode.begin(), s_bytecode.end());
|
||||
furvm::mod_h mainModule = context->emplace("main", s_bytecode.begin(), s_bytecode.end());
|
||||
furvm::function_h mainFunc = mainModule->emplace_function("main", 0, 0);
|
||||
mainModule->emplace_function(furlangModule, printFunc).dispatch();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user