forked from KPGPMC/furlang
feat(furvm): add basic function
This commit is contained in:
+12
-1
@@ -2,10 +2,13 @@
|
||||
|
||||
#include "furvm/context.hpp"
|
||||
#include "furvm/executor.hpp"
|
||||
#include "furvm/function.hpp"
|
||||
#include "furvm/instruction.hpp"
|
||||
#include "furvm/thing.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
static constexpr std::array<furvm::byte, 6> s_bytecode = {
|
||||
@@ -17,13 +20,21 @@ static constexpr std::array<furvm::byte, 6> s_bytecode = {
|
||||
furvm::byte(furvm::instruction_t::Return),
|
||||
};
|
||||
|
||||
void print(const furvm::executor_p& exec) {
|
||||
std::cout << exec->pop_thing()->int32() << '\n';
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
auto context = std::make_shared<furvm::context>();
|
||||
|
||||
auto mainModule = context->emplace(s_bytecode.begin(), s_bytecode.end());
|
||||
|
||||
auto mainFunction = furvm::function::create(mainModule, 0);
|
||||
|
||||
auto printFunction = furvm::function::create(mainModule, print);
|
||||
|
||||
auto executor = furvm::executor::create(context);
|
||||
executor->push_frame(mainModule, 0);
|
||||
executor->push_frame(mainFunction);
|
||||
|
||||
static constexpr std::size_t FPC = 3; // Frames per collection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user