| 160 | } |
| 161 | |
| 162 | void Module::Initialize() { |
| 163 | daScriptEnvironment::ensure(); |
| 164 | static bool atexit_registered = (atexit(daslang_atexit_audit), true); |
| 165 | (void)atexit_registered; |
| 166 | g_envTotal ++; |
| 167 | |
| 168 | if (daScriptEnvironment::getBound()->modules == nullptr) { |
| 169 | DAS_FATAL_ERROR("No modules founds. You should add modules before call that function."); |
| 170 | } |
| 171 | |
| 172 | // InitDependencies do not add new modules. |
| 173 | vector<bool> mod_state; |
| 174 | bool any = true; |
| 175 | bool all = false; |
| 176 | while ( !all && any ) { |
| 177 | all = true; |
| 178 | any = false; |
| 179 | size_t i = 0; |
| 180 | for ( auto m = daScriptEnvironment::getBound()->modules; m ; m = m->next, i++ ) { |
| 181 | auto result = m->initDependencies(); |
| 182 | all &= result; |
| 183 | if (i >= mod_state.size()) { |
| 184 | // init |
| 185 | mod_state.emplace_back(false); |
| 186 | DAS_ASSERT(mod_state.size() == i + 1); |
| 187 | } |
| 188 | if (result && !mod_state.at(i)) { |
| 189 | mod_state.at(i) = true; |
| 190 | any = true; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | if (!any) { |
| 195 | // Some modules was not initialized! |
| 196 | size_t i = 0; |
| 197 | string error = ""; |
| 198 | for ( auto m = daScriptEnvironment::getBound()->modules; m ; m = m->next, i++ ) { |
| 199 | DAS_ASSERT(mod_state.size() == i); |
| 200 | if (!mod_state.at(i)) { |
| 201 | error += " " + m->name; |
| 202 | } |
| 203 | } |
| 204 | DAS_FATAL_ERROR("Unable to initialize some modules:%s\n", error.c_str()); |
| 205 | } |
| 206 | // Collect reachable TypeDecl from thread root into module roots, sweep the rest. |
| 207 | auto & threadRoot = gc_root::gc_get_thread_root(); |
| 208 | for ( auto m = daScriptEnvironment::getBound()->modules; m ; m = m->next ) { |
| 209 | m->gc_collect(&threadRoot); |
| 210 | } |
| 211 | threadRoot.gc_sweep(); |
| 212 | daScriptEnvironment::getBound()->g_modulesInitialized = true; |
| 213 | } |
| 214 | |
| 215 | void Module::CollectFileInfo(das::vector<FileInfoPtr> &finfos) { |
| 216 | DAS_ASSERT(daScriptEnvironment::getOwned()!=nullptr); |
nothing calls this directly
no test coverage detected