summaryrefslogtreecommitdiff
path: root/src/yue.cpp
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
commitdd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch)
tree0f2de1df55897e2713977c5a53936757e14b477a /src/yue.cpp
parent7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff)
downloadyuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'src/yue.cpp')
-rw-r--r--src/yue.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/yue.cpp b/src/yue.cpp
index ee4eb38..a30075d 100644
--- a/src/yue.cpp
+++ b/src/yue.cpp
@@ -201,8 +201,13 @@ 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 conf.options["path"] = (workPath / "?.lua"sv).string(); 205 if (!it->second.empty()) {
206 it->second += ';';
207 }
208 it->second += (fs::path(workPath) / "?.lua"sv).string();
209 } else {
210 conf.options["path"] = (fs::path(workPath) / "?.lua"sv).string();
206 } 211 }
207 } 212 }
208 auto result = yue::YueCompiler{YUE_ARGS}.compile(s, conf); 213 auto result = yue::YueCompiler{YUE_ARGS}.compile(s, conf);
@@ -852,7 +857,6 @@ int main(int narg, const char** args) {
852 std::list<std::future<std::tuple<int, std::string, std::string>>> results; 857 std::list<std::future<std::tuple<int, std::string, std::string>>> results;
853 for (const auto& file : files) { 858 for (const auto& file : files) {
854 auto task = async<std::tuple<int, std::string, std::string>>([=]() { 859 auto task = async<std::tuple<int, std::string, std::string>>([=]() {
855 try {
856 std::ifstream input(file.first, std::ios::in); 860 std::ifstream input(file.first, std::ios::in);
857 if (input) { 861 if (input) {
858 std::string s( 862 std::string s(
@@ -862,7 +866,12 @@ int main(int narg, const char** args) {
862 conf.module = file.first; 866 conf.module = file.first;
863 if (!workPath.empty()) { 867 if (!workPath.empty()) {
864 auto it = conf.options.find("path"); 868 auto it = conf.options.find("path");
865 if (it == conf.options.end()) { 869 if (it != conf.options.end()) {
870 if (!it->second.empty()) {
871 it->second += ';';
872 }
873 it->second += (fs::path(workPath) / "?.lua"sv).string();
874 } else {
866 conf.options["path"] = (fs::path(workPath) / "?.lua"sv).string(); 875 conf.options["path"] = (fs::path(workPath) / "?.lua"sv).string();
867 } 876 }
868 } 877 }
@@ -942,15 +951,6 @@ int main(int narg, const char** args) {
942 } else { 951 } else {
943 return std::tuple{1, std::string(), "Failed to read file: "s + file.first + '\n'}; 952 return std::tuple{1, std::string(), "Failed to read file: "s + file.first + '\n'};
944 } 953 }
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 }
954 }); 954 });
955 results.push_back(std::move(task)); 955 results.push_back(std::move(task));
956 } 956 }