aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdoc/docs/doc/README.md9
-rw-r--r--spec/inputs/try_catch.yue6
-rw-r--r--spec/outputs/5.1/try_catch.lua4
-rw-r--r--spec/outputs/try_catch.lua16
-rw-r--r--src/yuescript/yue_compiler.cpp16
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}
971print a, b 971print a, b
972``` 972```
973<YueDisplay> 973<YueDisplay>
974
974<pre> 975<pre>
975thing = {1, 2} 976thing = {1, 2}
976 977
@@ -1295,7 +1296,7 @@ catch err
1295 1296
1296## Attributes 1297## Attributes
1297 1298
1298Syntax 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. 1299Syntax 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
1301const a = 123 1302const a = 123
@@ -2374,6 +2375,9 @@ if a in (0, 11)
2374 2375
2375if a in {1, 3, 5, 7} 2376if a in {1, 3, 5, 7}
2376 print "checking equality with discrete values" 2377 print "checking equality with discrete values"
2378
2379if 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
2391if a in {1, 3, 5, 7} 2395if a in {1, 3, 5, 7}
2392 print "checking equality with discrete values" 2396 print "checking equality with discrete values"
2397
2398if 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
53do
54 try
55 func 1, 2, 3
56
57 try func 1, 2, 3
58
53nil 59nil
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
70end 70end
71do
72pcall(func, 1, 2, 3)
73pcall(func, 1, 2, 3)
74end
71return nil 75return 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 @@
1xpcall(function() 1xpcall(func, function(err)
2 return func(1, 2, 3)
3end, function(err)
4 return print(err) 2 return print(err)
5end) 3end, 1, 2, 3)
6xpcall(func, function(err) 4xpcall(func, function(err)
7 return print(err) 5 return print(err)
8end, 1, 2, 3) 6end, 1, 2, 3)
@@ -11,11 +9,9 @@ pcall(function()
11 return func(1, 2, 3) 9 return func(1, 2, 3)
12end) 10end)
13do 11do
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)
20end 16end
21pcall(tb.func) 17pcall(tb.func)
@@ -58,4 +54,8 @@ do
58 print(result) 54 print(result)
59 end 55 end
60end 56end
57do
58pcall(func, 1, 2, 3)
59pcall(func, 1, 2, 3)
60end
61return nil 61return 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
75const std::string_view version = "0.17.12"sv; 75const std::string_view version = "0.17.13"sv;
76const std::string_view extension = "yue"sv; 76const std::string_view extension = "yue"sv;
77 77
78class CompileError : public std::logic_error { 78class 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>();