Showing the changes to src/exec/main.cpp (1 of 3 files). Show all
Unified · Split
| @@ -38,22 +38,18 @@ namespace · 37 unmodified lines | |||
| 38 | if (vm_args.size() == 0) | 38 | if (vm_args.size() == 0) |
| 39 | throw vm_user_exception{ "Entry module not supplied" }; | 39 | throw vm_user_exception{ "Entry module not supplied" }; |
| 40 | 40 | ||
| 41 | // First argument is the module to load | ||
| 42 | auto entry_module_path = vm_args[0]; | ||
| 43 | auto command_module_path = new vm_string_t{ std::strlen(entry_module_path), reinterpret_cast<uint8_t *>(entry_module_path) }; | ||
| 44 | |||
| 45 | // Pre-load the command module in the VM. | ||
| 46 | command_module = vm.load_module(command_module_path->str()); | ||
| 47 | |||
| 48 | // Convert arguments to a list | 41 | // Convert arguments to a list |
| 42 | vm_string_t *command_module_path = nullptr; | ||
| 49 | vm_list_t *args = nullptr; | 43 | vm_list_t *args = nullptr; |
| 50 | vm_list_t *last = nullptr; | 44 | vm_list_t *last = nullptr; |
| 51 | for (auto i = std::size_t{ 1 }; i < vm_args.size(); ++i) | 45 | for (auto i = std::size_t{ 0 }; i < vm_args.size(); ++i) |
| 52 | { | 46 | { |
| 53 | auto tmp = vm_args[i]; | 47 | auto tmp = vm_args[i]; |
| 54 | auto arg = new vm_string_t{ std::strlen(tmp), reinterpret_cast<uint8_t *>(tmp) }; | 48 | auto arg = new vm_string_t{ std::strlen(tmp), reinterpret_cast<uint8_t *>(tmp) }; |
| 55 | if (args == nullptr) | 49 | if (args == nullptr) |
| 56 | { | 50 | { |
| 51 | // First argument is the module to load | ||
| 52 | command_module_path = arg; | ||
| 57 | assert(last == nullptr); | 53 | assert(last == nullptr); |
| 58 | args = new vm_list_t{ intrinsic_type_desc::type<vm_string_t>() }; | 54 | args = new vm_list_t{ intrinsic_type_desc::type<vm_string_t>() }; |
| 59 | last = args; | 55 | last = args; |
| @@ -70,7 +66,12 @@ namespace · 10 unmodified lines | |||
| 70 | pt_ref(last->value()) = arg->get_allocation(); | 66 | pt_ref(last->value()) = arg->get_allocation(); |
| 71 | } | 67 | } |
| 72 | 68 | ||
| 73 | // Create the module | 69 | assert(args != nullptr); |
| 70 | |||
| 71 | // Pre-load the command module in the VM. | ||
| 72 | command_module = vm.load_module(command_module_path->str()); | ||
| 73 | |||
| 74 | // Create the entry module | ||
| 74 | auto entry_module = std::make_unique<vm_module_t>(); | 75 | auto entry_module = std::make_unique<vm_module_t>(); |
| 75 | auto &e = *entry_module; | 76 | auto &e = *entry_module; |
| 76 | 77 | ||
| @@ -94,12 +95,13 @@ namespace · 17 unmodified lines | |||
| 94 | const auto mp_type = type_descriptor_t::create(8, { 0xc0 }); | 95 | const auto mp_type = type_descriptor_t::create(8, { 0xc0 }); |
| 95 | e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory)); | 96 | e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory)); |
| 96 | auto mp_base = e.original_mp->get_allocation<pointer_t>(); | 97 | auto mp_base = e.original_mp->get_allocation<pointer_t>(); |
| 97 | mp_base[0] = command_module_path->get_allocation(); | ||
| 98 | 98 | ||
| 99 | if (args != nullptr) | 99 | // Take a reference on the command module path and store it on the entry frame |
| 100 | mp_base[1] = args->get_allocation(); | 100 | command_module_path->add_ref(); |
| 101 | mp_base[0] = command_module_path->get_allocation(); | ||
| 102 | mp_base[1] = args->get_allocation(); | ||
| 101 | 103 | ||
| 102 | // Define the frame offsets for the two arguments | 104 | // Define the frame offset for the argument |
| 103 | const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset; | 105 | const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset; |
| 104 | 106 | ||
| 105 | e.code_section = | 107 | e.code_section = |
| @@ -360,7 +362,7 @@ int main(int argc, char* argv[]) · 254 unmodified lines | |||
| 360 | catch (const vm_system_exception &se) | 362 | catch (const vm_system_exception &se) |
| 361 | { | 363 | { |
| 362 | std::cerr | 364 | std::cerr |
| 363 | << "Internal exception:\n " | 365 | << "Internal exception:\n" |
| 364 | << se.what() | 366 | << se.what() |
| 365 | << std::endl; | 367 | << std::endl; |
| 366 | 368 | ||