Showing the changes to src/exec/main.cpp (1 of 10 files). Show all
Unified · Split
| @@ -11,10 +11,12 @@ · 10 unmodified lines | |||
| 11 | #include <builtin_module.h> | 11 | #include <builtin_module.h> |
| 12 | #include <debug.h> | 12 | #include <debug.h> |
| 13 | #include <exceptions.h> | 13 | #include <exceptions.h> |
| 14 | #include <vm_asm.h> | ||
| 14 | #include "exec.h" | 15 | #include "exec.h" |
| 15 | 16 | ||
| 16 | using namespace disvm; | 17 | using namespace disvm; |
| 17 | using namespace disvm::runtime; | 18 | using namespace disvm::runtime; |
| 19 | using namespace disvm::assembly::sigkind; | ||
| 18 | 20 | ||
| 19 | namespace | 21 | namespace |
| 20 | { | 22 | { |
| @@ -88,20 +90,16 @@ namespace · 67 unmodified lines | |||
| 88 | }; | 90 | }; |
| 89 | 91 | ||
| 90 | // Initialize the module base register | 92 | // Initialize the module base register |
| 91 | const auto mp_type = type_descriptor_t::create(12, { 0xe0 }); | 93 | const auto mp_type = type_descriptor_t::create(8, { 0xc0 }); |
| 92 | e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory)); | 94 | e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory)); |
| 93 | auto mp_base = e.original_mp->get_allocation<pointer_t>(); | 95 | auto mp_base = e.original_mp->get_allocation<pointer_t>(); |
| 94 | mp_base[0] = command_module_path->get_allocation(); | 96 | mp_base[0] = command_module_path->get_allocation(); |
| 95 | 97 | ||
| 96 | // [TODO] Implement the UI context for the command | ||
| 97 | mp_base[1] = nullptr; | ||
| 98 | |||
| 99 | if (args != nullptr) | 98 | if (args != nullptr) |
| 100 | mp_base[2] = args->get_allocation(); | 99 | mp_base[1] = args->get_allocation(); |
| 101 | 100 | ||
| 102 | // Define the frame offsets for the two arguments | 101 | // Define the frame offsets for the two arguments |
| 103 | const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset; | 102 | const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset; |
| 104 | const auto second_arg_offset = first_arg_offset + vm_frame_constants::register_size_in_bytes; | ||
| 105 | 103 | ||
| 106 | e.code_section = | 104 | e.code_section = |
| 107 | { | 105 | { |
| @@ -124,17 +122,9 @@ namespace · 16 unmodified lines | |||
| 124 | { vm_exec_op_t | 122 | { vm_exec_op_t |
| 125 | { | 123 | { |
| 126 | opcode_t::movp, | 124 | opcode_t::movp, |
| 127 | { address_mode_t::offset_indirect_mp, 4, 0 }, // UI context | 125 | { address_mode_t::offset_indirect_mp, 4, 0 }, // Argument list |
| 128 | { address_mode_middle_t::none }, | ||
| 129 | { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> UI context offset | ||
| 130 | } | ||
| 131 | }, | ||
| 132 | { vm_exec_op_t | ||
| 133 | { | ||
| 134 | opcode_t::movp, | ||
| 135 | { address_mode_t::offset_indirect_mp, 8, 0 }, // Argument list | ||
| 136 | { address_mode_middle_t::none }, | 126 | { address_mode_middle_t::none }, |
| 137 | { address_mode_t::offset_double_indirect_fp, 24, second_arg_offset } // module call frame -> argument list offset | 127 | { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> argument list offset |
| 138 | } | 128 | } |
| 139 | }, | 129 | }, |
| 140 | { vm_exec_op_t | 130 | { vm_exec_op_t |
| @@ -148,13 +138,21 @@ namespace · 7 unmodified lines | |||
| 148 | { vm_exec_op_t{ opcode_t::ret,{ address_mode_t::none },{ address_mode_middle_t::none },{ address_mode_t::none } } }, | 138 | { vm_exec_op_t{ opcode_t::ret,{ address_mode_t::none },{ address_mode_middle_t::none },{ address_mode_t::none } } }, |
| 149 | }; | 139 | }; |
| 150 | 140 | ||
| 151 | // Create import section for Command | 141 | // Create import section for Exec |
| 152 | // See limbo/Command.m for type details | 142 | // See limbo/Exec.m for type details |
| 153 | { | 143 | { |
| 154 | import_function_t func{}; | 144 | import_function_t func; |
| 155 | 145 | ||
| 156 | // [TODO] Create mechanism to generated type signatures | 146 | const auto exec_init_sig = 0x2e01144a; |
| 157 | func.sig = 0x4244b354; | 147 | |
| 148 | // Validate the hard-coded type signature on debug builds. | ||
| 149 | #if !defined(NDEBUG) | ||
| 150 | sig_stream_t m; | ||
| 151 | m << Tfunction::create(Tlist::create(Tstring::id)).returns(Tnone::id); | ||
| 152 | assert(exec_init_sig == m.get_signature_hash()); | ||
| 153 | assert(exec_init_sig == sig_stream_t::compute_signature_hash("f(Ls)n")); | ||
| 154 | #endif | ||
| 155 | func.sig = exec_init_sig; | ||
| 158 | 156 | ||
| 159 | std::array<uint8_t, 5> func_name = { "init" }; | 157 | std::array<uint8_t, 5> func_name = { "init" }; |
| 160 | func.name = std::make_unique<vm_string_t>(func_name.size() - 1, func_name.data()); | 158 | func.name = std::make_unique<vm_string_t>(func_name.size() - 1, func_name.data()); |