+13
-9
@@ -12,9 +12,17 @@
|
||||
|
||||
namespace furvm {
|
||||
|
||||
void executor::push_frame(const mod_h& mod, const function_h& function) {
|
||||
if (function->type() != function_t::Normal) throw std::runtime_error("unexpected function type");
|
||||
m_frames.emplace((struct executor::frame){ mod, function->position(), m_stack.size() });
|
||||
void executor::push_frame(const mod_h& mod, function function) {
|
||||
while (function.type() == function_t::Import) {
|
||||
function = *m_context->module_at(function.imp().mod)->function_at(function.imp().function);
|
||||
}
|
||||
switch (function.type()) {
|
||||
case function_t::Normal: {
|
||||
m_frames.emplace((struct executor::frame){ mod, function.position(), m_stack.size() });
|
||||
} break;
|
||||
case function_t::Native:
|
||||
default: throw std::runtime_error("unexpected function type");
|
||||
}
|
||||
}
|
||||
|
||||
struct executor::frame executor::pop_frame() {
|
||||
@@ -155,13 +163,9 @@ void executor::step() {
|
||||
|
||||
const function_h& function = frame.mod->function_at(funcId);
|
||||
switch (function->type()) {
|
||||
case function_t::Normal: push_frame(frame.mod, function); break;
|
||||
case function_t::Normal:
|
||||
case function_t::Import: push_frame(frame.mod, *function); break;
|
||||
case function_t::Native: function->native()(*this); break;
|
||||
case function_t::Import: {
|
||||
// const mod_p& impMod = m_context->m_modules.at(function->imported_module());
|
||||
// push_frame(frame.mod, function->imported_function());
|
||||
throw std::runtime_error("unimplemented");
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
case instruction_t::Jump: {
|
||||
|
||||
@@ -10,7 +10,7 @@ function::~function() {
|
||||
case function_t::Native:
|
||||
default: break;
|
||||
case function_t::Import: {
|
||||
m_value.imp.moduleName.~basic_string();
|
||||
m_value.imp.~import_function();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,7 @@ function::function(function&& other) noexcept
|
||||
new (&m_value.native) native_function(std::move(other.m_value.native));
|
||||
} break;
|
||||
case function_t::Import: {
|
||||
m_value.imp.moduleName = std::move(other.m_value.imp.moduleName);
|
||||
m_value.imp.function = other.m_value.imp.function;
|
||||
m_value.imp = std::move(other.m_value.imp);
|
||||
} break;
|
||||
}
|
||||
other.m_value.position = 0;
|
||||
@@ -45,8 +44,7 @@ function& function::operator=(function&& other) noexcept {
|
||||
new (&m_value.native) native_function(std::move(other.m_value.native));
|
||||
} break;
|
||||
case function_t::Import: {
|
||||
m_value.imp.moduleName = std::move(other.m_value.imp.moduleName);
|
||||
m_value.imp.function = other.m_value.imp.function;
|
||||
m_value.imp = std::move(other.m_value.imp);
|
||||
} break;
|
||||
}
|
||||
other.m_value.position = 0;
|
||||
@@ -64,8 +62,7 @@ function::function(const function& other)
|
||||
new (&m_value.native) native_function(other.m_value.native);
|
||||
} break;
|
||||
case function_t::Import: {
|
||||
m_value.imp.moduleName = other.m_value.imp.moduleName;
|
||||
m_value.imp.function = other.m_value.imp.function;
|
||||
m_value.imp = other.m_value.imp;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -83,8 +80,7 @@ function& function::operator=(const function& other) {
|
||||
new (&m_value.native) native_function(other.m_value.native);
|
||||
} break;
|
||||
case function_t::Import: {
|
||||
m_value.imp.moduleName = other.m_value.imp.moduleName;
|
||||
m_value.imp.function = other.m_value.imp.function;
|
||||
m_value.imp = other.m_value.imp;
|
||||
} break;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ int main(void) {
|
||||
furvm::function_h mainFunc = mainModule->emplace_function("main", 0);
|
||||
|
||||
furvm::executor_h executor = context->emplace_executor(context);
|
||||
executor->push_frame(mainModule, mainFunc);
|
||||
executor->push_frame(mainModule, *mainFunc);
|
||||
|
||||
static constexpr std::size_t FPC = 3; // Frames per collection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user