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.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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue