| 28 | }; |
| 29 | |
| 30 | static Result init_dyn_modules(smart_ptr<FileAccess> fa, string path, TextWriter &tout, bool debug = false) { |
| 31 | const auto mod_filename = path + "/" + MODULE_SUFFIX; |
| 32 | if (debug) { |
| 33 | tout << "try file: " << mod_filename << ".\n"; |
| 34 | } |
| 35 | auto fi = fa->getFileInfo(mod_filename); |
| 36 | if (fi) { |
| 37 | ModuleGroup dummyGroup; |
| 38 | if (debug) { |
| 39 | tout << "file found: " << mod_filename << ".\n"; |
| 40 | } |
| 41 | CodeOfPolicies policies; |
| 42 | policies.no_init_check = true; |
| 43 | auto program = compileDaScript(mod_filename, fa, tout, dummyGroup, policies); |
| 44 | if ( program->failed() ) { |
| 45 | for ( auto & err : program->errors ) { |
| 46 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr ); |
| 47 | } |
| 48 | return Result::CE; |
| 49 | } else { |
| 50 | auto pctx = SimulateWithErrReport(program, tout); |
| 51 | if ( !pctx ) { |
| 52 | return Result::SimError; |
| 53 | } else { |
| 54 | auto fnVec = pctx->findFunctions(INIT_NAME); |
| 55 | das::vector<SimFunction *> fnMVec; |
| 56 | for ( auto fnAS : fnVec ) { |
| 57 | if ( verifyCall<void, const char *>(fnAS->debugInfo, dummyGroup) ) { |
| 58 | fnMVec.push_back(fnAS); |
| 59 | } |
| 60 | } |
| 61 | if ( fnMVec.size()==0 ) { |
| 62 | tout << "function '" << INIT_NAME << "' not found in '" << path << "'\n"; |
| 63 | return Result::CE; |
| 64 | } else if ( fnMVec.size()>1 ) { |
| 65 | tout << "too many options for '" << INIT_NAME << "'\ncandidates are:\n"; |
| 66 | for ( auto fnAS : fnMVec ) { |
| 67 | tout << " " << fnAS->mangledName << "\n"; |
| 68 | } |
| 69 | return Result::CE; |
| 70 | } else { |
| 71 | auto fnTest = fnMVec.back(); |
| 72 | pctx->restart(); |
| 73 | char * fname = pctx->allocateString(path.c_str(),uint32_t(path.length()),nullptr); |
| 74 | vec4f args[1] = { |
| 75 | cast<char *>::from(fname) |
| 76 | }; |
| 77 | auto _res = pctx->evalWithCatch(fnTest, args); |
| 78 | if ( auto ex = pctx->getException() ) { |
| 79 | tout << "EXCEPTION: " << ex << " at " << pctx->exceptionAt.describe() << "\n"; |
| 80 | return Result::Exception; |
| 81 | } |
| 82 | return Result::OK; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } else { |
| 87 | if (debug) { |
no test coverage detected