aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-09-30 11:29:41 +0800
committerLi Jin <dragon-fly@qq.com>2022-09-30 11:29:41 +0800
commit5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2 (patch)
tree5c5c0ecdab0d19544652bc05b70d8131e1645337 /spec
parenta6b6753fda9745f316f3236462b74794b35b85c9 (diff)
downloadyuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.gz
yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.bz2
yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.zip
fix issue #81, refactor continue with gotos.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/goto.yue4
-rw-r--r--spec/inputs/loops.yue8
-rw-r--r--spec/inputs/test/loops_spec.yue6
-rw-r--r--spec/outputs/5.1/loops.lua381
-rw-r--r--spec/outputs/5.1/test/loops_spec.lua69
-rw-r--r--spec/outputs/goto.lua4
-rw-r--r--spec/outputs/loops.lua204
-rw-r--r--spec/outputs/test/loops_spec.lua51
8 files changed, 537 insertions, 190 deletions
diff --git a/spec/inputs/goto.yue b/spec/inputs/goto.yue
index 1197251..61584ca 100644
--- a/spec/inputs/goto.yue
+++ b/spec/inputs/goto.yue
@@ -10,8 +10,8 @@ do
10 for z = 1, 10 do for y = 1, 10 do for x = 1, 10 10 for z = 1, 10 do for y = 1, 10 do for x = 1, 10
11 if x^2 + y^2 == z^2 11 if x^2 + y^2 == z^2
12 print 'found a Pythagorean triple:', x, y, z 12 print 'found a Pythagorean triple:', x, y, z
13 goto done 13 goto ok
14 ::done:: 14 ::ok::
15 15
16do 16do
17 for z = 1, 10 17 for z = 1, 10
diff --git a/spec/inputs/loops.yue b/spec/inputs/loops.yue
index d03e661..d997c65 100644
--- a/spec/inputs/loops.yue
+++ b/spec/inputs/loops.yue
@@ -111,10 +111,10 @@ until a == 10
111 111
112x = 0 112x = 0
113repeat 113repeat
114 x += 1 114 x += 1
115 y = x 115 y = x
116 continue if x < 5 116 continue if x < 5
117 print y 117 print y
118until y == 10 118until y == 10
119 119
120a = 3 120a = 3
diff --git a/spec/inputs/test/loops_spec.yue b/spec/inputs/test/loops_spec.yue
index 817919f..a115581 100644
--- a/spec/inputs/test/loops_spec.yue
+++ b/spec/inputs/test/loops_spec.yue
@@ -5,8 +5,8 @@ describe "loops", ->
5 continue if x % 2 == 1 5 continue if x % 2 == 1
6 x 6 x
7 7
8 assert.same output, { 2,4,6 } 8 assert.same { 2,4,6 }, output
9 9
10 it "continue in repeat", -> 10 it "continue in repeat", ->
11 output = {} 11 output = {}
12 a = 0 12 a = 0
@@ -19,5 +19,5 @@ describe "loops", ->
19 output[] = a 19 output[] = a
20 until a == 8 20 until a == 8
21 21
22 assert.same output, { 1,2,4 } 22 assert.same { 1,2,4 }, output
23 23
diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua
new file mode 100644
index 0000000..a3b9548
--- /dev/null
+++ b/spec/outputs/5.1/loops.lua
@@ -0,0 +1,381 @@
1for x = 1, 10 do
2 print("yeah")
3end
4for x = 1, #something do
5 print("yeah")
6end
7for y = 100, 60, -3 do
8 print("count down", y)
9end
10for a = 1, 10 do
11 print("okay")
12end
13for a = 1, 10 do
14 for b = 2, 43 do
15 print(a, b)
16 end
17end
18for i in iter do
19 for j in yeah do
20 local x = 343 + i + j
21 print(i, j)
22 end
23end
24local _list_0 = something
25for _index_0 = 1, #_list_0 do
26 local x = _list_0[_index_0]
27 print(x)
28end
29for k, v in pairs(hello) do
30 print(k, v)
31end
32for x in y, z do
33 print(x)
34end
35for x in y, z, k do
36 print(x)
37end
38local _list_1 = modules
39for _index_0 = 1, #_list_1 do
40 local name, members = _list_1[_index_0]
41 print(name, member)
42end
43local x
44x = function()
45 for x in y do
46 local _ = y
47 end
48end
49local hello = {
50 1,
51 2,
52 3,
53 4,
54 5
55}
56do
57 local _accum_0 = { }
58 local _len_0 = 1
59 for _index_0 = 1, #hello do
60 local y = hello[_index_0]
61 if y % 2 == 0 then
62 _accum_0[_len_0] = y
63 end
64 _len_0 = _len_0 + 1
65 end
66 x = _accum_0
67end
68x = function()
69 for _index_0 = 1, #hello do
70 local x = hello[_index_0]
71 local _ = y
72 end
73end
74local t
75do
76 local _accum_0 = { }
77 local _len_0 = 1
78 for i = 10, 20 do
79 _accum_0[_len_0] = i * 2
80 _len_0 = _len_0 + 1
81 end
82 t = _accum_0
83end
84local hmm = 0
85local y
86do
87 local _accum_0 = { }
88 local _len_0 = 1
89 for j = 3, 30, 8 do
90 hmm = hmm + 1
91 _accum_0[_len_0] = j * hmm
92 _len_0 = _len_0 + 1
93 end
94 y = _accum_0
95end
96local _
97_ = function()
98 for k = 10, 40 do
99 _ = "okay"
100 end
101end
102_ = function()
103 local _accum_0 = { }
104 local _len_0 = 1
105 for k = 10, 40 do
106 _accum_0[_len_0] = "okay"
107 _len_0 = _len_0 + 1
108 end
109 return _accum_0
110end
111while true do
112 print("name")
113end
114while 5 + 5 do
115 print("okay world")
116 working(man)
117end
118while also do
119 i(work(too))
120 _ = "okay"
121end
122local i = 0
123do
124 local _accum_0 = { }
125 local _len_0 = 1
126 while i < 10 do
127 i = i + 1
128 _len_0 = _len_0 + 1
129 end
130 x = _accum_0
131end
132do
133 local _accum_0 = { }
134 local _len_0 = 1
135 local _list_2 = 3
136 for _index_0 = 1, #_list_2 do
137 local thing = _list_2[_index_0]
138 y = "hello"
139 _len_0 = _len_0 + 1
140 end
141 x = _accum_0
142end
143do
144 local _accum_0 = { }
145 local _len_0 = 1
146 for x = 1, 2 do
147 y = "hello"
148 _len_0 = _len_0 + 1
149 end
150 x = _accum_0
151end
152while true do
153 local _continue_0 = false
154 repeat
155 if false then
156 _continue_0 = true
157 break
158 end
159 print("yes")
160 if true then
161 break
162 end
163 print("no")
164 _continue_0 = true
165 until true
166 if not _continue_0 then
167 break
168 end
169end
170for i = 1, 10 do
171 while true do
172 local _continue_0 = false
173 repeat
174 do
175 if not true then
176 _continue_0 = true
177 break
178 end
179 break
180 end
181 _continue_0 = true
182 until true
183 if not _continue_0 then
184 break
185 end
186 end
187end
188local a = 1
189repeat
190 local _cond_0 = false
191 local _continue_0 = false
192 repeat
193 a = a + 1
194 if a == 5 then
195 _cond_0 = a == 10
196 _continue_0 = true
197 break
198 end
199 if a == 6 then
200 break
201 end
202 print(a)
203 _cond_0 = a == 10
204 _continue_0 = true
205 until true
206 if not _continue_0 then
207 break
208 end
209until _cond_0
210x = 0
211repeat
212 local _cond_0 = false
213 local _continue_0 = false
214 repeat
215 x = x + 1
216 y = x
217 if x < 5 then
218 _cond_0 = y == 10
219 _continue_0 = true
220 break
221 end
222 print(y)
223 _cond_0 = y == 10
224 _continue_0 = true
225 until true
226 if not _continue_0 then
227 break
228 end
229until _cond_0
230a = 3
231while not (a == 0) do
232 a = a - 1
233end
234local done = false
235while not done do
236 done = true
237end
238repeat
239 print("hello")
240until true
241while not done do
242 x = 10
243 repeat
244 x = x - 1
245 until x == 0
246end
247while not cond do
248 print("okay")
249end
250for x = 1, 10 do
251 local _continue_0 = false
252 repeat
253 if x > 3 and x < 7 then
254 _continue_0 = true
255 break
256 end
257 print(x)
258 _continue_0 = true
259 until true
260 if not _continue_0 then
261 break
262 end
263end
264local list
265do
266 local _accum_0 = { }
267 local _len_0 = 1
268 for x = 1, 10 do
269 local _continue_0 = false
270 repeat
271 if x > 3 and x < 7 then
272 _continue_0 = true
273 break
274 end
275 _accum_0[_len_0] = x
276 _len_0 = _len_0 + 1
277 _continue_0 = true
278 until true
279 if not _continue_0 then
280 break
281 end
282 end
283 list = _accum_0
284end
285local _list_2 = {
286 1,
287 2,
288 3,
289 4,
290 5,
291 6
292}
293for _index_0 = 1, #_list_2 do
294 local a = _list_2[_index_0]
295 local _continue_0 = false
296 repeat
297 if a == 1 then
298 _continue_0 = true
299 break
300 end
301 if a == 3 then
302 _continue_0 = true
303 break
304 end
305 print(a)
306 _continue_0 = true
307 until true
308 if not _continue_0 then
309 break
310 end
311end
312for x = 1, 10 do
313 local _continue_0 = false
314 repeat
315 if x % 2 == 0 then
316 _continue_0 = true
317 break
318 end
319 for y = 2, 12 do
320 local _continue_1 = false
321 repeat
322 if y % 3 == 0 then
323 _continue_1 = true
324 break
325 end
326 _continue_1 = true
327 until true
328 if not _continue_1 then
329 break
330 end
331 end
332 _continue_0 = true
333 until true
334 if not _continue_0 then
335 break
336 end
337end
338while true do
339 local _continue_0 = false
340 repeat
341 do
342 if false then
343 _continue_0 = true
344 break
345 end
346 break
347 end
348 _continue_0 = true
349 until true
350 if not _continue_0 then
351 break
352 end
353end
354while true do
355 local _continue_0 = false
356 repeat
357 if false then
358 _continue_0 = true
359 break
360 end
361 do
362 return 22
363 end
364 _continue_0 = true
365 until true
366 if not _continue_0 then
367 break
368 end
369end
370do
371 local xxx = {
372 1,
373 2,
374 3,
375 4
376 }
377 for _index_0 = 1, #xxx do
378 local thing = xxx[_index_0]
379 print(thing)
380 end
381end
diff --git a/spec/outputs/5.1/test/loops_spec.lua b/spec/outputs/5.1/test/loops_spec.lua
new file mode 100644
index 0000000..bad17a6
--- /dev/null
+++ b/spec/outputs/5.1/test/loops_spec.lua
@@ -0,0 +1,69 @@
1return describe("loops", function()
2 it("should continue", function()
3 local input = {
4 1,
5 2,
6 3,
7 4,
8 5,
9 6
10 }
11 local output
12 do
13 local _accum_0 = { }
14 local _len_0 = 1
15 for _index_0 = 1, #input do
16 local x = input[_index_0]
17 local _continue_0 = false
18 repeat
19 if x % 2 == 1 then
20 _continue_0 = true
21 break
22 end
23 _accum_0[_len_0] = x
24 _len_0 = _len_0 + 1
25 _continue_0 = true
26 until true
27 if not _continue_0 then
28 break
29 end
30 end
31 output = _accum_0
32 end
33 return assert.same({
34 2,
35 4,
36 6
37 }, output)
38 end)
39 return it("continue in repeat", function()
40 local output = { }
41 local a = 0
42 repeat
43 local _cond_0 = false
44 local _continue_0 = false
45 repeat
46 a = a + 1
47 if a == 3 then
48 _cond_0 = a == 8
49 _continue_0 = true
50 break
51 end
52 if a == 5 then
53 break
54 end
55 output[#output + 1] = a
56 _cond_0 = a == 8
57 _continue_0 = true
58 until true
59 if not _continue_0 then
60 break
61 end
62 until _cond_0
63 return assert.same({
64 1,
65 2,
66 4
67 }, output)
68 end)
69end)
diff --git a/spec/outputs/goto.lua b/spec/outputs/goto.lua
index d1f7b77..421508a 100644
--- a/spec/outputs/goto.lua
+++ b/spec/outputs/goto.lua
@@ -14,12 +14,12 @@ do
14 for x = 1, 10 do 14 for x = 1, 10 do
15 if x ^ 2 + y ^ 2 == z ^ 2 then 15 if x ^ 2 + y ^ 2 == z ^ 2 then
16 print('found a Pythagorean triple:', x, y, z) 16 print('found a Pythagorean triple:', x, y, z)
17 goto done 17 goto ok
18 end 18 end
19 end 19 end
20 end 20 end
21 end 21 end
22 ::done:: 22 ::ok::
23end 23end
24do 24do
25 for z = 1, 10 do 25 for z = 1, 10 do
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua
index e5c189e..9c16ee4 100644
--- a/spec/outputs/loops.lua
+++ b/spec/outputs/loops.lua
@@ -150,83 +150,47 @@ do
150 x = _accum_0 150 x = _accum_0
151end 151end
152while true do 152while true do
153 local _continue_0 = false 153 if false then
154 repeat 154 goto _continue_0
155 if false then 155 end
156 _continue_0 = true 156 print("yes")
157 break 157 if true then
158 end
159 print("yes")
160 if true then
161 break
162 end
163 print("no")
164 _continue_0 = true
165 until true
166 if not _continue_0 then
167 break 158 break
168 end 159 end
160 print("no")
161 ::_continue_0::
169end 162end
170for i = 1, 10 do 163for i = 1, 10 do
171 while true do 164 while true do
172 local _continue_0 = false 165 if not true then
173 repeat 166 goto _continue_1
174 do
175 if not true then
176 _continue_0 = true
177 break
178 end
179 break
180 end
181 _continue_0 = true
182 until true
183 if not _continue_0 then
184 break
185 end 167 end
168 break
169 ::_continue_1::
186 end 170 end
187end 171end
188local a = 1 172local a = 1
189repeat 173repeat
190 local _cond_0 = false 174 a = a + 1
191 local _continue_0 = false 175 if a == 5 then
192 repeat 176 goto _continue_2
193 a = a + 1 177 end
194 if a == 5 then 178 if a == 6 then
195 _cond_0 = a == 10
196 _continue_0 = true
197 break
198 end
199 if a == 6 then
200 break
201 end
202 print(a)
203 _cond_0 = a == 10
204 _continue_0 = true
205 until true
206 if not _continue_0 then
207 break 179 break
208 end 180 end
209until _cond_0 181 print(a)
182 ::_continue_2::
183until a == 10
210x = 0 184x = 0
211repeat 185repeat
212 local _cond_0 = false 186 x = x + 1
213 local _continue_0 = false 187 y = x
214 repeat 188 if x < 5 then
215 x = x + 1 189 goto _continue_3
216 y = x
217 if x < 5 then
218 _cond_0 = y == 10
219 _continue_0 = true
220 break
221 end
222 print(y)
223 _cond_0 = y == 10
224 _continue_0 = true
225 until true
226 if not _continue_0 then
227 break
228 end 190 end
229until _cond_0 191 print(y)
192 ::_continue_3::
193until y == 10
230a = 3 194a = 3
231while not (a == 0) do 195while not (a == 0) do
232 a = a - 1 196 a = a - 1
@@ -248,37 +212,23 @@ while not cond do
248 print("okay") 212 print("okay")
249end 213end
250for x = 1, 10 do 214for x = 1, 10 do
251 local _continue_0 = false 215 if x > 3 and x < 7 then
252 repeat 216 goto _continue_4
253 if x > 3 and x < 7 then
254 _continue_0 = true
255 break
256 end
257 print(x)
258 _continue_0 = true
259 until true
260 if not _continue_0 then
261 break
262 end 217 end
218 print(x)
219 ::_continue_4::
263end 220end
264local list 221local list
265do 222do
266 local _accum_0 = { } 223 local _accum_0 = { }
267 local _len_0 = 1 224 local _len_0 = 1
268 for x = 1, 10 do 225 for x = 1, 10 do
269 local _continue_0 = false 226 if x > 3 and x < 7 then
270 repeat 227 goto _continue_5
271 if x > 3 and x < 7 then
272 _continue_0 = true
273 break
274 end
275 _accum_0[_len_0] = x
276 _len_0 = _len_0 + 1
277 _continue_0 = true
278 until true
279 if not _continue_0 then
280 break
281 end 228 end
229 _accum_0[_len_0] = x
230 _len_0 = _len_0 + 1
231 ::_continue_5::
282 end 232 end
283 list = _accum_0 233 list = _accum_0
284end 234end
@@ -292,78 +242,42 @@ local _list_2 = {
292} 242}
293for _index_0 = 1, #_list_2 do 243for _index_0 = 1, #_list_2 do
294 local a = _list_2[_index_0] 244 local a = _list_2[_index_0]
295 local _continue_0 = false 245 if a == 1 then
296 repeat 246 goto _continue_6
297 if a == 1 then
298 _continue_0 = true
299 break
300 end
301 if a == 3 then
302 _continue_0 = true
303 break
304 end
305 print(a)
306 _continue_0 = true
307 until true
308 if not _continue_0 then
309 break
310 end 247 end
248 if a == 3 then
249 goto _continue_6
250 end
251 print(a)
252 ::_continue_6::
311end 253end
312for x = 1, 10 do 254for x = 1, 10 do
313 local _continue_0 = false 255 if x % 2 == 0 then
314 repeat 256 goto _continue_7
315 if x % 2 == 0 then 257 end
316 _continue_0 = true 258 for y = 2, 12 do
317 break 259 if y % 3 == 0 then
318 end 260 goto _continue_8
319 for y = 2, 12 do
320 local _continue_1 = false
321 repeat
322 if y % 3 == 0 then
323 _continue_1 = true
324 break
325 end
326 _continue_1 = true
327 until true
328 if not _continue_1 then
329 break
330 end
331 end 261 end
332 _continue_0 = true 262 ::_continue_8::
333 until true
334 if not _continue_0 then
335 break
336 end 263 end
264 ::_continue_7::
337end 265end
338while true do 266while true do
339 local _continue_0 = false 267 if false then
340 repeat 268 goto _continue_9
341 do
342 if false then
343 _continue_0 = true
344 break
345 end
346 break
347 end
348 _continue_0 = true
349 until true
350 if not _continue_0 then
351 break
352 end 269 end
270 break
271 ::_continue_9::
353end 272end
354while true do 273while true do
355 local _continue_0 = false 274 if false then
356 repeat 275 goto _continue_10
357 if false then 276 end
358 _continue_0 = true 277 do
359 break
360 end
361 return 22 278 return 22
362 _continue_0 = true
363 until true
364 if not _continue_0 then
365 break
366 end 279 end
280 ::_continue_10::
367end 281end
368do 282do
369 local xxx = { 283 local xxx = {
diff --git a/spec/outputs/test/loops_spec.lua b/spec/outputs/test/loops_spec.lua
index 34f2e9c..9c85e1a 100644
--- a/spec/outputs/test/loops_spec.lua
+++ b/spec/outputs/test/loops_spec.lua
@@ -14,56 +14,39 @@ return describe("loops", function()
14 local _len_0 = 1 14 local _len_0 = 1
15 for _index_0 = 1, #input do 15 for _index_0 = 1, #input do
16 local x = input[_index_0] 16 local x = input[_index_0]
17 local _continue_0 = false 17 if x % 2 == 1 then
18 repeat 18 goto _continue_0
19 if x % 2 == 1 then
20 _continue_0 = true
21 break
22 end
23 _accum_0[_len_0] = x
24 _len_0 = _len_0 + 1
25 _continue_0 = true
26 until true
27 if not _continue_0 then
28 break
29 end 19 end
20 _accum_0[_len_0] = x
21 _len_0 = _len_0 + 1
22 ::_continue_0::
30 end 23 end
31 output = _accum_0 24 output = _accum_0
32 end 25 end
33 return assert.same(output, { 26 return assert.same({
34 2, 27 2,
35 4, 28 4,
36 6 29 6
37 }) 30 }, output)
38 end) 31 end)
39 return it("continue in repeat", function() 32 return it("continue in repeat", function()
40 local output = { } 33 local output = { }
41 local a = 0 34 local a = 0
42 repeat 35 repeat
43 local _cond_0 = false 36 a = a + 1
44 local _continue_0 = false 37 if a == 3 then
45 repeat 38 goto _continue_0
46 a = a + 1 39 end
47 if a == 3 then 40 if a == 5 then
48 _cond_0 = a == 8
49 _continue_0 = true
50 break
51 end
52 if a == 5 then
53 break
54 end
55 output[#output + 1] = a
56 _cond_0 = a == 8
57 _continue_0 = true
58 until true
59 if not _continue_0 then
60 break 41 break
61 end 42 end
62 until _cond_0 43 output[#output + 1] = a
63 return assert.same(output, { 44 ::_continue_0::
45 until a == 8
46 return assert.same({
64 1, 47 1,
65 2, 48 2,
66 4 49 4
67 }) 50 }, output)
68 end) 51 end)
69end) 52end)