diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-11-22 09:53:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-11-22 09:53:46 +0800 |
| commit | 8d36b240cd0800bd5584d52cb5d19d0ae5371357 (patch) | |
| tree | 9016aa87a946851a854452af838ad745e478365e /src/yuescript/yue_compiler.cpp | |
| parent | 1b0bf8554e84bcd4d68dd2131838ea9c923ed694 (diff) | |
| download | yuescript-8d36b240cd0800bd5584d52cb5d19d0ae5371357.tar.gz yuescript-8d36b240cd0800bd5584d52cb5d19d0ae5371357.tar.bz2 yuescript-8d36b240cd0800bd5584d52cb5d19d0ae5371357.zip | |
fix optimization case from issue #115.
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index cf9f188..3e58305 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -60,7 +60,7 @@ namespace yue { | |||
| 60 | 60 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.15.16"sv; | 63 | const std::string_view version = "0.15.17"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
| @@ -8161,7 +8161,32 @@ private: | |||
| 8161 | if (auto simpleVal = simpleSingleValueFrom(value)) { | 8161 | if (auto simpleVal = simpleSingleValueFrom(value)) { |
| 8162 | constVal = ast_is<const_value_t, Num_t>(simpleVal->value); | 8162 | constVal = ast_is<const_value_t, Num_t>(simpleVal->value); |
| 8163 | } | 8163 | } |
| 8164 | if (constVal || !singleVariableFrom(value, false).empty()) { | 8164 | bool localVal = false; |
| 8165 | if (auto var = singleVariableFrom(value, false); isLocal(var)) { | ||
| 8166 | localVal = true; | ||
| 8167 | } | ||
| 8168 | if (!constVal && !localVal) { | ||
| 8169 | for (auto exp : chainAssign->exprs.objects()) { | ||
| 8170 | std::string var = singleVariableFrom(exp, false); | ||
| 8171 | if (!var.empty()) { | ||
| 8172 | str_list temp; | ||
| 8173 | transformAssignment(assignmentFrom(static_cast<Exp_t*>(exp), value, exp), temp); | ||
| 8174 | auto newChainAssign = x->new_ptr<ChainAssign_t>(); | ||
| 8175 | auto newAssign = x->new_ptr<Assign_t>(); | ||
| 8176 | newAssign->values.push_back(exp); | ||
| 8177 | newChainAssign->assign.set(newAssign); | ||
| 8178 | for (auto e : chainAssign->exprs.objects()) { | ||
| 8179 | if (e != exp) { | ||
| 8180 | newChainAssign->exprs.push_back(e); | ||
| 8181 | } | ||
| 8182 | } | ||
| 8183 | transformChainAssign(newChainAssign, temp); | ||
| 8184 | out.push_back(join(temp)); | ||
| 8185 | return; | ||
| 8186 | } | ||
| 8187 | } | ||
| 8188 | } | ||
| 8189 | if (constVal || localVal) { | ||
| 8165 | for (auto exp : chainAssign->exprs.objects()) { | 8190 | for (auto exp : chainAssign->exprs.objects()) { |
| 8166 | transformAssignment(assignmentFrom(static_cast<Exp_t*>(exp), value, exp), temp); | 8191 | transformAssignment(assignmentFrom(static_cast<Exp_t*>(exp), value, exp), temp); |
| 8167 | } | 8192 | } |
