+11
-10
@@ -11,19 +11,19 @@
|
||||
#include <sstream>
|
||||
|
||||
static void print_thing(const furvm::thing<furvm::thing_allocator>& thing) {
|
||||
switch (thing.type()->t) {
|
||||
case furvm::type_t::Primitive: {
|
||||
switch (thing.type().type) {
|
||||
case furvm::thing_type::Primitive: {
|
||||
std::cout << thing.integer();
|
||||
} break;
|
||||
case furvm::type_t::Array: {
|
||||
case furvm::thing_type::Array: {
|
||||
std::cout << "{ ";
|
||||
for (furvm::long_t i = 0; i < thing.size(); ++i) {
|
||||
for (furvm::thing<>::s64 i = 0; i < thing.size(); ++i) {
|
||||
if (i > 0) std::cout << ", ";
|
||||
print_thing(thing.at(i));
|
||||
}
|
||||
std::cout << " }\n";
|
||||
} break;
|
||||
default: std::cerr << "{Something went wrong}";
|
||||
default: std::cerr << "{Type not recognized}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ int main(int argc, char** argv) {
|
||||
#else
|
||||
static const furvm::byte s_bytecode[] = {
|
||||
static_cast<furvm::byte>(furvm::instruction_t::Array),
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
@@ -58,10 +58,11 @@ int main(int argc, char** argv) {
|
||||
static_cast<furvm::byte>(furvm::instruction_t::Return),
|
||||
};
|
||||
|
||||
furvm::mod_h mod = context->emplace("main", s_bytecode, s_bytecode + sizeof(s_bytecode));
|
||||
furvm::type_h intType = mod->emplace_type(std::make_shared<furvm::type>(context->at("core")->type_at(2), 10));
|
||||
auto mainFunc = mod->emplace_function("main", furvm::function_sig{}, 0);
|
||||
mod->emplace_function(furvm::function_sig{ { intType } }, "print").dispatch();
|
||||
auto mod = context->emplace("main", s_bytecode, s_bytecode + sizeof(s_bytecode));
|
||||
auto intType = mod->emplace_type(sizeof(int));
|
||||
auto arrayType = mod->emplace_type(intType.id(), 10);
|
||||
auto mainFunc = mod->emplace_function("main", furvm::function_sig{}, 0);
|
||||
mod->emplace_function(furvm::function_sig{ { arrayType } }, "print").dispatch();
|
||||
#endif
|
||||
mod->set_native_function("print", [](furvm::executor& executor) { print_thing(*executor.load_thing(0)); });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user