aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-11-14 23:31:36 +0800
committerLi Jin <dragon-fly@qq.com>2025-11-14 23:31:36 +0800
commit2dc2aa85990c3e334765138e76e11b94d9ed73d1 (patch)
tree8bfe3b64a1770c03b91e1205ca3987c73d3e31f3 /src
parent69f896ca6960419133bf9a5ecc231f7aa934ac56 (diff)
downloadyuescript-2dc2aa85990c3e334765138e76e11b94d9ed73d1.tar.gz
yuescript-2dc2aa85990c3e334765138e76e11b94d9ed73d1.tar.bz2
yuescript-2dc2aa85990c3e334765138e76e11b94d9ed73d1.zip
Fixed code generating.v0.29.8
Diffstat (limited to 'src')
-rw-r--r--src/yuescript/yue_compiler.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 8c28e61..d6db3fc 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -8317,9 +8317,12 @@ private:
8317 auto compInner = static_cast<CompInner_t*>(comp->items.back()); 8317 auto compInner = static_cast<CompInner_t*>(comp->items.back());
8318 str_list temp; 8318 str_list temp;
8319 std::string accumVar = getUnusedName("_accum_"sv); 8319 std::string accumVar = getUnusedName("_accum_"sv);
8320 std::string lenVar = getUnusedName("_len_"sv);
8321 addToScope(accumVar); 8320 addToScope(accumVar);
8322 addToScope(lenVar); 8321 std::string lenVar;
8322 if (!isSpread) {
8323 lenVar = getUnusedName("_len_"sv);
8324 addToScope(lenVar);
8325 }
8323 for (auto item : compInner->items.objects()) { 8326 for (auto item : compInner->items.objects()) {
8324 switch (item->get_id()) { 8327 switch (item->get_id()) {
8325 case id<CompForEach_t>(): 8328 case id<CompForEach_t>():
@@ -8337,7 +8340,7 @@ private:
8337 } 8340 }
8338 } 8341 }
8339 { 8342 {
8340 auto assignLeft = toAst<ExpList_t>(accumVar + '[' + lenVar + (isSpread ? "][]"s : "]"s), x); 8343 auto assignLeft = toAst<ExpList_t>(accumVar + '[' + (isSpread ? "]"s : lenVar + ']'), x);
8341 auto assign = x->new_ptr<Assign_t>(); 8344 auto assign = x->new_ptr<Assign_t>();
8342 assign->values.push_back(value); 8345 assign->values.push_back(value);
8343 auto assignment = x->new_ptr<ExpListAssign_t>(); 8346 auto assignment = x->new_ptr<ExpListAssign_t>();
@@ -8351,10 +8354,15 @@ private:
8351 popScope(); 8354 popScope();
8352 } 8355 }
8353 _buf << indent() << "local "sv << accumVar << " = { }"sv << nll(comp); 8356 _buf << indent() << "local "sv << accumVar << " = { }"sv << nll(comp);
8354 _buf << indent() << "local "sv << lenVar << " = 1"sv << nll(comp); 8357 if (isSpread) {
8355 _buf << join(temp); 8358 _buf << join(temp);
8356 _buf << assignStr; 8359 _buf << assignStr;
8357 _buf << indent(int(temp.size())) << lenVar << " = "sv << lenVar << " + 1"sv << nll(comp); 8360 } else {
8361 _buf << indent() << "local "sv << lenVar << " = 1"sv << nll(comp);
8362 _buf << join(temp);
8363 _buf << assignStr;
8364 _buf << indent(int(temp.size())) << lenVar << " = "sv << lenVar << " + 1"sv << nll(comp);
8365 }
8358 for (int ind = int(temp.size()) - 1; ind > -1; --ind) { 8366 for (int ind = int(temp.size()) - 1; ind > -1; --ind) {
8359 _buf << indent(ind) << "end"sv << nll(comp); 8367 _buf << indent(ind) << "end"sv << nll(comp);
8360 } 8368 }