Reuse a lambda in main.cpp.
This commit is contained in:
parent
604532dc34
commit
fbe8e189d3
21
src/main.cpp
21
src/main.cpp
|
@ -30,21 +30,24 @@ int main(int argc, char* argv[]) {
|
||||||
else if (currentArg == Argument("parallel")) parallel = true;
|
else if (currentArg == Argument("parallel")) parallel = true;
|
||||||
else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg);
|
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()) {
|
if (!files.empty()) {
|
||||||
const set<string_view> uniqueFiles(files.begin(), files.end());
|
const set<string_view> uniqueFiles(files.begin(), files.end());
|
||||||
vector<future<string>> Units;
|
vector<future<string>> Units;
|
||||||
const launch& Policy = not parallel ? launch::deferred : launch::async;
|
const launch& Policy = not parallel ? launch::deferred : launch::async;
|
||||||
for (string_view fileName: uniqueFiles) {
|
for (string_view fileName: uniqueFiles) {
|
||||||
if (fileName != "none") {
|
if (fileName != "none") {
|
||||||
future<string> newAsync = async(Policy, [printResult, fileName, target]() mutable {
|
future<string> newAsync = async(Policy, [&fileName, &compile]() {
|
||||||
const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target);
|
return compile(fileName);
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
Units.push_back(move(newAsync));
|
Units.push_back(move(newAsync));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue