diff options
author | Li Jin <dragon-fly@qq.com> | 2023-07-28 15:54:12 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-07-28 15:54:12 +0800 |
commit | a89680fe48dd1520843d7629e2006f732e313200 (patch) | |
tree | 8be73ac13bf9389e11d0835ed9bff90cc0be4b74 /src | |
parent | 11e855b8124e21beb737ecb4b4e6228e610f572d (diff) | |
download | yuescript-a89680fe48dd1520843d7629e2006f732e313200.tar.gz yuescript-a89680fe48dd1520843d7629e2006f732e313200.tar.bz2 yuescript-a89680fe48dd1520843d7629e2006f732e313200.zip |
made a little optimization for try-catch syntax.
Diffstat (limited to 'src')
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 4d8ed86..ed5e849 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -72,7 +72,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
72 | "close"s // Lua 5.4 | 72 | "close"s // Lua 5.4 |
73 | }; | 73 | }; |
74 | 74 | ||
75 | const std::string_view version = "0.17.12"sv; | 75 | const std::string_view version = "0.17.13"sv; |
76 | const std::string_view extension = "yue"sv; | 76 | const std::string_view extension = "yue"sv; |
77 | 77 | ||
78 | class CompileError : public std::logic_error { | 78 | class CompileError : public std::logic_error { |
@@ -7952,6 +7952,20 @@ private: | |||
7952 | funLit->body.set(body); | 7952 | funLit->body.set(body); |
7953 | } | 7953 | } |
7954 | if (auto tryBlock = tryNode->func.as<Block_t>()) { | 7954 | if (auto tryBlock = tryNode->func.as<Block_t>()) { |
7955 | BLOCK_START | ||
7956 | BREAK_IF(tryBlock->statements.size() != 1); | ||
7957 | auto stmt = static_cast<Statement_t*>(tryBlock->statements.front()); | ||
7958 | auto expListAssign = stmt->content.as<ExpListAssign_t>(); | ||
7959 | BREAK_IF(expListAssign->action); | ||
7960 | auto value = singleValueFrom(expListAssign->expList); | ||
7961 | BREAK_IF(!value); | ||
7962 | auto chainValue = value->item.as<ChainValue_t>(); | ||
7963 | BREAK_IF(!chainValue); | ||
7964 | BREAK_IF(!isChainValueCall(chainValue)); | ||
7965 | tryNode->func.set(expListAssign->expList->exprs.front()); | ||
7966 | BLOCK_END | ||
7967 | } | ||
7968 | if (auto tryBlock = tryNode->func.as<Block_t>()) { | ||
7955 | auto tryExp = toAst<Exp_t>("->"sv, x); | 7969 | auto tryExp = toAst<Exp_t>("->"sv, x); |
7956 | auto funLit = simpleSingleValueFrom(tryExp)->value.to<FunLit_t>(); | 7970 | auto funLit = simpleSingleValueFrom(tryExp)->value.to<FunLit_t>(); |
7957 | auto body = x->new_ptr<Body_t>(); | 7971 | auto body = x->new_ptr<Body_t>(); |