diff --git a/src/main.cpp b/src/main.cpp index 384f681..9e2d23d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,21 +30,24 @@ int main(int argc, char* argv[]) { else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); } + const auto compile = [printResult, target](string_view& name) { + const string transpiledString = transpile(parseString(getFileContent(name.data())), target); + stringstream consoleOutput; + if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; + name.remove_suffix(6); + string outputFile; + (outputFile = name).append(target); + outputFileContent(outputFile, transpiledString); + return consoleOutput.str(); + }; if (!files.empty()) { const set uniqueFiles(files.begin(), files.end()); vector> Units; const launch& Policy = not parallel ? launch::deferred : launch::async; for (string_view fileName: uniqueFiles) { if (fileName != "none") { - future newAsync = async(Policy, [printResult, fileName, target]() mutable { - const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target); - stringstream consoleOutput; - if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; - fileName.remove_suffix(6); - string outputFile; - (outputFile = fileName).append(target); - outputFileContent(outputFile, transpiledString); - return consoleOutput.str(); + future newAsync = async(Policy, [&fileName, &compile]() { + return compile(fileName); }); Units.push_back(move(newAsync)); }