History

The disvm-exec program was dropping the name of the module in the argument list passed to the Exec.init() entry point.

arr committed 10 years ago

Commit ed790b41 parent 824a71a3 files · +23 −16Browse files

Showing the changes to src/exec/main.cpp (1 of 3 files). Show all

Unified · Split

src/exec/main.cpp+16−14
@@ -38,22 +38,18 @@ namespace · 37 unmodified lines
3838 if (vm_args.size() == 0)
3939 throw vm_user_exception{ "Entry module not supplied" };
4040
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−
4841 // Convert arguments to a list
42+ vm_string_t *command_module_path = nullptr;
4943 vm_list_t *args = nullptr;
5044 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)
5246 {
5347 auto tmp = vm_args[i];
5448 auto arg = new vm_string_t{ std::strlen(tmp), reinterpret_cast<uint8_t *>(tmp) };
5549 if (args == nullptr)
5650 {
51+ // First argument is the module to load
52+ command_module_path = arg;
5753 assert(last == nullptr);
5854 args = new vm_list_t{ intrinsic_type_desc::type<vm_string_t>() };
5955 last = args;
@@ -70,7 +66,12 @@ namespace · 10 unmodified lines
7066 pt_ref(last->value()) = arg->get_allocation();
7167 }
7268
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
7475 auto entry_module = std::make_unique<vm_module_t>();
7576 auto &e = *entry_module;
7677
@@ -94,12 +95,13 @@ namespace · 17 unmodified lines
9495 const auto mp_type = type_descriptor_t::create(8, { 0xc0 });
9596 e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory));
9697 auto mp_base = e.original_mp->get_allocation<pointer_t>();
97− mp_base[0] = command_module_path->get_allocation();
9898
99− if (args != nullptr)
100− mp_base[1] = args->get_allocation();
99+ // Take a reference on the command module path and store it on the entry frame
100+ command_module_path->add_ref();
101+ mp_base[0] = command_module_path->get_allocation();
102+ mp_base[1] = args->get_allocation();
101103
102− // Define the frame offsets for the two arguments
104+ // Define the frame offset for the argument
103105 const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset;
104106
105107 e.code_section =
@@ -360,7 +362,7 @@ int main(int argc, char* argv[]) · 254 unmodified lines
360362 catch (const vm_system_exception &se)
361363 {
362364 std::cerr
363− << "Internal exception:\n "
365+ << "Internal exception:\n"
364366 << se.what()
365367 << std::endl;
366368