Reuse a lambda in main.cpp.

This commit is contained in:
Username404 2021-08-06 11:58:43 +02:00
parent 604532dc34
commit fbe8e189d3
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 12 additions and 9 deletions

View File

@ -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<string_view> uniqueFiles(files.begin(), files.end());
vector<future<string>> Units;
const launch& Policy = not parallel ? launch::deferred : launch::async;
for (string_view fileName: uniqueFiles) {
if (fileName != "none") {
future<string> 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<string> newAsync = async(Policy, [&fileName, &compile]() {
return compile(fileName);
});
Units.push_back(move(newAsync));
}