diff options
author | Li Jin <dragon-fly@qq.com> | 2022-03-05 13:10:12 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-03-05 13:10:12 +0800 |
commit | f48e99462a9fac6b4e5ad1b823b78d263025970c (patch) | |
tree | e2304e75fca79ddf98caf26392e7a7ba8264d1d6 /src | |
parent | 9eb846a1e1e11f7ce2f6b89120b2835af470daa6 (diff) | |
download | yuescript-f48e99462a9fac6b4e5ad1b823b78d263025970c.tar.gz yuescript-f48e99462a9fac6b4e5ad1b823b78d263025970c.tar.bz2 yuescript-f48e99462a9fac6b4e5ad1b823b78d263025970c.zip |
fix issue #82.
Diffstat (limited to 'src')
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
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 | } |