History

Address code analysis violations. Disable all Microsoft language extensions - All header files now end with a single new line character. Split vs_asm header from type signature templates - vs_asm_sigkind.h created

arr committed 9 years ago

Commit 02a7d6a1 parent ea995f224 files · +417 −392Browse files

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

Unified · Split

src/exec/main.cpp+19−23
@@ -11,7 +11,7 @@ · 10 unmodified lines
1111 #include <builtin_module.h>
1212 #include <debug.h>
1313 #include <exceptions.h>
14−#include <vm_asm.h>
14+#include <vm_asm_sigkind.h>
1515 #include <vm_version.h>
1616 #include "exec.h"
1717
@@ -21,6 +21,12 @@ using namespace disvm::assembly::sigkind; · 3 unmodified lines
2121
2222 namespace
2323 {
24+ template<int L>
25+ std::unique_ptr<vm_string_t> create_string_from_const(const char(&ca)[L])
26+ {
27+ return std::make_unique<vm_string_t>(L - 1, reinterpret_cast<const uint8_t*>(ca));
28+ }
29+
2430 // Entry frame layout
2531 struct vm_entry_frame_t final : public vm_frame_base_alloc_t
2632 {
@@ -35,24 +41,17 @@ namespace · 8 unmodified lines
3541
3642 std::unique_ptr<vm_module_t> create_entry_module(vm_t &vm, const std::vector<char *> &vm_args)
3743 {
38− if (vm_args.size() == 0)
39− throw vm_user_exception{ "Entry module not supplied" };
40−
4144 // Convert arguments to a list
4245 vm_string_t *command_module_path = nullptr;
43− vm_list_t *args = nullptr;
44− vm_list_t *last = nullptr;
45− for (auto i = std::size_t{ 0 }; i < vm_args.size(); ++i)
46+ vm_list_t *mod_args = new vm_list_t{ intrinsic_type_desc::type<vm_string_t>() };
47+ vm_list_t *last = mod_args;
48+ for (auto raw_arg : vm_args)
4649 {
47− auto tmp = vm_args[i];
48− auto arg = new vm_string_t{ std::strlen(tmp), reinterpret_cast<uint8_t *>(tmp) };
49− if (args == nullptr)
50+ auto curr_arg = new vm_string_t{ std::strlen(raw_arg), reinterpret_cast<uint8_t *>(raw_arg) };
51+ if (command_module_path == nullptr)
5052 {
5153 // First argument is the module to load
52− command_module_path = arg;
53− assert(last == nullptr);
54− args = new vm_list_t{ intrinsic_type_desc::type<vm_string_t>() };
55− last = args;
54+ command_module_path = curr_arg;
5655 }
5756 else
5857 {
@@ -63,10 +62,11 @@ namespace · 4 unmodified lines
6362 last = new_tail;
6463 }
6564
66− pt_ref(last->value()) = arg->get_allocation();
65+ pt_ref(last->value()) = curr_arg->get_allocation();
6766 }
6867
69− assert(args != nullptr);
68+ if (command_module_path == nullptr)
69+ throw vm_user_exception{ "Entry module not supplied" };
7070
7171 // Pre-load the command module in the VM.
7272 command_module = vm.load_module(command_module_path->str());
@@ -79,9 +79,7 @@ namespace · 6 unmodified lines
7979 e.header.entry_pc = 0;
8080 e.header.entry_type = 0;
8181 e.header.runtime_flag = (runtime_flags_t::has_import);
82−
83− std::array<uint8_t, 8> mod_name = { "_entry_" };
84− e.module_name = std::make_unique<vm_string_t>(mod_name.size() - 1, mod_name.data());
82+ e.module_name = create_string_from_const("_entry_");
8583
8684 // Inherit the stack extent from the command module and add the entry frame size.
8785 e.header.stack_extent = command_module->header.stack_extent + sizeof(vm_entry_frame_t);
@@ -99,7 +97,7 @@ namespace · 11 unmodified lines
9997 // Take a reference on the command module path and store it on the entry frame
10098 command_module_path->add_ref();
10199 mp_base[0] = command_module_path->get_allocation();
102− mp_base[1] = args->get_allocation();
100+ mp_base[1] = mod_args->get_allocation();
103101
104102 // Define the frame offset for the argument
105103 const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset();
@@ -168,9 +166,7 @@ namespace · 62 unmodified lines
168166 assert(exec_init_sig == sig_stream_t::compute_signature_hash("f(Ls)n"));
169167 #endif
170168 func.sig = exec_init_sig;
171−
172− std::array<uint8_t, 5> func_name = { "init" };
173− func.name = std::make_unique<vm_string_t>(func_name.size() - 1, func_name.data());
169+ func.name = create_string_from_const("init");
174170
175171 import_vm_module_t import{};
176172 import.functions.push_back(std::move(func));