diff options
author | Li Jin <dragon-fly@qq.com> | 2024-02-28 15:57:30 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2024-02-28 15:57:30 +0800 |
commit | 412bc3d7606cb0d07c39861c7ae4e89c7139da31 (patch) | |
tree | 6a60b8f3ad459604dcabe5c5c9cf5a98500ef9f7 /src | |
parent | 27f503ab99f0fb39e2a7df30ad2c970aa53084bd (diff) | |
download | yuescript-412bc3d7606cb0d07c39861c7ae4e89c7139da31.tar.gz yuescript-412bc3d7606cb0d07c39861c7ae4e89c7139da31.tar.bz2 yuescript-412bc3d7606cb0d07c39861c7ae4e89c7139da31.zip |
confirmed only the index/key variable is const in for-loop.v0.22.1
Diffstat (limited to 'src')
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 7a4aa62..0d38fa5 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
76 | }; | 76 | }; |
77 | 77 | ||
78 | const std::string_view version = "0.22.0"sv; | 78 | const std::string_view version = "0.22.1"sv; |
79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
80 | 80 | ||
81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
@@ -6892,7 +6892,8 @@ private: | |||
6892 | auto x = nameList; | 6892 | auto x = nameList; |
6893 | str_list temp; | 6893 | str_list temp; |
6894 | str_list vars; | 6894 | str_list vars; |
6895 | str_list varBefore, varConstAfter, varAfter; | 6895 | str_list varBefore, varAfter; |
6896 | std::string varConstAfter; | ||
6896 | bool extraScope = false; | 6897 | bool extraScope = false; |
6897 | std::list<std::pair<ast_node*, ast_ptr<false, ast_node>>> destructPairs; | 6898 | std::list<std::pair<ast_node*, ast_ptr<false, ast_node>>> destructPairs; |
6898 | for (auto _item : nameList->items.objects()) { | 6899 | for (auto _item : nameList->items.objects()) { |
@@ -6901,7 +6902,9 @@ private: | |||
6901 | case id<Variable_t>(): | 6902 | case id<Variable_t>(): |
6902 | transformVariable(static_cast<Variable_t*>(item), vars); | 6903 | transformVariable(static_cast<Variable_t*>(item), vars); |
6903 | varAfter.push_back(vars.back()); | 6904 | varAfter.push_back(vars.back()); |
6904 | varConstAfter.push_back(vars.back()); | 6905 | if (_item == nameList->items.objects().front()) { |
6906 | varConstAfter = vars.back(); | ||
6907 | } | ||
6905 | break; | 6908 | break; |
6906 | case id<TableLit_t>(): { | 6909 | case id<TableLit_t>(): { |
6907 | auto desVar = getUnusedName("_des_"sv); | 6910 | auto desVar = getUnusedName("_des_"sv); |
@@ -7035,7 +7038,7 @@ private: | |||
7035 | pushScope(); | 7038 | pushScope(); |
7036 | for (const auto& var : vars) forceAddToScope(var); | 7039 | for (const auto& var : vars) forceAddToScope(var); |
7037 | for (const auto& var : varAfter) addToScope(var); | 7040 | for (const auto& var : varAfter) addToScope(var); |
7038 | for (const auto& var : varConstAfter) markVarConst(var); | 7041 | if (!varConstAfter.empty()) markVarConst(varConstAfter); |
7039 | if (!destructPairs.empty()) { | 7042 | if (!destructPairs.empty()) { |
7040 | temp.clear(); | 7043 | temp.clear(); |
7041 | for (auto& pair : destructPairs) { | 7044 | for (auto& pair : destructPairs) { |