diff options
author | Li Jin <dragon-fly@qq.com> | 2023-11-09 18:30:16 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-11-09 18:30:16 +0800 |
commit | 0ca14d8e6c37f5d1360178034851f36c636a7a43 (patch) | |
tree | 415c0b6083054fe837d0afb458bdd62dac778b84 /src/yuescript/yue_compiler.cpp | |
parent | 5ad0f4daa8171460dc71332669c365bb8e07dab0 (diff) | |
download | yuescript-0ca14d8e6c37f5d1360178034851f36c636a7a43.tar.gz yuescript-0ca14d8e6c37f5d1360178034851f36c636a7a43.tar.bz2 yuescript-0ca14d8e6c37f5d1360178034851f36c636a7a43.zip |
fix a missing case for condition chaining.v0.20.5
Diffstat (limited to '')
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 1733967..7fdf45e 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.20.4"sv; | 78 | const std::string_view version = "0.20.5"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 { |
@@ -1042,7 +1042,7 @@ private: | |||
1042 | for (auto it = uname->m_begin.m_it; it != uname->m_end.m_it; ++it) { | 1042 | for (auto it = uname->m_begin.m_it; it != uname->m_end.m_it; ++it) { |
1043 | auto ch = *it; | 1043 | auto ch = *it; |
1044 | if (ch > 255) { | 1044 | if (ch > 255) { |
1045 | buf << "_u"sv << std::hex << ch; | 1045 | buf << "_u"sv << std::hex << static_cast<int>(ch); |
1046 | } else { | 1046 | } else { |
1047 | buf << static_cast<char>(ch); | 1047 | buf << static_cast<char>(ch); |
1048 | } | 1048 | } |
@@ -3438,25 +3438,10 @@ private: | |||
3438 | ifCond->condition.set(condExp); | 3438 | ifCond->condition.set(condExp); |
3439 | ifNode->nodes.push_back(ifCond); | 3439 | ifNode->nodes.push_back(ifCond); |
3440 | ifNode->nodes.push_back(toAst<Statement_t>("false"sv, exp)); | 3440 | ifNode->nodes.push_back(toAst<Statement_t>("false"sv, exp)); |
3441 | YueFormat format{}; | ||
3442 | auto code = ifNode->to_string(&format); | ||
3441 | if (newCondExp) { | 3443 | if (newCondExp) { |
3442 | if (nodes) { | 3444 | if (!nodes) { |
3443 | auto block = exp->new_ptr<Block_t>(); | ||
3444 | auto stmt = exp->new_ptr<Statement_t>(); | ||
3445 | stmt->content.set(preDefine); | ||
3446 | preDefine.set(nullptr); | ||
3447 | block->statements.push_back(stmt); | ||
3448 | auto simpleValue = exp->new_ptr<SimpleValue_t>(); | ||
3449 | simpleValue->value.set(ifNode); | ||
3450 | auto explist = exp->new_ptr<ExpList_t>(); | ||
3451 | explist->exprs.push_back(newExp(simpleValue, exp)); | ||
3452 | auto expListAssign = exp->new_ptr<ExpListAssign_t>(); | ||
3453 | expListAssign->expList.set(explist); | ||
3454 | stmt = exp->new_ptr<Statement_t>(); | ||
3455 | stmt->content.set(expListAssign); | ||
3456 | block->statements.push_back(stmt); | ||
3457 | nodes->push_back(block); | ||
3458 | nodes = &ifNode->nodes; | ||
3459 | } else { | ||
3460 | auto ifNodePrev = exp->new_ptr<If_t>(); | 3445 | auto ifNodePrev = exp->new_ptr<If_t>(); |
3461 | ifNodePrev->type.set(toAst<IfType_t>("unless"sv, exp)); | 3446 | ifNodePrev->type.set(toAst<IfType_t>("unless"sv, exp)); |
3462 | auto ifCondPrev = exp->new_ptr<IfCond_t>(); | 3447 | auto ifCondPrev = exp->new_ptr<IfCond_t>(); |
@@ -3468,6 +3453,22 @@ private: | |||
3468 | newCondExp.set(newExp(simpleValue, exp)); | 3453 | newCondExp.set(newExp(simpleValue, exp)); |
3469 | nodes = &ifNodePrev->nodes; | 3454 | nodes = &ifNodePrev->nodes; |
3470 | } | 3455 | } |
3456 | auto block = exp->new_ptr<Block_t>(); | ||
3457 | auto stmt = exp->new_ptr<Statement_t>(); | ||
3458 | stmt->content.set(preDefine); | ||
3459 | preDefine.set(nullptr); | ||
3460 | block->statements.push_back(stmt); | ||
3461 | auto simpleValue = exp->new_ptr<SimpleValue_t>(); | ||
3462 | simpleValue->value.set(ifNode); | ||
3463 | auto explist = exp->new_ptr<ExpList_t>(); | ||
3464 | explist->exprs.push_back(newExp(simpleValue, exp)); | ||
3465 | auto expListAssign = exp->new_ptr<ExpListAssign_t>(); | ||
3466 | expListAssign->expList.set(explist); | ||
3467 | stmt = exp->new_ptr<Statement_t>(); | ||
3468 | stmt->content.set(expListAssign); | ||
3469 | block->statements.push_back(stmt); | ||
3470 | nodes->push_back(block); | ||
3471 | nodes = &ifNode->nodes; | ||
3471 | } else { | 3472 | } else { |
3472 | auto block = exp->new_ptr<Block_t>(); | 3473 | auto block = exp->new_ptr<Block_t>(); |
3473 | auto stmt = exp->new_ptr<Statement_t>(); | 3474 | auto stmt = exp->new_ptr<Statement_t>(); |
@@ -9175,17 +9176,17 @@ private: | |||
9175 | pushScope(); | 9176 | pushScope(); |
9176 | extraScope = true; | 9177 | extraScope = true; |
9177 | } | 9178 | } |
9178 | auto typeVar = getUnusedName("_type_"); | 9179 | auto typeVar = getUnusedName("_type_"sv); |
9179 | forceAddToScope(typeVar); | 9180 | forceAddToScope(typeVar); |
9180 | tabCheckVar = getUnusedName("_tab_"); | 9181 | tabCheckVar = getUnusedName("_tab_"sv); |
9181 | forceAddToScope(tabCheckVar); | 9182 | forceAddToScope(tabCheckVar); |
9182 | temp.push_back(indent() + "local "s + typeVar + " = "s + globalVar("type", branch) + '(' + objVar + ')' + nll(branch)); | 9183 | temp.push_back(indent() + "local "s + typeVar + " = "s + globalVar("type"sv, branch) + '(' + objVar + ')' + nll(branch)); |
9183 | temp.push_back(indent() + "local "s + tabCheckVar + " = \"table\" == "s + typeVar + " or \"userdata\" == "s + typeVar + nll(branch)); | 9184 | temp.push_back(indent() + "local "s + tabCheckVar + " = \"table\" == "s + typeVar + " or \"userdata\" == "s + typeVar + nll(branch)); |
9184 | } | 9185 | } |
9185 | std::string matchVar; | 9186 | std::string matchVar; |
9186 | bool lastBranch = branches.back() == branch_ && !switchNode->lastBranch; | 9187 | bool lastBranch = branches.back() == branch_ && !switchNode->lastBranch; |
9187 | if (!lastBranch) { | 9188 | if (!lastBranch) { |
9188 | matchVar = getUnusedName("_match_"); | 9189 | matchVar = getUnusedName("_match_"sv); |
9189 | forceAddToScope(matchVar); | 9190 | forceAddToScope(matchVar); |
9190 | temp.push_back(indent() + "local "s + matchVar + " = false"s + nll(branch)); | 9191 | temp.push_back(indent() + "local "s + matchVar + " = false"s + nll(branch)); |
9191 | } | 9192 | } |