diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:26 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:56 +0800 |
| commit | e02321107277a63e7dcb12ab163c9942ac101b87 (patch) | |
| tree | f38c6f2fbf4ee35df4938933dbc1e645733356f4 /src | |
| parent | 5d5b657f606b5939062983b1f90c3359d542672e (diff) | |
| download | yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2 yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip | |
Updated tests.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 34 |
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 | ||
| 81 | const std::string_view version = "0.32.4"sv; | 81 | const std::string_view version = "0.32.5"sv; |
| 82 | const std::string_view extension = "yue"sv; | 82 | const std::string_view extension = "yue"sv; |
| 83 | 83 | ||
| 84 | class CompileError : public std::logic_error { | 84 | class 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) { |
