Showing the changes to src/exec/main.cpp (1 of 18 files). Show all
Unified · Split
| @@ -4,12 +4,14 @@ · 3 unmodified lines | ||
| 4 | 4 | // Author: arr |
| 5 | 5 | // |
| 6 | 6 | |
| 7 | −#include <cstdio> | |
| 7 | +#include <iostream> | |
| 8 | 8 | #include <cassert> |
| 9 | 9 | #include <array> |
| 10 | −#include <disvm.h> | |
| 10 | +#include <memory> | |
| 11 | 11 | #include <builtin_module.h> |
| 12 | 12 | #include <debug.h> |
| 13 | +#include <exceptions.h> | |
| 14 | +#include "exec.h" | |
| 13 | 15 | |
| 14 | 16 | using namespace disvm; |
| 15 | 17 | using namespace disvm::runtime; |
| @@ -26,13 +28,10 @@ namespace · 10 unmodified lines | ||
| 26 | 28 | |
| 27 | 29 | const auto entry_frame_pointer_map = std::vector<byte_t>{ 0x06 }; |
| 28 | 30 | |
| 29 | − std::shared_ptr<const runtime::vm_module_t> command_module; | |
| 31 | + std::shared_ptr<const vm_module_t> command_module; | |
| 30 | 32 | |
| 31 | − std::unique_ptr<vm_module_t> create_entry_module(disvm::vm_t &vm, int argc, char* argv[]) | |
| 33 | + std::unique_ptr<vm_module_t> create_entry_module(vm_t &vm, int argc, char* argv[]) | |
| 32 | 34 | { |
| 33 | − if (argc == 0) | |
| 34 | − return{}; | |
| 35 | − | |
| 36 | 35 | // First argument is the module to load |
| 37 | 36 | auto command_module_path = new vm_string_t{ std::strlen(argv[0]), reinterpret_cast<uint8_t *>(argv[0]) }; |
| 38 | 37 | |
| @@ -168,14 +167,37 @@ namespace · 129 unmodified lines | ||
| 168 | 167 | |
| 169 | 168 | int main(int argc, char* argv[]) |
| 170 | 169 | { |
| 171 | − disvm::vm_t vm; | |
| 170 | + // [TODO] Handle command line arguments | |
| 171 | + assert(argc > 1); | |
| 172 | + | |
| 173 | + vm_t vm; | |
| 174 | + | |
| 175 | + //vm.load_tool(std::make_shared<debugger>()); | |
| 172 | 176 | |
| 173 | − // Ignore the process name | |
| 174 | − auto entry = create_entry_module(vm, argc - 1, argv + 1); | |
| 177 | + try | |
| 178 | + { | |
| 179 | + // Ignore the process name | |
| 180 | + auto entry = create_entry_module(vm, argc - 1, argv + 1); | |
| 175 | 181 | |
| 176 | − vm.exec(std::move(entry)); | |
| 182 | + vm.exec(std::move(entry)); | |
| 177 | 183 | |
| 178 | − vm.spin_sleep_till_idle(std::chrono::milliseconds(100)); | |
| 184 | + vm.spin_sleep_till_idle(std::chrono::milliseconds(100)); | |
| 185 | + } | |
| 186 | + catch (vm_user_exception &ue) | |
| 187 | + { | |
| 188 | + std::cout << ue.what() << std::endl; | |
| 189 | + | |
| 190 | + return EXIT_FAILURE; | |
| 191 | + } | |
| 192 | + catch (vm_system_exception &se) | |
| 193 | + { | |
| 194 | + std::cout | |
| 195 | + << "Internal exception:\n\t" | |
| 196 | + << se.what() | |
| 197 | + << std::endl; | |
| 198 | + | |
| 199 | + return EXIT_FAILURE; | |
| 200 | + } | |
| 179 | 201 | |
| 180 | 202 | return 0; |
| 181 | 203 | } |