diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
| commit | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch) | |
| tree | ceba95c48bd8d5d9fff3d1206483ddf073c0e03d /src/yue.cpp | |
| parent | e70e63a9737ed3a9e72f1329901075498190e6b4 (diff) | |
| download | yuescript-7c2a92b82e9808d3c5ea29b47d1c59d663fe984a.tar.gz yuescript-7c2a92b82e9808d3c5ea29b47d1c59d663fe984a.tar.bz2 yuescript-7c2a92b82e9808d3c5ea29b47d1c59d663fe984a.zip | |
Add compiler improvements and comprehensive test suitecompiler-improvements
- Fixed path option handling to avoid semicolon concatenation issues
- Added exception handling for std::length_error and general exceptions
- Added comprehensive test specifications for advanced language features
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/yue.cpp')
| -rw-r--r-- | src/yue.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index f48d14b..ee4eb38 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -201,10 +201,7 @@ static std::string compileFile(const fs::path& file, yue::YueConfig conf, const | |||
| 201 | conf.module = modulePath.string(); | 201 | conf.module = modulePath.string(); |
| 202 | if (!workPath.empty()) { | 202 | if (!workPath.empty()) { |
| 203 | auto it = conf.options.find("path"); | 203 | auto it = conf.options.find("path"); |
| 204 | if (it != conf.options.end()) { | 204 | if (it == conf.options.end()) { |
| 205 | it->second += ';'; | ||
| 206 | it->second += (workPath / "?.lua"sv).string(); | ||
| 207 | } else { | ||
| 208 | conf.options["path"] = (workPath / "?.lua"sv).string(); | 205 | conf.options["path"] = (workPath / "?.lua"sv).string(); |
| 209 | } | 206 | } |
| 210 | } | 207 | } |
| @@ -855,6 +852,7 @@ int main(int narg, const char** args) { | |||
| 855 | std::list<std::future<std::tuple<int, std::string, std::string>>> results; | 852 | std::list<std::future<std::tuple<int, std::string, std::string>>> results; |
| 856 | for (const auto& file : files) { | 853 | for (const auto& file : files) { |
| 857 | auto task = async<std::tuple<int, std::string, std::string>>([=]() { | 854 | auto task = async<std::tuple<int, std::string, std::string>>([=]() { |
| 855 | try { | ||
| 858 | std::ifstream input(file.first, std::ios::in); | 856 | std::ifstream input(file.first, std::ios::in); |
| 859 | if (input) { | 857 | if (input) { |
| 860 | std::string s( | 858 | std::string s( |
| @@ -864,10 +862,7 @@ int main(int narg, const char** args) { | |||
| 864 | conf.module = file.first; | 862 | conf.module = file.first; |
| 865 | if (!workPath.empty()) { | 863 | if (!workPath.empty()) { |
| 866 | auto it = conf.options.find("path"); | 864 | auto it = conf.options.find("path"); |
| 867 | if (it != conf.options.end()) { | 865 | if (it == conf.options.end()) { |
| 868 | it->second += ';'; | ||
| 869 | it->second += (fs::path(workPath) / "?.lua"sv).string(); | ||
| 870 | } else { | ||
| 871 | conf.options["path"] = (fs::path(workPath) / "?.lua"sv).string(); | 866 | conf.options["path"] = (fs::path(workPath) / "?.lua"sv).string(); |
| 872 | } | 867 | } |
| 873 | } | 868 | } |
| @@ -947,6 +942,15 @@ int main(int narg, const char** args) { | |||
| 947 | } else { | 942 | } else { |
| 948 | return std::tuple{1, std::string(), "Failed to read file: "s + file.first + '\n'}; | 943 | return std::tuple{1, std::string(), "Failed to read file: "s + file.first + '\n'}; |
| 949 | } | 944 | } |
| 945 | } catch (const std::length_error& e) { | ||
| 946 | std::ostringstream buf; | ||
| 947 | buf << "std::length_error: " << e.what() << " for file: " << file.first << '\n'; | ||
| 948 | return std::tuple{1, std::string(), buf.str()}; | ||
| 949 | } catch (const std::exception& e) { | ||
| 950 | std::ostringstream buf; | ||
| 951 | buf << "Exception: " << e.what() << " for file: " << file.first << '\n'; | ||
| 952 | return std::tuple{1, std::string(), buf.str()}; | ||
| 953 | } | ||
| 950 | }); | 954 | }); |
| 951 | results.push_back(std::move(task)); | 955 | results.push_back(std::move(task)); |
| 952 | } | 956 | } |
