boot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "crucible/core/boot.hpp" #include "crucible/core/environment.hpp" #include "crucible/core/handlers.hpp" #include "crucible/core/iterators.hpp" #include <exception> #include <type_traits> #include <utility> namespace crucible { auto boot_from_main(int argc, char **argv, boot_function const boot) -> int { // Very first thing: set the terminate handler so that we get a backtrace if anything crashes std::set_terminate(handle_terminate); // Parse environment variables environment().initialize(); // Convert argv into Crucible data structures auto const arguments { iterate(argv, argc) .map([](char const *argument) { return string_view { argument, std::strlen(argument) }; }) .materialize<heap_buffer<string_view>>() }; // Call into client code. If you're looking for where your program starts, it's here :) exit_status const status { boot(arguments.view()) }; // Convert exit_status back into an int and finish up static_assert(std::is_same_v<std::underlying_type_t<exit_status>, int>); return static_cast<int>(status); } }