diff options
author | Li Jin <dragon-fly@qq.com> | 2023-08-07 09:57:27 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-08-07 09:57:27 +0800 |
commit | c9b70274787ed8a77e7b47c4628197f0c6c1ba30 (patch) | |
tree | fae88047d312962aebfd97a0183c2f9f19e2cc76 /spec | |
parent | aff8e69bf589d2ee5f4a7b72b7e2f643d55b87fa (diff) | |
download | yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.tar.gz yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.tar.bz2 yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.zip |
fixing issue #143 and #144.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/attrib.yue | 31 | ||||
-rw-r--r-- | spec/outputs/5.1/attrib.lua | 238 | ||||
-rw-r--r-- | spec/outputs/attrib.lua | 45 |
3 files changed, 290 insertions, 24 deletions
diff --git a/spec/inputs/attrib.yue b/spec/inputs/attrib.yue index 500ef0f..fbff75a 100644 --- a/spec/inputs/attrib.yue +++ b/spec/inputs/attrib.yue | |||
@@ -1,3 +1,5 @@ | |||
1 | const a, b, c, d = 1, 2, 3, 4 | ||
2 | |||
1 | do | 3 | do |
2 | close a, b = setmetatable {},__close:=> print "closed" | 4 | close a, b = setmetatable {},__close:=> print "closed" |
3 | const c, d = 123, 'abc' | 5 | const c, d = 123, 'abc' |
@@ -6,6 +8,12 @@ do | |||
6 | const c, d | 8 | const c, d |
7 | 9 | ||
8 | do | 10 | do |
11 | const a, {b, c}, {d} = f!, f1! | ||
12 | |||
13 | do | ||
14 | const a, {b, c}, {d} = f! | ||
15 | |||
16 | do | ||
9 | close v = if flag | 17 | close v = if flag |
10 | func! | 18 | func! |
11 | else | 19 | else |
@@ -22,27 +30,24 @@ do | |||
22 | close d = | 30 | close d = |
23 | :value if a ?? b | 31 | :value if a ?? b |
24 | 32 | ||
25 | macro defer = (item)-> "close _ = #{item}" | ||
26 | macro defer_f = (func)-> "close _ = setmetatable {},__close:#{func}" | ||
27 | |||
28 | do | 33 | do |
29 | $defer with io.open "file.txt" | 34 | close _ = with io.open "file.txt" |
30 | \write "Hello" | 35 | \write "Hello" |
31 | 36 | ||
32 | $defer setmetatable {},__close:=> print "second" | 37 | close _ = <close>: -> print "second" |
33 | 38 | ||
34 | $defer_f -> print "first" | 39 | close _ = <close>: -> print "first" |
35 | 40 | ||
36 | _defers = setmetatable {},__close:=> | 41 | _defers = setmetatable {}, __close: => |
37 | @[#@]! | 42 | @[#@]! |
38 | @[#@] = nil | 43 | @[#@] = nil |
39 | 44 | ||
40 | macro defer_i = (item)-> " | 45 | def = (item)-> |
41 | _defers[#_defers + 1] = #{item} | 46 | _defers[#_defers + 1] = item |
42 | close _ = _defers" | 47 | _defers |
43 | 48 | ||
44 | do | 49 | do |
45 | $defer_i -> print 3 | 50 | close _ = def -> print 3 |
46 | $defer_i -> print 2 | 51 | close _ = def -> print 2 |
47 | $defer_i -> print 1 | 52 | close _ = def -> print 1 |
48 | 53 | ||
diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua new file mode 100644 index 0000000..f782b45 --- /dev/null +++ b/spec/outputs/5.1/attrib.lua | |||
@@ -0,0 +1,238 @@ | |||
1 | local a, b, c, d = 1, 2, 3, 4 | ||
2 | do | ||
3 | local a, b = setmetatable({ }, { | ||
4 | __close = function(self) | ||
5 | return print("closed") | ||
6 | end | ||
7 | }) | ||
8 | local _close_0 = assert(getmetatable(a).__close) | ||
9 | local _close_1 = assert(getmetatable(b).__close); | ||
10 | (function(_arg_0, ...) | ||
11 | local _ok_0 = _arg_0 | ||
12 | _close_1(b) | ||
13 | _close_0(a) | ||
14 | if _ok_0 then | ||
15 | return ... | ||
16 | else | ||
17 | return error(...) | ||
18 | end | ||
19 | end)(pcall(function(...) | ||
20 | local c, d = 123, 'abc' | ||
21 | close(a, b) | ||
22 | return const(c, d) | ||
23 | end, ...)) | ||
24 | end | ||
25 | do | ||
26 | local a = f() | ||
27 | local b, c, d | ||
28 | do | ||
29 | local _obj_0, _obj_1 = f1() | ||
30 | b, c = _obj_0[1], _obj_0[2] | ||
31 | d = _obj_1[1] | ||
32 | end | ||
33 | end | ||
34 | do | ||
35 | local a, b, c, d | ||
36 | do | ||
37 | local _obj_0, _obj_1, _obj_2 = f() | ||
38 | a = _obj_0 | ||
39 | b, c = _obj_1[1], _obj_1[2] | ||
40 | d = _obj_2[1] | ||
41 | end | ||
42 | end | ||
43 | do | ||
44 | local v = (function() | ||
45 | if flag then | ||
46 | return func() | ||
47 | else | ||
48 | return setmetatable({ }, { | ||
49 | __close = function(self) end | ||
50 | }) | ||
51 | end | ||
52 | end)() | ||
53 | local _close_0 = assert(getmetatable(v).__close); | ||
54 | (function(_arg_0, ...) | ||
55 | local _ok_0 = _arg_0 | ||
56 | _close_0(v) | ||
57 | if _ok_0 then | ||
58 | return ... | ||
59 | else | ||
60 | return error(...) | ||
61 | end | ||
62 | end)(pcall(function(...) | ||
63 | local f = (function() | ||
64 | local _with_0 = io.open("file.txt") | ||
65 | _with_0:write("Hello") | ||
66 | return _with_0 | ||
67 | end)() | ||
68 | local _close_1 = assert(getmetatable(f).__close) | ||
69 | return (function(_arg_0, ...) | ||
70 | local _ok_0 = _arg_0 | ||
71 | _close_1(f) | ||
72 | if _ok_0 then | ||
73 | return ... | ||
74 | else | ||
75 | return error(...) | ||
76 | end | ||
77 | end)(pcall(function(...) end, ...)) | ||
78 | end, ...)) | ||
79 | end | ||
80 | do | ||
81 | local a = (function() | ||
82 | if true then | ||
83 | return 1 | ||
84 | end | ||
85 | end)() | ||
86 | local b = (function() | ||
87 | if not false then | ||
88 | if x then | ||
89 | return 1 | ||
90 | end | ||
91 | end | ||
92 | end)() | ||
93 | local _close_0 = assert(getmetatable(b).__close); | ||
94 | (function(_arg_0, ...) | ||
95 | local _ok_0 = _arg_0 | ||
96 | _close_0(b) | ||
97 | if _ok_0 then | ||
98 | return ... | ||
99 | else | ||
100 | return error(...) | ||
101 | end | ||
102 | end)(pcall(function(...) | ||
103 | local c = (function() | ||
104 | if true then | ||
105 | local _exp_0 = x | ||
106 | if "abc" == _exp_0 then | ||
107 | return 998 | ||
108 | end | ||
109 | end | ||
110 | end)() | ||
111 | local d = (function() | ||
112 | if (function() | ||
113 | if a ~= nil then | ||
114 | return a | ||
115 | else | ||
116 | return b | ||
117 | end | ||
118 | end)() then | ||
119 | return { | ||
120 | value = value | ||
121 | } | ||
122 | end | ||
123 | end)() | ||
124 | local _close_1 = assert(getmetatable(d).__close) | ||
125 | return (function(_arg_0, ...) | ||
126 | local _ok_0 = _arg_0 | ||
127 | _close_1(d) | ||
128 | if _ok_0 then | ||
129 | return ... | ||
130 | else | ||
131 | return error(...) | ||
132 | end | ||
133 | end)(pcall(function(...) end, ...)) | ||
134 | end, ...)) | ||
135 | end | ||
136 | do | ||
137 | local _ = (function() | ||
138 | local _with_0 = io.open("file.txt") | ||
139 | _with_0:write("Hello") | ||
140 | return _with_0 | ||
141 | end)() | ||
142 | local _close_0 = assert(getmetatable(_).__close); | ||
143 | (function(_arg_0, ...) | ||
144 | local _ok_0 = _arg_0 | ||
145 | _close_0(_) | ||
146 | if _ok_0 then | ||
147 | return ... | ||
148 | else | ||
149 | return error(...) | ||
150 | end | ||
151 | end)(pcall(function(...) | ||
152 | local _ = setmetatable({ }, { | ||
153 | __close = function() | ||
154 | return print("second") | ||
155 | end | ||
156 | }) | ||
157 | local _close_1 = assert(getmetatable(_).__close) | ||
158 | return (function(_arg_0, ...) | ||
159 | local _ok_0 = _arg_0 | ||
160 | _close_1(_) | ||
161 | if _ok_0 then | ||
162 | return ... | ||
163 | else | ||
164 | return error(...) | ||
165 | end | ||
166 | end)(pcall(function(...) | ||
167 | local _ = setmetatable({ }, { | ||
168 | __close = function() | ||
169 | return print("first") | ||
170 | end | ||
171 | }) | ||
172 | local _close_2 = assert(getmetatable(_).__close) | ||
173 | return (function(_arg_0, ...) | ||
174 | local _ok_0 = _arg_0 | ||
175 | _close_2(_) | ||
176 | if _ok_0 then | ||
177 | return ... | ||
178 | else | ||
179 | return error(...) | ||
180 | end | ||
181 | end)(pcall(function(...) end, ...)) | ||
182 | end, ...)) | ||
183 | end, ...)) | ||
184 | end | ||
185 | local _defers = setmetatable({ }, { | ||
186 | __close = function(self) | ||
187 | self[#self]() | ||
188 | self[#self] = nil | ||
189 | end | ||
190 | }) | ||
191 | local def | ||
192 | def = function(item) | ||
193 | _defers[#_defers + 1] = item | ||
194 | return _defers | ||
195 | end | ||
196 | do | ||
197 | local _ = def(function() | ||
198 | return print(3) | ||
199 | end) | ||
200 | local _close_0 = assert(getmetatable(_).__close) | ||
201 | return (function(_arg_0, ...) | ||
202 | local _ok_0 = _arg_0 | ||
203 | _close_0(_) | ||
204 | if _ok_0 then | ||
205 | return ... | ||
206 | else | ||
207 | return error(...) | ||
208 | end | ||
209 | end)(pcall(function(...) | ||
210 | local _ = def(function() | ||
211 | return print(2) | ||
212 | end) | ||
213 | local _close_1 = assert(getmetatable(_).__close) | ||
214 | return (function(_arg_0, ...) | ||
215 | local _ok_0 = _arg_0 | ||
216 | _close_1(_) | ||
217 | if _ok_0 then | ||
218 | return ... | ||
219 | else | ||
220 | return error(...) | ||
221 | end | ||
222 | end)(pcall(function(...) | ||
223 | local _ = def(function() | ||
224 | return print(1) | ||
225 | end) | ||
226 | local _close_2 = assert(getmetatable(_).__close) | ||
227 | return (function(_arg_0, ...) | ||
228 | local _ok_0 = _arg_0 | ||
229 | _close_2(_) | ||
230 | if _ok_0 then | ||
231 | return ... | ||
232 | else | ||
233 | return error(...) | ||
234 | end | ||
235 | end)(pcall(function(...) end, ...)) | ||
236 | end, ...)) | ||
237 | end, ...)) | ||
238 | end | ||
diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua index aaff747..919b7e0 100644 --- a/spec/outputs/attrib.lua +++ b/spec/outputs/attrib.lua | |||
@@ -1,14 +1,35 @@ | |||
1 | local a <const>, b <const>, c <const>, d <const> = 1, 2, 3, 4 | ||
1 | do | 2 | do |
2 | local a <close>, b <close> = setmetatable({ }, { | 3 | local a, b = setmetatable({ }, { |
3 | __close = function(self) | 4 | __close = function(self) |
4 | return print("closed") | 5 | return print("closed") |
5 | end | 6 | end |
6 | }) | 7 | }) |
8 | local _close_0 <close> = a | ||
9 | local _close_1 <close> = b | ||
7 | local c <const>, d <const> = 123, 'abc' | 10 | local c <const>, d <const> = 123, 'abc' |
8 | close(a, b) | 11 | close(a, b) |
9 | const(c, d) | 12 | const(c, d) |
10 | end | 13 | end |
11 | do | 14 | do |
15 | local a <const> = f() | ||
16 | local b, c, d | ||
17 | do | ||
18 | local _obj_0, _obj_1 = f1() | ||
19 | b, c = _obj_0[1], _obj_0[2] | ||
20 | d = _obj_1[1] | ||
21 | end | ||
22 | end | ||
23 | do | ||
24 | local a, b, c, d | ||
25 | do | ||
26 | local _obj_0, _obj_1, _obj_2 = f() | ||
27 | a = _obj_0 | ||
28 | b, c = _obj_1[1], _obj_1[2] | ||
29 | d = _obj_2[1] | ||
30 | end | ||
31 | end | ||
32 | do | ||
12 | local v <close> = (function() | 33 | local v <close> = (function() |
13 | if flag then | 34 | if flag then |
14 | return func() | 35 | return func() |
@@ -66,7 +87,7 @@ do | |||
66 | return _with_0 | 87 | return _with_0 |
67 | end)() | 88 | end)() |
68 | local _ <close> = setmetatable({ }, { | 89 | local _ <close> = setmetatable({ }, { |
69 | __close = function(self) | 90 | __close = function() |
70 | return print("second") | 91 | return print("second") |
71 | end | 92 | end |
72 | }) | 93 | }) |
@@ -82,17 +103,19 @@ local _defers = setmetatable({ }, { | |||
82 | self[#self] = nil | 103 | self[#self] = nil |
83 | end | 104 | end |
84 | }) | 105 | }) |
106 | local def | ||
107 | def = function(item) | ||
108 | _defers[#_defers + 1] = item | ||
109 | return _defers | ||
110 | end | ||
85 | do | 111 | do |
86 | _defers[#_defers + 1] = function() | 112 | local _ <close> = def(function() |
87 | return print(3) | 113 | return print(3) |
88 | end | 114 | end) |
89 | local _ <close> = _defers | 115 | local _ <close> = def(function() |
90 | _defers[#_defers + 1] = function() | ||
91 | return print(2) | 116 | return print(2) |
92 | end | 117 | end) |
93 | local _ <close> = _defers | 118 | local _ <close> = def(function() |
94 | _defers[#_defers + 1] = function() | ||
95 | return print(1) | 119 | return print(1) |
96 | end | 120 | end) |
97 | local _ <close> = _defers | ||
98 | end | 121 | end |