aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2025-04-11 17:33:12 +0800
committerLi Jin <dragon-fly@qq.com>2025-04-11 17:33:12 +0800
commite96308912e2e04535836a2c282b0a7300d2d81fd (patch)
tree9c6f55dbce6193dac6f78dad94f76ad1c0a6ef1a
parent9750786a5c03b5ce3ea22b240d1b3cd34990856b (diff)
downloadyuescript-0.27.4.tar.gz
yuescript-0.27.4.tar.bz2
yuescript-0.27.4.zip
Fixing issue #206.v0.27.4
-rw-r--r--spec/outputs/5.1/attrib.lua18
-rw-r--r--spec/outputs/5.1/try_catch.lua6
-rw-r--r--spec/outputs/assign.lua6
-rw-r--r--spec/outputs/attrib.lua18
-rw-r--r--spec/outputs/do.lua6
-rw-r--r--spec/outputs/syntax.lua8
-rw-r--r--spec/outputs/try_catch.lua6
-rw-r--r--spec/outputs/unicode/assign.lua6
-rw-r--r--spec/outputs/unicode/attrib.lua18
-rw-r--r--spec/outputs/unicode/do.lua6
-rw-r--r--spec/outputs/unicode/macro.lua113
-rw-r--r--spec/outputs/unicode/syntax.lua8
-rw-r--r--spec/outputs/unicode/try_catch.lua10
-rw-r--r--src/yuescript/yue_ast.h1
-rw-r--r--src/yuescript/yue_compiler.cpp12
15 files changed, 150 insertions, 92 deletions
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua
index a156e84..bda24bc 100644
--- a/spec/outputs/5.1/attrib.lua
+++ b/spec/outputs/5.1/attrib.lua
@@ -136,9 +136,11 @@ do
136 end 136 end
137 local b 137 local b
138 if not false then 138 if not false then
139 if x then 139 b = ((function()
140 b = 1 140 if x then
141 end 141 return 1
142 end
143 end)())
142 end 144 end
143 local _close_0 145 local _close_0
144 if (function() 146 if (function()
@@ -164,10 +166,12 @@ do
164 end)(pcall(function() 166 end)(pcall(function()
165 local c 167 local c
166 if true then 168 if true then
167 local _exp_0 = x 169 c = ((function()
168 if "abc" == _exp_0 then 170 local _exp_0 = x
169 c = 998 171 if "abc" == _exp_0 then
170 end 172 return 998
173 end
174 end)())
171 end 175 end
172 local d 176 local d
173 if (function() 177 if (function()
diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua
index d4c80c1..efd92c6 100644
--- a/spec/outputs/5.1/try_catch.lua
+++ b/spec/outputs/5.1/try_catch.lua
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb)
8 return tb.func() 8 return tb.func()
9end 9end
10local _anon_func_3 = function(tb) 10local _anon_func_3 = function(tb)
11 return tb.func() 11 return (tb.func())
12end 12end
13local _anon_func_4 = function(tb) 13local _anon_func_4 = function(tb)
14 return tb:func(1, 2, 3) 14 return (tb:func(1, 2, 3))
15end 15end
16local _anon_func_5 = function(tb) 16local _anon_func_5 = function(tb)
17 return tb.func(1) 17 return tb.func(1)
@@ -64,7 +64,7 @@ f = function()
64 print("OK") 64 print("OK")
65 end 65 end
66 if xpcall(function() 66 if xpcall(function()
67 return func(1) 67 return (func(1))
68 end, function(err) 68 end, function(err)
69 return print(err) 69 return print(err)
70 end) then 70 end) then
diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua
index f889865..162c5a8 100644
--- a/spec/outputs/assign.lua
+++ b/spec/outputs/assign.lua
@@ -36,10 +36,10 @@ local x
36do 36do
37 local f = getHandler() 37 local f = getHandler()
38 if f then 38 if f then
39 do 39 x = ((function()
40 f() 40 f()
41 x = 123 41 return 123
42 end 42 end)())
43 end 43 end
44end 44end
45local _anon_func_0 = function(print) 45local _anon_func_0 = function(print)
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua
index e48963c..bb9916c 100644
--- a/spec/outputs/attrib.lua
+++ b/spec/outputs/attrib.lua
@@ -56,17 +56,21 @@ do
56 end 56 end
57 local b 57 local b
58 if not false then 58 if not false then
59 if x then 59 b = ((function()
60 b = 1 60 if x then
61 end 61 return 1
62 end
63 end)())
62 end 64 end
63 local _close_0 <close> = b 65 local _close_0 <close> = b
64 local c 66 local c
65 if true then 67 if true then
66 local _exp_0 = x 68 c = ((function()
67 if "abc" == _exp_0 then 69 local _exp_0 = x
68 c = 998 70 if "abc" == _exp_0 then
69 end 71 return 998
72 end
73 end)())
70 end 74 end
71 local d 75 local d
72 if (function() 76 if (function()
diff --git a/spec/outputs/do.lua b/spec/outputs/do.lua
index 6473e03..96d1022 100644
--- a/spec/outputs/do.lua
+++ b/spec/outputs/do.lua
@@ -32,10 +32,10 @@ local t = {
32} 32}
33return function(y, k) 33return function(y, k)
34 if y == nil then 34 if y == nil then
35 do 35 y = ((function()
36 x = 10 + 2 36 x = 10 + 2
37 y = x 37 return x
38 end 38 end)())
39 end 39 end
40 if k == nil then 40 if k == nil then
41 do 41 do
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
index 5fd1821..040a325 100644
--- a/spec/outputs/syntax.lua
+++ b/spec/outputs/syntax.lua
@@ -239,9 +239,11 @@ x = 0
239local _list_0 = values 239local _list_0 = values
240for _index_0 = 1, #_list_0 do 240for _index_0 = 1, #_list_0 do
241 local v = _list_0[_index_0] 241 local v = _list_0[_index_0]
242 if ntype(v) == "fndef" then 242 _ = ((function()
243 _ = x + 1 243 if ntype(v) == "fndef" then
244 end 244 return x + 1
245 end
246 end)())
245end 247end
246hello = { 248hello = {
247 something = world, 249 something = world,
diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua
index d4c80c1..efd92c6 100644
--- a/spec/outputs/try_catch.lua
+++ b/spec/outputs/try_catch.lua
@@ -8,10 +8,10 @@ local _anon_func_2 = function(tb)
8 return tb.func() 8 return tb.func()
9end 9end
10local _anon_func_3 = function(tb) 10local _anon_func_3 = function(tb)
11 return tb.func() 11 return (tb.func())
12end 12end
13local _anon_func_4 = function(tb) 13local _anon_func_4 = function(tb)
14 return tb:func(1, 2, 3) 14 return (tb:func(1, 2, 3))
15end 15end
16local _anon_func_5 = function(tb) 16local _anon_func_5 = function(tb)
17 return tb.func(1) 17 return tb.func(1)
@@ -64,7 +64,7 @@ f = function()
64 print("OK") 64 print("OK")
65 end 65 end
66 if xpcall(function() 66 if xpcall(function()
67 return func(1) 67 return (func(1))
68 end, function(err) 68 end, function(err)
69 return print(err) 69 return print(err)
70 end) then 70 end) then
diff --git a/spec/outputs/unicode/assign.lua b/spec/outputs/unicode/assign.lua
index bf43953..d4ad56a 100644
--- a/spec/outputs/unicode/assign.lua
+++ b/spec/outputs/unicode/assign.lua
@@ -36,10 +36,10 @@ local _u53d8_u91cfx
36do 36do
37 local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570() 37 local _u51fd_u6570 = _u83b7_u53d6_u5904_u7406_u51fd_u6570()
38 if _u51fd_u6570 then 38 if _u51fd_u6570 then
39 do 39 _u53d8_u91cfx = ((function()
40 _u51fd_u6570() 40 _u51fd_u6570()
41 _u53d8_u91cfx = 123 41 return 123
42 end 42 end)())
43 end 43 end
44end 44end
45local _anon_func_0 = function(_u6253_u5370) 45local _anon_func_0 = function(_u6253_u5370)
diff --git a/spec/outputs/unicode/attrib.lua b/spec/outputs/unicode/attrib.lua
index 1c48de4..5e5bb99 100644
--- a/spec/outputs/unicode/attrib.lua
+++ b/spec/outputs/unicode/attrib.lua
@@ -48,17 +48,21 @@ do
48 end 48 end
49 local _u5173_u95ed_u53d8_u91cfb 49 local _u5173_u95ed_u53d8_u91cfb
50 if not false then 50 if not false then
51 if _u6761_u4ef6x then 51 _u5173_u95ed_u53d8_u91cfb = ((function()
52 _u5173_u95ed_u53d8_u91cfb = 1 52 if _u6761_u4ef6x then
53 end 53 return 1
54 end
55 end)())
54 end 56 end
55 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb 57 local _close_0 <close> = _u5173_u95ed_u53d8_u91cfb
56 local _u5e38_u91cfc 58 local _u5e38_u91cfc
57 if true then 59 if true then
58 local _exp_0 = _u6761_u4ef6x 60 _u5e38_u91cfc = ((function()
59 if "abc" == _exp_0 then 61 local _exp_0 = _u6761_u4ef6x
60 _u5e38_u91cfc = 998 62 if "abc" == _exp_0 then
61 end 63 return 998
64 end
65 end)())
62 end 66 end
63 local _u5173_u95ed_u53d8_u91cfd 67 local _u5173_u95ed_u53d8_u91cfd
64 if (function() 68 if (function()
diff --git a/spec/outputs/unicode/do.lua b/spec/outputs/unicode/do.lua
index f9c3079..7bf1da3 100644
--- a/spec/outputs/unicode/do.lua
+++ b/spec/outputs/unicode/do.lua
@@ -32,10 +32,10 @@ local _u53d8_u91cft = {
32} 32}
33return function(_u53c2_u6570y, _u53c2_u6570k) 33return function(_u53c2_u6570y, _u53c2_u6570k)
34 if _u53c2_u6570y == nil then 34 if _u53c2_u6570y == nil then
35 do 35 _u53c2_u6570y = ((function()
36 _u53d8_u91cfx = 10 + 2 36 _u53d8_u91cfx = 10 + 2
37 _u53c2_u6570y = _u53d8_u91cfx 37 return _u53d8_u91cfx
38 end 38 end)())
39 end 39 end
40 if _u53c2_u6570k == nil then 40 if _u53c2_u6570k == nil then
41 do 41 do
diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua
index 099080f..b14f571 100644
--- a/spec/outputs/unicode/macro.lua
+++ b/spec/outputs/unicode/macro.lua
@@ -215,52 +215,85 @@ do
215-- 这有个注释 215-- 这有个注释
216end 216end
217local _ = require('下划线') 217local _ = require('下划线')
218local _call_0 = (_({ 218local _anon_func_0 = function(_)
219 1, 219 do
220 2, 220 local _call_0 = (_({
221 3, 221 1,
222 4, 222 2,
223 -2, 223 3,
224 3 224 4,
225})) 225 -2,
226_call_0 = _call_0["链"](_call_0) 226 3
227_call_0 = _call_0["映射"](_call_0, function(self) 227 }))
228 return self * 2 228 return _call_0["链"](_call_0)
229end) 229 end
230_call_0 = _call_0["过滤"](_call_0, function(self) 230end
231 return self > 3 231local _call_0 = ((function()
232end) 232 local _call_0 = ((function()
233local _u7ed3_u679ca = _call_0["取值"](_call_0) 233 local _call_0 = (_anon_func_0(_))
234do 234 return _call_0["映射"](_call_0, function(self)
235 local _call_1 = (_({ 235 return self * 2
236 1, 236 end)
237 2, 237 end)())
238 3, 238 return _call_0["过滤"](_call_0, function(self)
239 4,
240 -2,
241 3
242 }))
243 _call_1 = _call_1["链"](_call_1)
244 _call_1 = _call_1["映射"](_call_1, function(self)
245 return self * 2
246 end)
247 _call_1 = _call_1["过滤"](_call_1, function(self)
248 return self > 3 239 return self > 3
249 end) 240 end)
241end)())
242local _u7ed3_u679ca = _call_0["取值"](_call_0)
243local _anon_func_1 = function(_)
244 do
245 local _call_1 = (_({
246 1,
247 2,
248 3,
249 4,
250 -2,
251 3
252 }))
253 return _call_1["链"](_call_1)
254 end
255end
256do
257 local _call_1 = ((function()
258 local _call_1 = ((function()
259 local _call_1 = (_anon_func_1(_))
260 return _call_1["映射"](_call_1, function(self)
261 return self * 2
262 end)
263 end)())
264 return _call_1["过滤"](_call_1, function(self)
265 return self > 3
266 end)
267 end)())
250 _call_1["每一个"](_call_1, function(self) 268 _call_1["每一个"](_call_1, function(self)
251 return _u6253_u5370(self) 269 return _u6253_u5370(self)
252 end) 270 end)
253end 271end
254local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] 272local _anon_func_2 = function(_u539f_u70b9)
255_call_1 = _call_1["父节点"](_call_1) 273 do
256_call_1 = _call_1["后代"](_call_1) 274 local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"]
257_call_1 = _call_1["选择启用"](_call_1) 275 return _call_1["父节点"](_call_1)
258_call_1 = _call_1["选择可见"](_call_1) 276 end
259_call_1 = _call_1["标签等于"](_call_1, "fx") 277end
260_call_1 = _call_1["其中"](_call_1, function(x) 278local _call_1 = ((function()
261 local _call_2 = x["名称"] 279 local _call_1 = ((function()
262 return _call_2["结尾为"](_call_2, "(克隆)") 280 local _call_1 = ((function()
263end) 281 local _call_1 = ((function()
282 local _call_1 = ((function()
283 local _call_1 = (_anon_func_2(_u539f_u70b9))
284 return _call_1["后代"](_call_1)
285 end)())
286 return _call_1["选择启用"](_call_1)
287 end)())
288 return _call_1["选择可见"](_call_1)
289 end)())
290 return _call_1["标签等于"](_call_1, "fx")
291 end)())
292 return _call_1["其中"](_call_1, function(x)
293 local _call_2 = x["名称"]
294 return _call_2["结尾为"](_call_2, "(克隆)")
295 end)
296end)())
264_u7ed3_u679c = _call_1["摧毁"](_call_1) 297_u7ed3_u679c = _call_1["摧毁"](_call_1)
265do 298do
266 do 299 do
diff --git a/spec/outputs/unicode/syntax.lua b/spec/outputs/unicode/syntax.lua
index ea97bb9..1984f40 100644
--- a/spec/outputs/unicode/syntax.lua
+++ b/spec/outputs/unicode/syntax.lua
@@ -258,9 +258,11 @@ _u53d8_u91cfx = 0
258local _list_0 = _u503c 258local _list_0 = _u503c
259for _index_0 = 1, #_list_0 do 259for _index_0 = 1, #_list_0 do
260 local _u53d8_u91cfv = _list_0[_index_0] 260 local _u53d8_u91cfv = _list_0[_index_0]
261 if ntype(_u53d8_u91cfv) == "函数定义" then 261 _ = ((function()
262 _ = _u53d8_u91cfx + 1 262 if ntype(_u53d8_u91cfv) == "函数定义" then
263 end 263 return _u53d8_u91cfx + 1
264 end
265 end)())
264end 266end
265_u4f60_u597d = { 267_u4f60_u597d = {
266 ["某物"] = _u4e16_u754c, 268 ["某物"] = _u4e16_u754c,
diff --git a/spec/outputs/unicode/try_catch.lua b/spec/outputs/unicode/try_catch.lua
index 22f29f9..f8c7849 100644
--- a/spec/outputs/unicode/try_catch.lua
+++ b/spec/outputs/unicode/try_catch.lua
@@ -32,11 +32,13 @@ pcall(function()
32 return _u8868["函数"]() 32 return _u8868["函数"]()
33end) 33end)
34pcall(function() 34pcall(function()
35 return _u8868["函数"]() 35 return (_u8868["函数"]())
36end) 36end)
37pcall(function() 37pcall(function()
38 local _call_0 = _u8868 38 return ((function()
39 return _call_0["函数"](_call_0, 1, 2, 3) 39 local _call_0 = _u8868
40 return _call_0["函数"](_call_0, 1, 2, 3)
41 end)())
40end) 42end)
41pcall(function() 43pcall(function()
42 return _u8868["函数"](1) 44 return _u8868["函数"](1)
@@ -52,7 +54,7 @@ end)) then
52 _u6253_u5370("好的") 54 _u6253_u5370("好的")
53end 55end
54if xpcall(function() 56if xpcall(function()
55 return _u51fd_u6570(1) 57 return (_u51fd_u6570(1))
56end, function(_u9519_u8bef) 58end, function(_u9519_u8bef)
57 return _u6253_u5370(_u9519_u8bef) 59 return _u6253_u5370(_u9519_u8bef)
58end) then 60end) then
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index e670126..5e70645 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -620,6 +620,7 @@ AST_END(Slice)
620 620
621AST_NODE(Parens) 621AST_NODE(Parens)
622 ast_ptr<true, Exp_t> expr; 622 ast_ptr<true, Exp_t> expr;
623 bool extra = false;
623 AST_MEMBER(Parens, &expr) 624 AST_MEMBER(Parens, &expr)
624AST_END(Parens) 625AST_END(Parens)
625 626
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index a2a1864..68ce9b5 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
75 "close"s // Lua 5.4 75 "close"s // Lua 5.4
76}; 76};
77 77
78const std::string_view version = "0.27.3"sv; 78const std::string_view version = "0.27.4"sv;
79const std::string_view extension = "yue"sv; 79const std::string_view extension = "yue"sv;
80 80
81class CompileError : public std::logic_error { 81class CompileError : public std::logic_error {
@@ -1080,8 +1080,8 @@ private:
1080 if (unary->ops.empty()) { 1080 if (unary->ops.empty()) {
1081 Value_t* value = static_cast<Value_t*>(unary->expos.back()); 1081 Value_t* value = static_cast<Value_t*>(unary->expos.back());
1082 if (auto chain = ast_cast<ChainValue_t>(value->item); chain && chain->items.size() == 1) { 1082 if (auto chain = ast_cast<ChainValue_t>(value->item); chain && chain->items.size() == 1) {
1083 if (auto exp = chain->get_by_path<Callable_t, Parens_t, Exp_t>()) { 1083 if (auto parens = chain->get_by_path<Callable_t, Parens_t>(); parens && parens->extra) {
1084 if (auto insideValue = singleValueFrom(exp)) { 1084 if (auto insideValue = singleValueFrom(parens->expr)) {
1085 return insideValue; 1085 return insideValue;
1086 } 1086 }
1087 } 1087 }
@@ -3262,6 +3262,7 @@ private:
3262 } else if (destruct.items.size() == 1 && !singleValueFrom(*j)) { 3262 } else if (destruct.items.size() == 1 && !singleValueFrom(*j)) {
3263 auto p = destruct.value.get(); 3263 auto p = destruct.value.get();
3264 auto parens = p->new_ptr<Parens_t>(); 3264 auto parens = p->new_ptr<Parens_t>();
3265 parens->extra = true;
3265 if (auto tableBlock = ast_cast<TableBlock_t>(p)) { 3266 if (auto tableBlock = ast_cast<TableBlock_t>(p)) {
3266 auto tableLit = p->new_ptr<TableLit_t>(); 3267 auto tableLit = p->new_ptr<TableLit_t>();
3267 tableLit->values.dup(tableBlock->values); 3268 tableLit->values.dup(tableBlock->values);
@@ -4750,6 +4751,7 @@ private:
4750 newSimpleValue->value.set(funLit); 4751 newSimpleValue->value.set(funLit);
4751 auto newExpInParens = newExp(newSimpleValue, x); 4752 auto newExpInParens = newExp(newSimpleValue, x);
4752 auto newParens = x->new_ptr<Parens_t>(); 4753 auto newParens = x->new_ptr<Parens_t>();
4754 newParens->extra = true;
4753 newParens->expr.set(newExpInParens); 4755 newParens->expr.set(newExpInParens);
4754 auto newCallable = x->new_ptr<Callable_t>(); 4756 auto newCallable = x->new_ptr<Callable_t>();
4755 newCallable->item.set(newParens); 4757 newCallable->item.set(newParens);
@@ -5570,6 +5572,7 @@ private:
5570 auto x = chainList.front(); 5572 auto x = chainList.front();
5571 if (ast_is<ExistentialOp_t>(chainList.back())) { 5573 if (ast_is<ExistentialOp_t>(chainList.back())) {
5572 auto parens = x->new_ptr<Parens_t>(); 5574 auto parens = x->new_ptr<Parens_t>();
5575 parens->extra = true;
5573 { 5576 {
5574 auto chainValue = x->new_ptr<ChainValue_t>(); 5577 auto chainValue = x->new_ptr<ChainValue_t>();
5575 for (auto item : chainList) { 5578 for (auto item : chainList) {
@@ -6163,6 +6166,7 @@ private:
6163 ++next; 6166 ++next;
6164 if (next != chainList.end()) { 6167 if (next != chainList.end()) {
6165 auto paren = x->new_ptr<Parens_t>(); 6168 auto paren = x->new_ptr<Parens_t>();
6169 paren->extra = true;
6166 paren->expr.set(newExp(chainValue, x)); 6170 paren->expr.set(newExp(chainValue, x));
6167 auto ncallable = x->new_ptr<Callable_t>(); 6171 auto ncallable = x->new_ptr<Callable_t>();
6168 ncallable->item.set(paren); 6172 ncallable->item.set(paren);
@@ -6215,6 +6219,7 @@ private:
6215 simpleValue->value.set(funLit); 6219 simpleValue->value.set(funLit);
6216 auto exp = newExp(simpleValue, x); 6220 auto exp = newExp(simpleValue, x);
6217 auto paren = x->new_ptr<Parens_t>(); 6221 auto paren = x->new_ptr<Parens_t>();
6222 paren->extra = true;
6218 paren->expr.set(exp); 6223 paren->expr.set(exp);
6219 auto callable = x->new_ptr<Callable_t>(); 6224 auto callable = x->new_ptr<Callable_t>();
6220 callable->item.set(paren); 6225 callable->item.set(paren);
@@ -6631,6 +6636,7 @@ private:
6631 exp.set(info.node); 6636 exp.set(info.node);
6632 if (!exp->opValues.empty() || (chainList.size() > 2 || (chainList.size() == 2 && !ast_is<Invoke_t, InvokeArgs_t>(chainList.back())))) { 6637 if (!exp->opValues.empty() || (chainList.size() > 2 || (chainList.size() == 2 && !ast_is<Invoke_t, InvokeArgs_t>(chainList.back())))) {
6633 auto paren = x->new_ptr<Parens_t>(); 6638 auto paren = x->new_ptr<Parens_t>();
6639 paren->extra = true;
6634 paren->expr.set(exp); 6640 paren->expr.set(exp);
6635 auto callable = x->new_ptr<Callable_t>(); 6641 auto callable = x->new_ptr<Callable_t>();
6636 callable->item.set(paren); 6642 callable->item.set(paren);