From 0d0d9a9c56822919e9794658d31db57f8fc3e2bf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Dec 2015 13:54:59 +0200 Subject: Implement two-phase initialization of modules loaded from bootstrap.build --- build/module | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'build/module') diff --git a/build/module b/build/module index 984a50f..061ef60 100644 --- a/build/module +++ b/build/module @@ -6,8 +6,11 @@ #define BUILD_MODULE #include -#include -#include // unique_ptr + +#include +#include + +#include namespace build { @@ -21,6 +24,10 @@ namespace build ~module () = default; }; + extern "C" + using module_boot_function = + void (scope& root, const location&, unique_ptr&); + // Return false if the module configuration (normally based on the default // values) was unsuccessful but this is not (yet) an error. One example // would be the optional use of a module. Or a module might remain @@ -32,17 +39,30 @@ namespace build bool (scope& root, scope& base, const location&, - std::unique_ptr&, + unique_ptr&, bool first, // First time for this project. bool optional); // Loaded with 'using?' (optional module). - using loaded_module_map = - std::map>>; - // Load the specified module. Used by the parser but also by some - // modules to load prerequisite modules. Return true if the module - // was both successfully loaded and configured. + struct module_state + { + bool boot; // True if the module boot'ed but not yet init'ed. + module_init_function* init; + unique_ptr module; + const location loc; // Boot location. + }; + + using loaded_module_map = std::map; + + // Load and boot the specified module. + // + void + boot_module (const string& name, scope& root, const location&); + + // Load (if not already loaded) and initialize the specified module. Used + // by the parser but also by some modules to load prerequisite modules. + // Return true if the module was both successfully loaded and configured + // (false can only be returned if optional). // bool load_module (bool optional, @@ -53,7 +73,13 @@ namespace build // Builtin modules. // - using available_module_map = std::map; + struct module_functions + { + module_boot_function* boot; + module_init_function* init; + }; + + using available_module_map = std::map; extern available_module_map builtin_modules; } -- cgit v1.1