diff options
author | Liga <liga@wednesday.wtf> | 2024-03-12 02:26:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 10:26:17 +0800 |
commit | 4f399a181dc773bcc1a86737522915c2c776fb2b (patch) | |
tree | c8a77ec0d1527cea74bf86c759e1f2b471b16eb2 | |
parent | b1661cc294132bb89b16fccbc1a70ff8824eb002 (diff) | |
download | yuescript-0.22.3.tar.gz yuescript-0.22.3.tar.bz2 yuescript-0.22.3.zip |
Added option to stop implicit returns on the root. (#164)v0.22.3
-rw-r--r-- | src/yue.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 96bee0b..159132d 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
@@ -31,7 +31,9 @@ using namespace std::chrono_literals; | |||
31 | #include "linenoise.hpp" | 31 | #include "linenoise.hpp" |
32 | 32 | ||
33 | #if not(defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) | 33 | #if not(defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) |
34 | #define _DEFER(code, line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto) { code; }) | 34 | #define _DEFER(code, line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto) { \ |
35 | code; \ | ||
36 | }) | ||
35 | #define DEFER(code) _DEFER(code, __LINE__) | 37 | #define DEFER(code) _DEFER(code, __LINE__) |
36 | extern "C" { | 38 | extern "C" { |
37 | #include "lauxlib.h" | 39 | #include "lauxlib.h" |
@@ -292,6 +294,7 @@ int main(int narg, const char** args) { | |||
292 | " -b Dump compile time (doesn't write output)\n" | 294 | " -b Dump compile time (doesn't write output)\n" |
293 | " -g Dump global variables used in NAME LINE COLUMN\n" | 295 | " -g Dump global variables used in NAME LINE COLUMN\n" |
294 | " -l Write line numbers from source codes\n" | 296 | " -l Write line numbers from source codes\n" |
297 | " -j Disable implicit return at end of file\n" | ||
295 | " -c Reserve comments before statement from source codes\n" | 298 | " -c Reserve comments before statement from source codes\n" |
296 | #ifndef YUE_NO_WATCHER | 299 | #ifndef YUE_NO_WATCHER |
297 | " -w path Watch changes and compile every file under directory\n" | 300 | " -w path Watch changes and compile every file under directory\n" |
@@ -597,6 +600,8 @@ int main(int narg, const char** args) { | |||
597 | config.reserveLineNumber = true; | 600 | config.reserveLineNumber = true; |
598 | } else if (arg == "-c"sv) { | 601 | } else if (arg == "-c"sv) { |
599 | config.reserveComment = true; | 602 | config.reserveComment = true; |
603 | } else if (arg == "-j"sv) { | ||
604 | config.implicitReturnRoot = false; | ||
600 | } else if (arg == "-p"sv) { | 605 | } else if (arg == "-p"sv) { |
601 | writeToFile = false; | 606 | writeToFile = false; |
602 | } else if (arg == "-g"sv) { | 607 | } else if (arg == "-g"sv) { |
@@ -632,7 +637,7 @@ int main(int narg, const char** args) { | |||
632 | #else | 637 | #else |
633 | std::cout << "Error: -w is not supported\n"sv; | 638 | std::cout << "Error: -w is not supported\n"sv; |
634 | return 1; | 639 | return 1; |
635 | #endif // YUE_NO_WATCHER | 640 | #endif // YUE_NO_WATCHER |
636 | } else if (arg.size() > 2 && arg.substr(0, 2) == "--"sv && arg.substr(2, 1) != "-"sv) { | 641 | } else if (arg.size() > 2 && arg.substr(0, 2) == "--"sv && arg.substr(2, 1) != "-"sv) { |
637 | auto argStr = arg.substr(2); | 642 | auto argStr = arg.substr(2); |
638 | yue::Utils::trim(argStr); | 643 | yue::Utils::trim(argStr); |
@@ -698,7 +703,7 @@ int main(int narg, const char** args) { | |||
698 | #ifndef YUE_COMPILER_ONLY | 703 | #ifndef YUE_COMPILER_ONLY |
699 | return compileFile(fs::absolute(file.first), config, fullWorkPath, fullTargetPath, minify, rewrite); | 704 | return compileFile(fs::absolute(file.first), config, fullWorkPath, fullTargetPath, minify, rewrite); |
700 | #else | 705 | #else |
701 | return compileFile(fs::absolute(file.first), config, fullWorkPath, fullTargetPath); | 706 | return compileFile(fs::absolute(file.first), config, fullWorkPath, fullTargetPath); |
702 | #endif // YUE_COMPILER_ONLY | 707 | #endif // YUE_COMPILER_ONLY |
703 | }); | 708 | }); |
704 | results.push_back(std::move(task)); | 709 | results.push_back(std::move(task)); |