diff options
| -rw-r--r-- | spec/outputs/loops.lua | 16 | ||||
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 23 |
2 files changed, 30 insertions, 9 deletions
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua index a905e4e..aa69840 100644 --- a/spec/outputs/loops.lua +++ b/spec/outputs/loops.lua | |||
| @@ -171,11 +171,13 @@ for i = 1, 10 do | |||
| 171 | while true do | 171 | while true do |
| 172 | local _continue_0 = false | 172 | local _continue_0 = false |
| 173 | repeat | 173 | repeat |
| 174 | if not true then | 174 | do |
| 175 | _continue_0 = true | 175 | if not true then |
| 176 | _continue_0 = true | ||
| 177 | break | ||
| 178 | end | ||
| 176 | break | 179 | break |
| 177 | end | 180 | end |
| 178 | break | ||
| 179 | _continue_0 = true | 181 | _continue_0 = true |
| 180 | until true | 182 | until true |
| 181 | if not _continue_0 then | 183 | if not _continue_0 then |
| @@ -313,11 +315,13 @@ end | |||
| 313 | while true do | 315 | while true do |
| 314 | local _continue_0 = false | 316 | local _continue_0 = false |
| 315 | repeat | 317 | repeat |
| 316 | if false then | 318 | do |
| 317 | _continue_0 = true | 319 | if false then |
| 320 | _continue_0 = true | ||
| 321 | break | ||
| 322 | end | ||
| 318 | break | 323 | break |
| 319 | end | 324 | end |
| 320 | break | ||
| 321 | _continue_0 = true | 325 | _continue_0 = true |
| 322 | until true | 326 | until true |
| 323 | if not _continue_0 then | 327 | if not _continue_0 then |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6ae4771..45d7820 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -60,7 +60,7 @@ using namespace parserlib; | |||
| 60 | 60 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.10.4"sv; | 63 | const std::string_view version = "0.10.5"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class YueCompilerImpl { |
| @@ -4844,17 +4844,34 @@ private: | |||
| 4844 | } | 4844 | } |
| 4845 | return traversal::Continue; | 4845 | return traversal::Continue; |
| 4846 | }); | 4846 | }); |
| 4847 | bool extraDo = false; | ||
| 4847 | if (withContinue) { | 4848 | if (withContinue) { |
| 4849 | if (auto block = ast_cast<Block_t>(body)) { | ||
| 4850 | if (!block->statements.empty()) { | ||
| 4851 | auto stmt = static_cast<Statement_t*>(block->statements.back()); | ||
| 4852 | if (auto breakLoop = ast_cast<BreakLoop_t>(stmt->content)) { | ||
| 4853 | extraDo = _parser.toString(breakLoop) == "break"sv; | ||
| 4854 | } | ||
| 4855 | } | ||
| 4856 | } | ||
| 4848 | auto continueVar = getUnusedName("_continue_"sv); | 4857 | auto continueVar = getUnusedName("_continue_"sv); |
| 4849 | addToScope(continueVar); | 4858 | addToScope(continueVar); |
| 4859 | _continueVars.push(continueVar); | ||
| 4850 | _buf << indent() << "local "sv << continueVar << " = false"sv << nll(body); | 4860 | _buf << indent() << "local "sv << continueVar << " = false"sv << nll(body); |
| 4851 | _buf << indent() << "repeat"sv << nll(body); | 4861 | _buf << indent() << "repeat"sv << nll(body); |
| 4852 | temp.push_back(clearBuf()); | ||
| 4853 | _continueVars.push(continueVar); | ||
| 4854 | pushScope(); | 4862 | pushScope(); |
| 4863 | if (extraDo) { | ||
| 4864 | _buf << indent() << "do"sv << nll(body); | ||
| 4865 | pushScope(); | ||
| 4866 | } | ||
| 4867 | temp.push_back(clearBuf()); | ||
| 4855 | } | 4868 | } |
| 4856 | transform_plain_body(body, temp, usage, assignList); | 4869 | transform_plain_body(body, temp, usage, assignList); |
| 4857 | if (withContinue) { | 4870 | if (withContinue) { |
| 4871 | if (extraDo) { | ||
| 4872 | popScope(); | ||
| 4873 | _buf << indent() << "end"sv << nll(body); | ||
| 4874 | } | ||
| 4858 | if (!appendContent.empty()) { | 4875 | if (!appendContent.empty()) { |
| 4859 | _buf << indent() << appendContent; | 4876 | _buf << indent() << appendContent; |
| 4860 | } | 4877 | } |
