| 1297 | } |
| 1298 | |
| 1299 | ProgramPtr compileDaScript ( const string & fileName, |
| 1300 | const FileAccessPtr & access, |
| 1301 | TextWriter & logs, |
| 1302 | ModuleGroup & libGroup, |
| 1303 | CodeOfPolicies policies ) { |
| 1304 | DAS_ASSERTF(policies.no_init_check || (daScriptEnvironment::getBound() && daScriptEnvironment::getBound()->g_modulesInitialized), |
| 1305 | "compileDaScript on an environment that never called Module::Initialize(); " |
| 1306 | "call das::Module::Initialize() after registering modules in this environment."); |
| 1307 | gc_guard compile_gc_scope; |
| 1308 | GcCollectOnExit compile_gc_collect(compile_gc_scope); |
| 1309 | ReuseCacheGuard rcg; |
| 1310 | bool exportAll = policies.export_all || policies.validate_ast; |
| 1311 | if ( policies.validate_ast ) policies.rtti = true; |
| 1312 | auto time0 = ref_time_ticks(); |
| 1313 | *totParse = 0; |
| 1314 | *totInfer = 0; |
| 1315 | *totOpt = 0; |
| 1316 | *totM = 0; |
| 1317 | daScriptEnvironment::getBound()->macroTimeTicks = 0; |
| 1318 | vector<ModuleInfo> req; |
| 1319 | vector<MissingRecord> missing; |
| 1320 | vector<RequireRecord> circular, notAllowed; |
| 1321 | vector<FileInfo *> chain; |
| 1322 | das_set<string> dependencies; |
| 1323 | das_hash_map<string, NamelessModuleReq> namelessReq; |
| 1324 | vector<NamelessMismatch> namelessMismatches; |
| 1325 | uint64_t preqT = 0; |
| 1326 | string modName; |
| 1327 | auto builtinModule = Module::require("$"); |
| 1328 | DAS_ASSERTF(builtinModule, "Somehow `builtin` module is missing."); |
| 1329 | auto builtin_path = getDasRoot() + "/daslib/builtin.das"; |
| 1330 | bool allGood = addExtraDependency("builtin", builtin_path, missing, circular, notAllowed, req, dependencies, namelessReq, namelessMismatches, access, libGroup, policies, &logs); |
| 1331 | if ( !allGood ) { |
| 1332 | auto res = make_smart<Program>(); |
| 1333 | res->error("internal error: failed to build builtin.das", logs.str(), "", LineInfo(), CompilationError::internal_module); |
| 1334 | return res; |
| 1335 | } |
| 1336 | for ( const auto & em : access->getExtraModules() ) { |
| 1337 | allGood = addExtraDependency(em.first, em.second, missing, circular, notAllowed, req, dependencies, namelessReq, namelessMismatches, access, libGroup, policies, &logs) && allGood; |
| 1338 | } |
| 1339 | if ( !allGood ) { |
| 1340 | auto res = make_smart<Program>(); |
| 1341 | res->error("internal error", logs.str(), "", LineInfo(), CompilationError::internal_module); |
| 1342 | return res; |
| 1343 | } |
| 1344 | if ( getPrerequisits(fileName, access, modName, req, missing, circular, notAllowed, chain, |
| 1345 | dependencies, namelessReq, namelessMismatches, libGroup, nullptr, 1, !policies.ignore_shared_modules) ) { |
| 1346 | preqT = get_time_usec(time0); |
| 1347 | disableSerializationOnDebugger(req); |
| 1348 | if ( !verifyModuleNamesUnique(req, logs) ) { |
| 1349 | auto res = make_smart<Program>(); |
| 1350 | res->error("Several modules with invalid names", logs.str(), "", LineInfo(), |
| 1351 | CompilationError::already_declared_module); |
| 1352 | return res; |
| 1353 | } |
| 1354 | for ( const auto & mod : req) { |
| 1355 | if (mod.moduleName == modName) { |
| 1356 | auto res = make_smart<Program>(); |