aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-01-05 09:28:28 +0800
committerLi Jin <dragon-fly@qq.com>2021-01-05 09:28:28 +0800
commit6a48f108666126893dcf7ff54b12172795858d3a (patch)
tree1db61493cd9f076149ece7f9a805e29e6232c2d5
parentf641df51ecec17dbd24b476e271a4ee49ed6aded (diff)
downloadyuescript-6a48f108666126893dcf7ff54b12172795858d3a.tar.gz
yuescript-6a48f108666126893dcf7ff54b12172795858d3a.tar.bz2
yuescript-6a48f108666126893dcf7ff54b12172795858d3a.zip
fix.
-rw-r--r--src/MoonP/moon_compiler.cpp36
-rw-r--r--src/MoonP/moonplus.cpp8
2 files changed, 22 insertions, 22 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index 6fdaa3c..73f1407 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -2322,22 +2322,22 @@ private:
2322 pushOptions(macro->m_begin.m_line - 1); // cur loadstring codes chunk options 2322 pushOptions(macro->m_begin.m_line - 1); // cur loadstring codes chunk options
2323 if (lua_pcall(L, 3, 2, 0) != 0) { // loadstring(codes,chunk,options), cur f err 2323 if (lua_pcall(L, 3, 2, 0) != 0) { // loadstring(codes,chunk,options), cur f err
2324 std::string err = lua_tostring(L, -1); 2324 std::string err = lua_tostring(L, -1);
2325 throw std::logic_error(_info.errorMessage(s("fail to load macro codes\n"sv) + err, macro->macroLit)); 2325 throw std::logic_error(_info.errorMessage(s("failed to load macro codes\n"sv) + err, macro->macroLit));
2326 } // cur f err 2326 } // cur f err
2327 if (lua_isnil(L, -2) != 0) { // f == nil, cur f err 2327 if (lua_isnil(L, -2) != 0) { // f == nil, cur f err
2328 std::string err = lua_tostring(L, -1); 2328 std::string err = lua_tostring(L, -1);
2329 throw std::logic_error(_info.errorMessage(s("fail to load macro codes, at (macro "sv) + macroName + s("): "sv) + err, macro->macroLit)); 2329 throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro "sv) + macroName + s("): "sv) + err, macro->macroLit));
2330 } 2330 }
2331 lua_pop(L, 1); // cur f 2331 lua_pop(L, 1); // cur f
2332 pushMoonp("pcall"sv); // cur f pcall 2332 pushMoonp("pcall"sv); // cur f pcall
2333 lua_insert(L, -2); // cur pcall f 2333 lua_insert(L, -2); // cur pcall f
2334 if (lua_pcall(L, 1, 2, 0) != 0) { // f(), cur success macro 2334 if (lua_pcall(L, 1, 2, 0) != 0) { // f(), cur success macro
2335 std::string err = lua_tostring(L, -1); 2335 std::string err = lua_tostring(L, -1);
2336 throw std::logic_error(_info.errorMessage(s("fail to generate macro function\n"sv) + err, macro->macroLit)); 2336 throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, macro->macroLit));
2337 } // cur success res 2337 } // cur success res
2338 if (lua_toboolean(L, -2) == 0) { 2338 if (lua_toboolean(L, -2) == 0) {
2339 std::string err = lua_tostring(L, -1); 2339 std::string err = lua_tostring(L, -1);
2340 throw std::logic_error(_info.errorMessage(s("fail to generate macro function\n"sv) + err, macro->macroLit)); 2340 throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, macro->macroLit));
2341 } // cur true macro 2341 } // cur true macro
2342 lua_remove(L, -2); // cur macro 2342 lua_remove(L, -2); // cur macro
2343 if (exporting && !_moduleName.empty()) { 2343 if (exporting && !_moduleName.empty()) {
@@ -3092,22 +3092,22 @@ private:
3092 pushOptions(args->back()->m_begin.m_line - 1); // loadstring codes chunk options 3092 pushOptions(args->back()->m_begin.m_line - 1); // loadstring codes chunk options
3093 if (lua_pcall(L, 3, 2, 0) != 0) { // loadstring(codes,chunk,options), f err 3093 if (lua_pcall(L, 3, 2, 0) != 0) { // loadstring(codes,chunk,options), f err
3094 std::string err = lua_tostring(L, -1); 3094 std::string err = lua_tostring(L, -1);
3095 throw std::logic_error(_info.errorMessage(s("fail to load macro codes\n"sv) + err, x)); 3095 throw std::logic_error(_info.errorMessage(s("failed to load macro codes\n"sv) + err, x));
3096 } // f err 3096 } // f err
3097 if (lua_isnil(L, -2) != 0) { // f == nil, f err 3097 if (lua_isnil(L, -2) != 0) { // f == nil, f err
3098 std::string err = lua_tostring(L, -1); 3098 std::string err = lua_tostring(L, -1);
3099 throw std::logic_error(_info.errorMessage(s("fail to load macro codes, at (macro in-place): "sv) + err, x)); 3099 throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro in-place): "sv) + err, x));
3100 } 3100 }
3101 lua_pop(L, 1); // f 3101 lua_pop(L, 1); // f
3102 pushMoonp("pcall"sv); // f pcall 3102 pushMoonp("pcall"sv); // f pcall
3103 lua_insert(L, -2); // pcall f 3103 lua_insert(L, -2); // pcall f
3104 if (lua_pcall(L, 1, 2, 0) != 0) { // f(), success macroFunc 3104 if (lua_pcall(L, 1, 2, 0) != 0) { // f(), success macroFunc
3105 std::string err = lua_tostring(L, -1); 3105 std::string err = lua_tostring(L, -1);
3106 throw std::logic_error(_info.errorMessage(s("fail to generate macro function\n"sv) + err, x)); 3106 throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, x));
3107 } // success res 3107 } // success res
3108 if (lua_toboolean(L, -2) == 0) { 3108 if (lua_toboolean(L, -2) == 0) {
3109 std::string err = lua_tostring(L, -1); 3109 std::string err = lua_tostring(L, -1);
3110 throw std::logic_error(_info.errorMessage(s("fail to generate macro function\n"sv) + err, x)); 3110 throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, x));
3111 } // true macroFunc 3111 } // true macroFunc
3112 lua_remove(L, -2); // macroFunc 3112 lua_remove(L, -2); // macroFunc
3113 pushMoonp("pcall"sv); // macroFunc pcall 3113 pushMoonp("pcall"sv); // macroFunc pcall
@@ -3115,11 +3115,11 @@ private:
3115 bool success = lua_pcall(L, 1, 2, 0) == 0; 3115 bool success = lua_pcall(L, 1, 2, 0) == 0;
3116 if (!success) { // err 3116 if (!success) { // err
3117 std::string err = lua_tostring(L, -1); 3117 std::string err = lua_tostring(L, -1);
3118 throw std::logic_error(_info.errorMessage(s("fail to expand macro: "sv) + err, x)); 3118 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3119 } // success err 3119 } // success err
3120 if (lua_toboolean(L, -2) == 0) { 3120 if (lua_toboolean(L, -2) == 0) {
3121 std::string err = lua_tostring(L, -1); 3121 std::string err = lua_tostring(L, -1);
3122 throw std::logic_error(_info.errorMessage(s("fail to expand macro: "sv) + err, x)); 3122 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3123 } 3123 }
3124 return {s("block"sv), Empty, {}}; 3124 return {s("block"sv), Empty, {}};
3125 } 3125 }
@@ -3183,11 +3183,11 @@ private:
3183 bool success = lua_pcall(L, static_cast<int>(args->size()) + 1, 3, 0) == 0; 3183 bool success = lua_pcall(L, static_cast<int>(args->size()) + 1, 3, 0) == 0;
3184 if (!success) { // cur macro err 3184 if (!success) { // cur macro err
3185 std::string err = lua_tostring(L, -1); 3185 std::string err = lua_tostring(L, -1);
3186 throw std::logic_error(_info.errorMessage(s("fail to expand macro: "sv) + err, x)); 3186 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3187 } // cur macro success res option 3187 } // cur macro success res option
3188 if (lua_toboolean(L, -3) == 0) { 3188 if (lua_toboolean(L, -3) == 0) {
3189 std::string err = lua_tostring(L, -2); 3189 std::string err = lua_tostring(L, -2);
3190 throw std::logic_error(_info.errorMessage(s("fail to expand macro: "sv) + err, x)); 3190 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3191 } 3191 }
3192 lua_remove(L, -3); // cur macro res option 3192 lua_remove(L, -3); // cur macro res option
3193 if (lua_isstring(L, -2) == 0) { 3193 if (lua_isstring(L, -2) == 0) {
@@ -3271,7 +3271,7 @@ private:
3271 } 3271 }
3272 if (!info.node) { 3272 if (!info.node) {
3273 info.error = info.error.substr(info.error.find(':') + 2); 3273 info.error = info.error.substr(info.error.find(':') + 2);
3274 throw std::logic_error(_info.errorMessage("fail to parse expanded codes: " + info.error, x)); 3274 throw std::logic_error(_info.errorMessage("failed to parse expanded codes: " + info.error, x));
3275 } 3275 }
3276 int line = x->m_begin.m_line; 3276 int line = x->m_begin.m_line;
3277 int col = x->m_begin.m_col; 3277 int col = x->m_begin.m_col;
@@ -5079,10 +5079,10 @@ private:
5079 lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName 5079 lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName
5080 if (lua_pcall(L, 1, 1, 0) != 0) { 5080 if (lua_pcall(L, 1, 1, 0) != 0) {
5081 std::string err = lua_tostring(L, -1); 5081 std::string err = lua_tostring(L, -1);
5082 throw std::logic_error(_info.errorMessage(s("fail to resolve module path\n"sv) + err, x)); 5082 throw std::logic_error(_info.errorMessage(s("failed to resolve module path\n"sv) + err, x));
5083 } 5083 }
5084 if (lua_isnil(L, -1) != 0) { 5084 if (lua_isnil(L, -1) != 0) {
5085 throw std::logic_error(_info.errorMessage(s("fail to find module '"sv) + moduleName + '\'', x)); 5085 throw std::logic_error(_info.errorMessage(s("failed to find module '"sv) + moduleName + '\'', x));
5086 } 5086 }
5087 std::string moduleFullName = lua_tostring(L, -1); 5087 std::string moduleFullName = lua_tostring(L, -1);
5088 lua_pop(L, 1); // cur 5088 lua_pop(L, 1); // cur
@@ -5091,10 +5091,10 @@ private:
5091 lua_pushlstring(L, moduleFullName.c_str(), moduleFullName.size()); // cur load_text moduleFullName 5091 lua_pushlstring(L, moduleFullName.c_str(), moduleFullName.size()); // cur load_text moduleFullName
5092 if (lua_pcall(L, 1, 1, 0) != 0) { 5092 if (lua_pcall(L, 1, 1, 0) != 0) {
5093 std::string err = lua_tostring(L, -1); 5093 std::string err = lua_tostring(L, -1);
5094 throw std::logic_error(_info.errorMessage(s("fail to read module file\n"sv) + err, x)); 5094 throw std::logic_error(_info.errorMessage(s("failed to read module file\n"sv) + err, x));
5095 } // cur text 5095 } // cur text
5096 if (lua_isnil(L, -1) != 0) { 5096 if (lua_isnil(L, -1) != 0) {
5097 throw std::logic_error(_info.errorMessage("fail to get module text"sv, x)); 5097 throw std::logic_error(_info.errorMessage("failed to get module text"sv, x));
5098 } // cur text 5098 } // cur text
5099 std::string text = lua_tostring(L, -1); 5099 std::string text = lua_tostring(L, -1);
5100 auto compiler = MoonCompilerImpl(L, _luaOpen, false, moduleFullName); 5100 auto compiler = MoonCompilerImpl(L, _luaOpen, false, moduleFullName);
@@ -5105,7 +5105,7 @@ private:
5105 config.implicitReturnRoot = _config.implicitReturnRoot; 5105 config.implicitReturnRoot = _config.implicitReturnRoot;
5106 auto result = compiler.compile(text, config); 5106 auto result = compiler.compile(text, config);
5107 if (result.codes.empty() && !result.error.empty()) { 5107 if (result.codes.empty() && !result.error.empty()) {
5108 throw std::logic_error(_info.errorMessage(s("fail to compile module '"sv) + moduleName + s("\': "sv) + result.error, x)); 5108 throw std::logic_error(_info.errorMessage(s("failed to compile module '"sv) + moduleName + s("\': "sv) + result.error, x));
5109 } 5109 }
5110 lua_pop(L, 1); // cur 5110 lua_pop(L, 1); // cur
5111 } 5111 }
diff --git a/src/MoonP/moonplus.cpp b/src/MoonP/moonplus.cpp
index bea1d6e..47de01c 100644
--- a/src/MoonP/moonplus.cpp
+++ b/src/MoonP/moonplus.cpp
@@ -17,10 +17,10 @@ static const char moonplusCodes[] =
17 17
18static void init_moonplus(lua_State* L) { 18static void init_moonplus(lua_State* L) {
19 if (luaL_loadbuffer(L, moonplusCodes, sizeof(moonplusCodes) / sizeof(moonplusCodes[0]) - 1, "=(moonplus)") != 0) { 19 if (luaL_loadbuffer(L, moonplusCodes, sizeof(moonplusCodes) / sizeof(moonplusCodes[0]) - 1, "=(moonplus)") != 0) {
20 std::string err = std::string("fail to load moonplus module.\n") + lua_tostring(L, -1); 20 std::string err = std::string("failed to load moonplus module.\n") + lua_tostring(L, -1);
21 luaL_error(L, err.c_str()); 21 luaL_error(L, err.c_str());
22 } else if (lua_pcall(L, 0, 0, 0) != 0) { 22 } else if (lua_pcall(L, 0, 0, 0) != 0) {
23 std::string err = std::string("fail to init moonplus module.\n") + lua_tostring(L, -1); 23 std::string err = std::string("failed to init moonplus module.\n") + lua_tostring(L, -1);
24 luaL_error(L, err.c_str()); 24 luaL_error(L, err.c_str());
25 } 25 }
26} 26}
@@ -30,10 +30,10 @@ static const char stpCodes[] =
30 30
31static int init_stacktraceplus(lua_State* L) { 31static int init_stacktraceplus(lua_State* L) {
32 if (luaL_loadbuffer(L, stpCodes, sizeof(stpCodes) / sizeof(stpCodes[0]) - 1, "=(stacktraceplus)") != 0) { 32 if (luaL_loadbuffer(L, stpCodes, sizeof(stpCodes) / sizeof(stpCodes[0]) - 1, "=(stacktraceplus)") != 0) {
33 std::string err = std::string("fail to load stacktraceplus module.\n") + lua_tostring(L, -1); 33 std::string err = std::string("failed to load stacktraceplus module.\n") + lua_tostring(L, -1);
34 luaL_error(L, err.c_str()); 34 luaL_error(L, err.c_str());
35 } else if (lua_pcall(L, 0, 1, 0) != 0) { 35 } else if (lua_pcall(L, 0, 1, 0) != 0) {
36 std::string err = std::string("fail to init stacktraceplus module.\n") + lua_tostring(L, -1); 36 std::string err = std::string("failed to init stacktraceplus module.\n") + lua_tostring(L, -1);
37 luaL_error(L, err.c_str()); 37 luaL_error(L, err.c_str());
38 } 38 }
39 return 1; 39 return 1;