aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuescript/yue_compiler.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index d20b94b..c5e4a78 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -78,7 +78,7 @@ static std::unordered_set<std::string> Metamethods = {
78 "close"s // Lua 5.4 78 "close"s // Lua 5.4
79}; 79};
80 80
81const std::string_view version = "0.32.4"sv; 81const std::string_view version = "0.32.5"sv;
82const std::string_view extension = "yue"sv; 82const std::string_view extension = "yue"sv;
83 83
84class CompileError : public std::logic_error { 84class CompileError : public std::logic_error {
@@ -10226,7 +10226,7 @@ private:
10226 } else if (auto expList = expListFrom(statement)) { 10226 } else if (auto expList = expListFrom(statement)) {
10227 if (auto value = singleValueFrom(expList)) { 10227 if (auto value = singleValueFrom(expList)) {
10228 clsDecl = value->get_by_path<SimpleValue_t, ClassDecl_t>(); 10228 clsDecl = value->get_by_path<SimpleValue_t, ClassDecl_t>();
10229 } 10229 }
10230 } 10230 }
10231 if (clsDecl) { 10231 if (clsDecl) {
10232 auto variable = clsDecl->name.as<Variable_t>(); 10232 auto variable = clsDecl->name.as<Variable_t>();
@@ -10244,10 +10244,18 @@ private:
10244 } 10244 }
10245 _withVars.push(withVar); 10245 _withVars.push(withVar);
10246 std::string breakWithVar; 10246 std::string breakWithVar;
10247 bool extraBreakVar = false;
10247 if (assignList || returnValue) { 10248 if (assignList || returnValue) {
10248 auto breakLoopType = getBreakLoopType(with->body, withVar); 10249 if (assignList) {
10249 if (hasBreakWithValue(breakLoopType)) { 10250 breakWithVar = singleVariableFrom(assignList, AccessType::None);
10250 breakWithVar = withVar; 10251 }
10252 if (breakWithVar.empty()) {
10253 breakWithVar = getUnusedName("_val_"sv);
10254 extraBreakVar = true;
10255 }
10256 auto breakLoopType = getBreakLoopType(with->body, breakWithVar);
10257 if (!hasBreakWithValue(breakLoopType)) {
10258 breakWithVar.clear();
10251 } 10259 }
10252 } 10260 }
10253 if (with->eop) { 10261 if (with->eop) {
@@ -10328,17 +10336,19 @@ private:
10328 } 10336 }
10329 _withVars.pop(); 10337 _withVars.pop();
10330 if (assignList) { 10338 if (assignList) {
10331 auto assignment = x->new_ptr<ExpListAssign_t>(); 10339 if (breakWithVar.empty() || extraBreakVar) {
10332 assignment->expList.set(assignList); 10340 auto assignment = x->new_ptr<ExpListAssign_t>();
10333 auto assign = x->new_ptr<Assign_t>(); 10341 assignment->expList.set(assignList);
10334 assign->values.push_back(toAst<Exp_t>(withVar, x)); 10342 auto assign = x->new_ptr<Assign_t>();
10335 assignment->action.set(assign); 10343 assign->values.push_back(toAst<Exp_t>(breakWithVar.empty() ? withVar : breakWithVar, x));
10336 transformAssignment(assignment, temp); 10344 assignment->action.set(assign);
10345 transformAssignment(assignment, temp);
10346 }
10337 } 10347 }
10338 if (returnValue) { 10348 if (returnValue) {
10339 auto last = lastStatementFrom(with->body); 10349 auto last = lastStatementFrom(with->body);
10340 if (last && !last->content.is<Return_t>()) { 10350 if (last && !last->content.is<Return_t>()) {
10341 temp.push_back(indent() + "return "s + withVar + nl(with)); 10351 temp.push_back(indent() + "return "s + (breakWithVar.empty() ? withVar : breakWithVar) + nl(with));
10342 } 10352 }
10343 } 10353 }
10344 if (extraScope) { 10354 if (extraScope) {