aboutsummaryrefslogtreecommitdiff
path: root/src/yuescript/yue_compiler.cpp
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-12-07 23:49:48 +0800
committerLi Jin <dragon-fly@qq.com>2023-12-07 23:55:16 +0800
commit514b9f97febe8920a78d6078b092fe84b859a963 (patch)
tree8c76ba7579f69db7e2c899e4713009b910e0fa89 /src/yuescript/yue_compiler.cpp
parenta1d719e3bbfe8cd39c05d2a8f49143b9e814f876 (diff)
downloadyuescript-514b9f97febe8920a78d6078b092fe84b859a963.tar.gz
yuescript-514b9f97febe8920a78d6078b092fe84b859a963.tar.bz2
yuescript-514b9f97febe8920a78d6078b092fe84b859a963.zip
changed the if-assignment syntax to prevent some errors.v0.21.0
Diffstat (limited to '')
-rw-r--r--src/yuescript/yue_compiler.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 69a028f..d37f911 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
78const std::string_view version = "0.20.7"sv; 78const std::string_view version = "0.21.0"sv;
79const std::string_view extension = "yue"sv; 79const std::string_view extension = "yue"sv;
80 80
81class CompileError : public std::logic_error { 81class CompileError : public std::logic_error {
@@ -3088,7 +3088,7 @@ private:
3088 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { 3088 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) {
3089 ns.push_back(*it); 3089 ns.push_back(*it);
3090 if (auto cond = ast_cast<IfCond_t>(*it)) { 3090 if (auto cond = ast_cast<IfCond_t>(*it)) {
3091 if (*it != nodes.front() && cond->condition.is<Assignment_t>()) { 3091 if (*it != nodes.front() && cond->assignment) {
3092 auto x = *it; 3092 auto x = *it;
3093 auto newIf = x->new_ptr<If_t>(); 3093 auto newIf = x->new_ptr<If_t>();
3094 newIf->type.set(toAst<IfType_t>("if"sv, x)); 3094 newIf->type.set(toAst<IfType_t>("if"sv, x));
@@ -3142,11 +3142,12 @@ private:
3142 default: YUEE("AST node mismatch", node); break; 3142 default: YUEE("AST node mismatch", node); break;
3143 } 3143 }
3144 } 3144 }
3145 auto asmt = ifCondPairs.front().first->condition.as<Assignment_t>(); 3145 auto firstIfCond = ifCondPairs.front().first;
3146 auto asmt = firstIfCond->assignment.get();
3146 bool storingValue = false; 3147 bool storingValue = false;
3147 ast_ptr<false, ExpListAssign_t> extraAssignment; 3148 ast_ptr<false, ExpListAssign_t> extraAssignment;
3148 if (asmt) { 3149 if (asmt) {
3149 ast_ptr<false, ast_node> exp = asmt->expList->exprs.front(); 3150 auto exp = firstIfCond->condition.get();
3150 auto x = exp; 3151 auto x = exp;
3151 auto var = singleVariableFrom(exp, false); 3152 auto var = singleVariableFrom(exp, false);
3152 if (var.empty() || isGlobal(var)) { 3153 if (var.empty() || isGlobal(var)) {
@@ -3164,11 +3165,12 @@ private:
3164 temp.push_back(indent() + "do"s + nll(asmt)); 3165 temp.push_back(indent() + "do"s + nll(asmt));
3165 pushScope(); 3166 pushScope();
3166 } 3167 }
3167 asmt->expList->exprs.pop_front();
3168 auto expList = toAst<ExpList_t>(desVar, x); 3168 auto expList = toAst<ExpList_t>(desVar, x);
3169 auto assignment = x->new_ptr<ExpListAssign_t>(); 3169 auto assignment = x->new_ptr<ExpListAssign_t>();
3170 for (auto expr : asmt->expList->exprs.objects()) { 3170 if (asmt->expList) {
3171 expList->exprs.push_back(expr); 3171 for (auto expr : asmt->expList->exprs.objects()) {
3172 expList->exprs.push_back(expr);
3173 }
3172 } 3174 }
3173 assignment->expList.set(expList); 3175 assignment->expList.set(expList);
3174 assignment->action.set(asmt->assign); 3176 assignment->action.set(asmt->assign);
@@ -3196,9 +3198,10 @@ private:
3196 } 3198 }
3197 auto expList = x->new_ptr<ExpList_t>(); 3199 auto expList = x->new_ptr<ExpList_t>();
3198 expList->exprs.push_back(exp); 3200 expList->exprs.push_back(exp);
3199 asmt->expList->exprs.pop_front(); 3201 if (asmt->expList) {
3200 for (auto expr : asmt->expList->exprs.objects()) { 3202 for (auto expr : asmt->expList->exprs.objects()) {
3201 expList->exprs.push_back(expr); 3203 expList->exprs.push_back(expr);
3204 }
3202 } 3205 }
3203 auto assignment = x->new_ptr<ExpListAssign_t>(); 3206 auto assignment = x->new_ptr<ExpListAssign_t>();
3204 assignment->expList.set(expList); 3207 assignment->expList.set(expList);