diff options
-rwxr-xr-x | doc/docs/doc/README.md | 9 | ||||
-rw-r--r-- | spec/inputs/try_catch.yue | 6 | ||||
-rw-r--r-- | spec/outputs/5.1/try_catch.lua | 4 | ||||
-rw-r--r-- | spec/outputs/try_catch.lua | 16 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp | 16 |
5 files changed, 41 insertions, 10 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 92fe435..c237791 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -971,6 +971,7 @@ thing = {1, 2} | |||
971 | print a, b | 971 | print a, b |
972 | ``` | 972 | ``` |
973 | <YueDisplay> | 973 | <YueDisplay> |
974 | |||
974 | <pre> | 975 | <pre> |
975 | thing = {1, 2} | 976 | thing = {1, 2} |
976 | 977 | ||
@@ -1295,7 +1296,7 @@ catch err | |||
1295 | 1296 | ||
1296 | ## Attributes | 1297 | ## Attributes |
1297 | 1298 | ||
1298 | Syntax support for Lua 5.4 attributes. But you can use still use `const` declaration and get constant check working when targeting Lua versions below 5.4. | 1299 | Syntax support for Lua 5.4 attributes. But you can still use `const` declaration and get constant check working when targeting Lua versions below 5.4. |
1299 | 1300 | ||
1300 | ```moonscript | 1301 | ```moonscript |
1301 | const a = 123 | 1302 | const a = 123 |
@@ -2374,6 +2375,9 @@ if a in (0, 11) | |||
2374 | 2375 | ||
2375 | if a in {1, 3, 5, 7} | 2376 | if a in {1, 3, 5, 7} |
2376 | print "checking equality with discrete values" | 2377 | print "checking equality with discrete values" |
2378 | |||
2379 | if a in list | ||
2380 | print "checking if `a` is in a list" | ||
2377 | ``` | 2381 | ``` |
2378 | <YueDisplay> | 2382 | <YueDisplay> |
2379 | <pre> | 2383 | <pre> |
@@ -2390,6 +2394,9 @@ if a in (0, 11) | |||
2390 | 2394 | ||
2391 | if a in {1, 3, 5, 7} | 2395 | if a in {1, 3, 5, 7} |
2392 | print "checking equality with discrete values" | 2396 | print "checking equality with discrete values" |
2397 | |||
2398 | if a in list | ||
2399 | print "checking if `a` is in a list" | ||
2393 | </pre> | 2400 | </pre> |
2394 | </YueDisplay> | 2401 | </YueDisplay> |
2395 | 2402 | ||
diff --git a/spec/inputs/try_catch.yue b/spec/inputs/try_catch.yue index e38cbef..96a87fc 100644 --- a/spec/inputs/try_catch.yue +++ b/spec/inputs/try_catch.yue | |||
@@ -50,5 +50,11 @@ do | |||
50 | catch err | 50 | catch err |
51 | print err | 51 | print err |
52 | 52 | ||
53 | do | ||
54 | try | ||
55 | func 1, 2, 3 | ||
56 | |||
57 | try func 1, 2, 3 | ||
58 | |||
53 | nil | 59 | nil |
54 | 60 | ||
diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua index 577df16..9972dca 100644 --- a/spec/outputs/5.1/try_catch.lua +++ b/spec/outputs/5.1/try_catch.lua | |||
@@ -68,4 +68,8 @@ do | |||
68 | print(result) | 68 | print(result) |
69 | end | 69 | end |
70 | end | 70 | end |
71 | do | ||
72 | pcall(func, 1, 2, 3) | ||
73 | pcall(func, 1, 2, 3) | ||
74 | end | ||
71 | return nil | 75 | return nil |
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua index 129d412..de52c6c 100644 --- a/spec/outputs/try_catch.lua +++ b/spec/outputs/try_catch.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | xpcall(function() | 1 | xpcall(func, function(err) |
2 | return func(1, 2, 3) | ||
3 | end, function(err) | ||
4 | return print(err) | 2 | return print(err) |
5 | end) | 3 | end, 1, 2, 3) |
6 | xpcall(func, function(err) | 4 | xpcall(func, function(err) |
7 | return print(err) | 5 | return print(err) |
8 | end, 1, 2, 3) | 6 | end, 1, 2, 3) |
@@ -11,11 +9,9 @@ pcall(function() | |||
11 | return func(1, 2, 3) | 9 | return func(1, 2, 3) |
12 | end) | 10 | end) |
13 | do | 11 | do |
14 | local success, result = xpcall(function() | 12 | local success, result = xpcall(func, function(err) |
15 | return func(1, 2, 3) | ||
16 | end, function(err) | ||
17 | return print(err) | 13 | return print(err) |
18 | end) | 14 | end, 1, 2, 3) |
19 | success, result = pcall(func, 1, 2, 3) | 15 | success, result = pcall(func, 1, 2, 3) |
20 | end | 16 | end |
21 | pcall(tb.func) | 17 | pcall(tb.func) |
@@ -58,4 +54,8 @@ do | |||
58 | print(result) | 54 | print(result) |
59 | end | 55 | end |
60 | end | 56 | end |
57 | do | ||
58 | pcall(func, 1, 2, 3) | ||
59 | pcall(func, 1, 2, 3) | ||
60 | end | ||
61 | return nil | 61 | return nil |
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>(); |