Mercurial > vim
comparison src/testdir/test_vim9_disassemble.vim @ 20407:33166d945b54 v8.2.0758
patch 8.2.0758: Vim9: no test for STORELIST and STOREDICT
Commit: https://github.com/vim/vim/commit/cb7904016eb817e80760c394044740df8273c774
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 15 20:53:00 2020 +0200
patch 8.2.0758: Vim9: no test for STORELIST and STOREDICT
Problem: Vim9: no test for STORELIST and STOREDICT.
Solution: Add a test. Make matches stricter.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 15 May 2020 21:00:03 +0200 |
parents | 83573e907c8b |
children | 489cb75c76b6 |
comparison
equal
deleted
inserted
replaced
20406:58bcb71172b7 | 20407:33166d945b54 |
---|---|
152 '@z = ''rv''.*' .. | 152 '@z = ''rv''.*' .. |
153 ' STOREREG @z.*', | 153 ' STOREREG @z.*', |
154 res) | 154 res) |
155 enddef | 155 enddef |
156 | 156 |
157 def s:ScriptFuncStoreMember() | |
158 let locallist: list<number> = [] | |
159 locallist[0] = 123 | |
160 let localdict: dict<number> = {} | |
161 localdict["a"] = 456 | |
162 enddef | |
163 | |
164 def Test_disassemble_store_member() | |
165 let res = execute('disass s:ScriptFuncStoreMember') | |
166 assert_match('<SNR>\d*_ScriptFuncStoreMember\_s*' .. | |
167 'let locallist: list<number> = []\_s*' .. | |
168 '\d NEWLIST size 0\_s*' .. | |
169 '\d STORE $0\_s*' .. | |
170 'locallist\[0\] = 123\_s*' .. | |
171 '\d PUSHNR 123\_s*' .. | |
172 '\d PUSHNR 0\_s*' .. | |
173 '\d LOAD $0\_s*' .. | |
174 '\d STORELIST\_s*' .. | |
175 'let localdict: dict<number> = {}\_s*' .. | |
176 '\d NEWDICT size 0\_s*' .. | |
177 '\d STORE $1\_s*' .. | |
178 'localdict\["a"\] = 456\_s*' .. | |
179 '\d\+ PUSHNR 456\_s*' .. | |
180 '\d\+ PUSHS "a"\_s*' .. | |
181 '\d\+ LOAD $1\_s*' .. | |
182 '\d\+ STOREDICT\_s*' .. | |
183 '\d\+ PUSHNR 0\_s*' .. | |
184 '\d\+ RETURN', | |
185 res) | |
186 enddef | |
187 | |
157 def s:ScriptFuncUnlet() | 188 def s:ScriptFuncUnlet() |
158 g:somevar = "value" | 189 g:somevar = "value" |
159 unlet g:somevar | 190 unlet g:somevar |
160 unlet! g:somevar | 191 unlet! g:somevar |
161 unlet $SOMEVAR | 192 unlet $SOMEVAR |
162 enddef | 193 enddef |
163 | 194 |
164 def Test_disassemble_unlet() | 195 def Test_disassemble_unlet() |
165 let res = execute('disass s:ScriptFuncUnlet') | 196 let res = execute('disass s:ScriptFuncUnlet') |
166 assert_match('<SNR>\d*_ScriptFuncUnlet.*' .. | 197 assert_match('<SNR>\d*_ScriptFuncUnlet\_s*' .. |
167 'g:somevar = "value".*' .. | 198 'g:somevar = "value"\_s*' .. |
168 '\d PUSHS "value".*' .. | 199 '\d PUSHS "value"\_s*' .. |
169 '\d STOREG g:somevar.*' .. | 200 '\d STOREG g:somevar\_s*' .. |
170 'unlet g:somevar.*' .. | 201 'unlet g:somevar\_s*' .. |
171 '\d UNLET g:somevar.*' .. | 202 '\d UNLET g:somevar\_s*' .. |
172 'unlet! g:somevar.*' .. | 203 'unlet! g:somevar\_s*' .. |
173 '\d UNLET! g:somevar.*' .. | 204 '\d UNLET! g:somevar\_s*' .. |
174 'unlet $SOMEVAR.*' .. | 205 'unlet $SOMEVAR\_s*' .. |
175 '\d UNLETENV $SOMEVAR.*', | 206 '\d UNLETENV $SOMEVAR\_s*', |
176 res) | 207 res) |
177 enddef | 208 enddef |
178 | 209 |
179 def s:ScriptFuncTry() | 210 def s:ScriptFuncTry() |
180 try | 211 try |
181 echo 'yes' | 212 echo "yes" |
182 catch /fail/ | 213 catch /fail/ |
183 echo 'no' | 214 echo "no" |
184 finally | 215 finally |
185 throw 'end' | 216 throw "end" |
186 endtry | 217 endtry |
187 enddef | 218 enddef |
188 | 219 |
189 def Test_disassemble_try() | 220 def Test_disassemble_try() |
190 let res = execute('disass s:ScriptFuncTry') | 221 let res = execute('disass s:ScriptFuncTry') |
191 assert_match('<SNR>\d*_ScriptFuncTry.*' .. | 222 assert_match('<SNR>\d*_ScriptFuncTry\_s*' .. |
192 'try.*' .. | 223 'try\_s*' .. |
193 'TRY catch -> \d\+, finally -> \d\+.*' .. | 224 '\d TRY catch -> \d\+, finally -> \d\+\_s*' .. |
194 'catch /fail/.*' .. | 225 'echo "yes"\_s*' .. |
195 ' JUMP -> \d\+.*' .. | 226 '\d PUSHS "yes"\_s*' .. |
196 ' PUSH v:exception.*' .. | 227 '\d ECHO 1\_s*' .. |
197 ' PUSHS "fail".*' .. | 228 'catch /fail/\_s*' .. |
198 ' COMPARESTRING =\~.*' .. | 229 '\d JUMP -> \d\+\_s*' .. |
199 ' JUMP_IF_FALSE -> \d\+.*' .. | 230 '\d PUSH v:exception\_s*' .. |
200 ' CATCH.*' .. | 231 '\d PUSHS "fail"\_s*' .. |
201 'finally.*' .. | 232 '\d COMPARESTRING =\~\_s*' .. |
202 ' PUSHS "end".*' .. | 233 '\d JUMP_IF_FALSE -> \d\+\_s*' .. |
203 ' THROW.*' .. | 234 '\d CATCH\_s*' .. |
204 'endtry.*' .. | 235 'echo "no"\_s*' .. |
205 ' ENDTRY.*', | 236 '\d\+ PUSHS "no"\_s*' .. |
237 '\d\+ ECHO 1\_s*' .. | |
238 'finally\_s*' .. | |
239 'throw "end"\_s*' .. | |
240 '\d\+ PUSHS "end"\_s*' .. | |
241 '\d\+ THROW\_s*' .. | |
242 'endtry\_s*' .. | |
243 '\d\+ ENDTRY', | |
206 res) | 244 res) |
207 enddef | 245 enddef |
208 | 246 |
209 def s:ScriptFuncNew() | 247 def s:ScriptFuncNew() |
210 let ll = [1, "two", 333] | 248 let ll = [1, "two", 333] |
211 let dd = #{one: 1, two: "val"} | 249 let dd = #{one: 1, two: "val"} |
212 enddef | 250 enddef |
213 | 251 |
214 def Test_disassemble_new() | 252 def Test_disassemble_new() |
215 let res = execute('disass s:ScriptFuncNew') | 253 let res = execute('disass s:ScriptFuncNew') |
216 assert_match('<SNR>\d*_ScriptFuncNew.*' .. | 254 assert_match('<SNR>\d*_ScriptFuncNew\_s*' .. |
217 'let ll = \[1, "two", 333].*' .. | 255 'let ll = \[1, "two", 333\]\_s*' .. |
218 'PUSHNR 1.*' .. | 256 '\d PUSHNR 1\_s*' .. |
219 'PUSHS "two".*' .. | 257 '\d PUSHS "two"\_s*' .. |
220 'PUSHNR 333.*' .. | 258 '\d PUSHNR 333\_s*' .. |
221 'NEWLIST size 3.*' .. | 259 '\d NEWLIST size 3\_s*' .. |
222 'let dd = #{one: 1, two: "val"}.*' .. | 260 '\d STORE $0\_s*' .. |
223 'PUSHS "one".*' .. | 261 'let dd = #{one: 1, two: "val"}\_s*' .. |
224 'PUSHNR 1.*' .. | 262 '\d PUSHS "one"\_s*' .. |
225 'PUSHS "two".*' .. | 263 '\d PUSHNR 1\_s*' .. |
226 'PUSHS "val".*' .. | 264 '\d PUSHS "two"\_s*' .. |
227 'NEWDICT size 2.*', | 265 '\d PUSHS "val"\_s*' .. |
266 '\d NEWDICT size 2\_s*', | |
228 res) | 267 res) |
229 enddef | 268 enddef |
230 | 269 |
231 def FuncWithArg(arg: any) | 270 def FuncWithArg(arg: any) |
232 echo arg | 271 echo arg |
256 return "yes" | 295 return "yes" |
257 enddef | 296 enddef |
258 | 297 |
259 def Test_disassemble_call() | 298 def Test_disassemble_call() |
260 let res = execute('disass s:ScriptFuncCall') | 299 let res = execute('disass s:ScriptFuncCall') |
261 assert_match('<SNR>\d\+_ScriptFuncCall.*' .. | 300 assert_match('<SNR>\d\+_ScriptFuncCall\_s*' .. |
262 'changenr().*' .. | 301 'changenr()\_s*' .. |
263 ' BCALL changenr(argc 0).*' .. | 302 '\d BCALL changenr(argc 0)\_s*' .. |
264 'char2nr("abc").*' .. | 303 '\d DROP\_s*' .. |
265 ' PUSHS "abc".*' .. | 304 'char2nr("abc")\_s*' .. |
266 ' BCALL char2nr(argc 1).*' .. | 305 '\d PUSHS "abc"\_s*' .. |
267 'Test_disassemble_new().*' .. | 306 '\d BCALL char2nr(argc 1)\_s*' .. |
268 ' DCALL Test_disassemble_new(argc 0).*' .. | 307 '\d DROP\_s*' .. |
269 'FuncWithArg(343).*' .. | 308 'Test_disassemble_new()\_s*' .. |
270 ' PUSHNR 343.*' .. | 309 '\d DCALL Test_disassemble_new(argc 0)\_s*' .. |
271 ' DCALL FuncWithArg(argc 1).*' .. | 310 '\d DROP\_s*' .. |
272 'ScriptFuncNew().*' .. | 311 'FuncWithArg(343)\_s*' .. |
273 ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' .. | 312 '\d\+ PUSHNR 343\_s*' .. |
274 's:ScriptFuncNew().*' .. | 313 '\d\+ DCALL FuncWithArg(argc 1)\_s*' .. |
275 ' DCALL <SNR>\d\+_ScriptFuncNew(argc 0).*' .. | 314 '\d\+ DROP\_s*' .. |
276 'UserFunc().*' .. | 315 'ScriptFuncNew()\_s*' .. |
277 ' UCALL UserFunc(argc 0).*' .. | 316 '\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' .. |
278 'UserFuncWithArg("foo").*' .. | 317 '\d\+ DROP\_s*' .. |
279 ' PUSHS "foo".*' .. | 318 's:ScriptFuncNew()\_s*' .. |
280 ' UCALL UserFuncWithArg(argc 1).*' .. | 319 '\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' .. |
281 'let FuncRef = function("UserFunc").*' .. | 320 '\d\+ DROP\_s*' .. |
282 'FuncRef().*' .. | 321 'UserFunc()\_s*' .. |
283 ' LOAD $\d.*' .. | 322 '\d\+ UCALL UserFunc(argc 0)\_s*' .. |
284 ' PCALL (argc 0).*' .. | 323 '\d\+ DROP\_s*' .. |
285 'let FuncRefWithArg = function("UserFuncWithArg").*' .. | 324 'UserFuncWithArg("foo")\_s*' .. |
286 'FuncRefWithArg("bar").*' .. | 325 '\d\+ PUSHS "foo"\_s*' .. |
287 ' PUSHS "bar".*' .. | 326 '\d\+ UCALL UserFuncWithArg(argc 1)\_s*' .. |
288 ' LOAD $\d.*' .. | 327 '\d\+ DROP\_s*' .. |
289 ' PCALL (argc 1).*' .. | 328 'let FuncRef = function("UserFunc")\_s*' .. |
290 'return "yes".*' .. | 329 '\d\+ PUSHS "UserFunc"\_s*' .. |
291 ' PUSHS "yes".*' .. | 330 '\d\+ BCALL function(argc 1)\_s*' .. |
292 ' RETURN.*', | 331 '\d\+ STORE $0\_s*' .. |
332 'FuncRef()\_s*' .. | |
333 '\d\+ LOAD $\d\_s*' .. | |
334 '\d\+ PCALL (argc 0)\_s*' .. | |
335 '\d\+ DROP\_s*' .. | |
336 'let FuncRefWithArg = function("UserFuncWithArg")\_s*' .. | |
337 '\d\+ PUSHS "UserFuncWithArg"\_s*' .. | |
338 '\d\+ BCALL function(argc 1)\_s*' .. | |
339 '\d\+ STORE $1\_s*' .. | |
340 'FuncRefWithArg("bar")\_s*' .. | |
341 '\d\+ PUSHS "bar"\_s*' .. | |
342 '\d\+ LOAD $\d\_s*' .. | |
343 '\d\+ PCALL (argc 1)\_s*' .. | |
344 '\d\+ DROP\_s*' .. | |
345 'return "yes"\_s*' .. | |
346 '\d\+ PUSHS "yes"\_s*' .. | |
347 '\d\+ RETURN', | |
293 res) | 348 res) |
294 enddef | 349 enddef |
295 | 350 |
296 def s:CreateRefs() | 351 def s:CreateRefs() |
297 let local = 'a' | 352 let local = 'a' |
306 enddef | 361 enddef |
307 | 362 |
308 def Test_disassemble_closure() | 363 def Test_disassemble_closure() |
309 CreateRefs() | 364 CreateRefs() |
310 let res = execute('disass g:Append') | 365 let res = execute('disass g:Append') |
311 assert_match('<lambda>\d.*' .. | 366 assert_match('<lambda>\d\_s*' .. |
312 'local ..= arg.*' .. | 367 'local ..= arg\_s*' .. |
313 '\d LOADOUTER $0.*' .. | 368 '\d LOADOUTER $0\_s*' .. |
314 '\d LOAD arg\[-1\].*' .. | 369 '\d LOAD arg\[-1\]\_s*' .. |
315 '\d CONCAT.*' .. | 370 '\d CONCAT\_s*' .. |
316 '\d STOREOUTER $0.*' .. | 371 '\d STOREOUTER $0\_s*' .. |
317 '\d PUSHNR 0.*' .. | 372 '\d PUSHNR 0\_s*' .. |
318 '\d RETURN.*', | 373 '\d RETURN', |
319 res) | 374 res) |
320 | 375 |
321 res = execute('disass g:Get') | 376 res = execute('disass g:Get') |
322 assert_match('<lambda>\d.*' .. | 377 assert_match('<lambda>\d\_s*' .. |
323 'return local.*' .. | 378 'return local\_s*' .. |
324 '\d LOADOUTER $0.*' .. | 379 '\d LOADOUTER $0\_s*' .. |
325 '\d RETURN.*', | 380 '\d RETURN', |
326 res) | 381 res) |
327 | 382 |
328 unlet g:Append | 383 unlet g:Append |
329 unlet g:Get | 384 unlet g:Get |
330 enddef | 385 enddef |
340 RefThis()("text") | 395 RefThis()("text") |
341 enddef | 396 enddef |
342 | 397 |
343 def Test_disassemble_pcall() | 398 def Test_disassemble_pcall() |
344 let res = execute('disass s:ScriptPCall') | 399 let res = execute('disass s:ScriptPCall') |
345 assert_match('<SNR>\d\+_ScriptPCall.*' .. | 400 assert_match('<SNR>\d\+_ScriptPCall\_s*' .. |
346 'RefThis()("text").*' .. | 401 'RefThis()("text")\_s*' .. |
347 '\d DCALL RefThis(argc 0).*' .. | 402 '\d DCALL RefThis(argc 0)\_s*' .. |
348 '\d PUSHS "text".*' .. | 403 '\d PUSHS "text"\_s*' .. |
349 '\d PCALL top (argc 1).*' .. | 404 '\d PCALL top (argc 1)\_s*' .. |
350 '\d PCALL end.*' .. | 405 '\d PCALL end\_s*' .. |
351 '\d DROP.*' .. | 406 '\d DROP\_s*' .. |
352 '\d PUSHNR 0.*' .. | 407 '\d PUSHNR 0\_s*' .. |
353 '\d RETURN.*', | 408 '\d RETURN', |
354 res) | 409 res) |
355 enddef | 410 enddef |
356 | 411 |
357 | 412 |
358 def s:FuncWithForwardCall(): string | 413 def s:FuncWithForwardCall(): string |
363 return arg | 418 return arg |
364 enddef | 419 enddef |
365 | 420 |
366 def Test_disassemble_update_instr() | 421 def Test_disassemble_update_instr() |
367 let res = execute('disass s:FuncWithForwardCall') | 422 let res = execute('disass s:FuncWithForwardCall') |
368 assert_match('FuncWithForwardCall.*' .. | 423 assert_match('FuncWithForwardCall\_s*' .. |
369 'return g:DefinedLater("yes").*' .. | 424 'return g:DefinedLater("yes")\_s*' .. |
370 '\d PUSHS "yes".*' .. | 425 '\d PUSHS "yes"\_s*' .. |
371 '\d UCALL g:DefinedLater(argc 1).*' .. | 426 '\d UCALL g:DefinedLater(argc 1)\_s*' .. |
372 '\d CHECKTYPE string stack\[-1].*' .. | 427 '\d CHECKTYPE string stack\[-1]\_s*' .. |
373 '\d RETURN.*', | 428 '\d RETURN', |
374 res) | 429 res) |
375 | 430 |
376 " Calling the function will change UCALL into the faster DCALL | 431 " Calling the function will change UCALL into the faster DCALL |
377 assert_equal('yes', FuncWithForwardCall()) | 432 assert_equal('yes', FuncWithForwardCall()) |
378 | 433 |
379 res = execute('disass s:FuncWithForwardCall') | 434 res = execute('disass s:FuncWithForwardCall') |
380 assert_match('FuncWithForwardCall.*' .. | 435 assert_match('FuncWithForwardCall\_s*' .. |
381 'return g:DefinedLater("yes").*' .. | 436 'return g:DefinedLater("yes")\_s*' .. |
382 '\d PUSHS "yes".*' .. | 437 '\d PUSHS "yes"\_s*' .. |
383 '\d DCALL DefinedLater(argc 1).*' .. | 438 '\d DCALL DefinedLater(argc 1)\_s*' .. |
384 '\d CHECKTYPE string stack\[-1].*' .. | 439 '\d CHECKTYPE string stack\[-1]\_s*' .. |
385 '\d RETURN.*', | 440 '\d RETURN', |
386 res) | 441 res) |
387 enddef | 442 enddef |
388 | 443 |
389 | 444 |
390 def FuncWithDefault(arg: string = 'default'): string | 445 def FuncWithDefault(arg: string = 'default'): string |
391 return arg | 446 return arg |
392 enddef | 447 enddef |
393 | 448 |
394 def Test_disassemble_call_default() | 449 def Test_disassemble_call_default() |
395 let res = execute('disass FuncWithDefault') | 450 let res = execute('disass FuncWithDefault') |
396 assert_match('FuncWithDefault.*' .. | 451 assert_match('FuncWithDefault\_s*' .. |
397 '\d PUSHS "default".*' .. | 452 '\d PUSHS "default"\_s*' .. |
398 '\d STORE arg\[-1].*' .. | 453 '\d STORE arg\[-1]\_s*' .. |
399 'return arg.*' .. | 454 'return arg\_s*' .. |
400 '\d LOAD arg\[-1].*' .. | 455 '\d LOAD arg\[-1]\_s*' .. |
401 '\d RETURN.*', | 456 '\d RETURN', |
402 res) | 457 res) |
403 enddef | 458 enddef |
404 | 459 |
405 | 460 |
406 def HasEval() | 461 def HasEval() |
432 enddef | 487 enddef |
433 | 488 |
434 def Test_disassemble_const_expr() | 489 def Test_disassemble_const_expr() |
435 assert_equal("\nyes", execute('call HasEval()')) | 490 assert_equal("\nyes", execute('call HasEval()')) |
436 let instr = execute('disassemble HasEval') | 491 let instr = execute('disassemble HasEval') |
437 assert_match('HasEval.*' .. | 492 assert_match('HasEval\_s*' .. |
438 'if has("eval").*' .. | 493 'if has("eval")\_s*' .. |
439 ' PUSHS "yes".*', | 494 'echo "yes"\_s*' .. |
495 '\d PUSHS "yes"\_s*' .. | |
496 '\d ECHO 1\_s*' .. | |
497 'else\_s*' .. | |
498 'echo "no"\_s*' .. | |
499 'endif\_s*', | |
440 instr) | 500 instr) |
441 assert_notmatch('JUMP', instr) | 501 assert_notmatch('JUMP', instr) |
442 | 502 |
443 assert_equal("\nno", execute('call HasNothing()')) | 503 assert_equal("\nno", execute('call HasNothing()')) |
444 instr = execute('disassemble HasNothing') | 504 instr = execute('disassemble HasNothing') |
445 assert_match('HasNothing.*' .. | 505 assert_match('HasNothing\_s*' .. |
446 'if has("nothing").*' .. | 506 'if has("nothing")\_s*' .. |
447 'else.*' .. | 507 'echo "yes"\_s*' .. |
448 ' PUSHS "no".*', | 508 'else\_s*' .. |
509 'echo "no"\_s*' .. | |
510 '\d PUSHS "no"\_s*' .. | |
511 '\d ECHO 1\_s*' .. | |
512 'endif', | |
449 instr) | 513 instr) |
450 assert_notmatch('PUSHS "yes"', instr) | 514 assert_notmatch('PUSHS "yes"', instr) |
451 assert_notmatch('JUMP', instr) | 515 assert_notmatch('JUMP', instr) |
452 | 516 |
453 assert_equal("\neval", execute('call HasSomething()')) | 517 assert_equal("\neval", execute('call HasSomething()')) |
454 instr = execute('disassemble HasSomething') | 518 instr = execute('disassemble HasSomething') |
455 assert_match('HasSomething.*' .. | 519 assert_match('HasSomething.*' .. |
456 'if has("nothing").*' .. | 520 'if has("nothing")\_s*' .. |
457 'elseif has("something").*' .. | 521 'echo "nothing"\_s*' .. |
458 'elseif has("eval").*' .. | 522 'elseif has("something")\_s*' .. |
459 ' PUSHS "eval".*' .. | 523 'echo "something"\_s*' .. |
460 'elseif has("less").*', | 524 'elseif has("eval")\_s*' .. |
525 'echo "eval"\_s*' .. | |
526 '\d PUSHS "eval"\_s*' .. | |
527 '\d ECHO 1\_s*' .. | |
528 'elseif has("less").*' .. | |
529 'echo "less"\_s*' .. | |
530 'endif', | |
461 instr) | 531 instr) |
462 assert_notmatch('PUSHS "nothing"', instr) | 532 assert_notmatch('PUSHS "nothing"', instr) |
463 assert_notmatch('PUSHS "something"', instr) | 533 assert_notmatch('PUSHS "something"', instr) |
464 assert_notmatch('PUSHS "less"', instr) | 534 assert_notmatch('PUSHS "less"', instr) |
465 assert_notmatch('JUMP', instr) | 535 assert_notmatch('JUMP', instr) |
471 let Party2: func = funcref("UserFunc") | 541 let Party2: func = funcref("UserFunc") |
472 enddef | 542 enddef |
473 | 543 |
474 def Test_disassemble_function() | 544 def Test_disassemble_function() |
475 let instr = execute('disassemble WithFunc') | 545 let instr = execute('disassemble WithFunc') |
476 assert_match('WithFunc.*' .. | 546 assert_match('WithFunc\_s*' .. |
477 'let Funky1: func.*' .. | 547 'let Funky1: func\_s*' .. |
478 '0 PUSHFUNC "\[none]".*' .. | 548 '0 PUSHFUNC "\[none]"\_s*' .. |
479 '1 STORE $0.*' .. | 549 '1 STORE $0\_s*' .. |
480 'let Funky2: func = function("len").*' .. | 550 'let Funky2: func = function("len")\_s*' .. |
481 '2 PUSHS "len".*' .. | 551 '2 PUSHS "len"\_s*' .. |
482 '3 BCALL function(argc 1).*' .. | 552 '3 BCALL function(argc 1)\_s*' .. |
483 '4 STORE $1.*' .. | 553 '4 STORE $1\_s*' .. |
484 'let Party2: func = funcref("UserFunc").*' .. | 554 'let Party2: func = funcref("UserFunc")\_s*' .. |
485 '\d PUSHS "UserFunc".*' .. | 555 '\d PUSHS "UserFunc"\_s*' .. |
486 '\d BCALL funcref(argc 1).*' .. | 556 '\d BCALL funcref(argc 1)\_s*' .. |
487 '\d STORE $2.*' .. | 557 '\d STORE $2\_s*' .. |
488 '\d PUSHNR 0.*' .. | 558 '\d PUSHNR 0\_s*' .. |
489 '\d RETURN.*', | 559 '\d RETURN', |
490 instr) | 560 instr) |
491 enddef | 561 enddef |
492 | 562 |
493 if has('channel') | 563 if has('channel') |
494 def WithChannel() | 564 def WithChannel() |
500 | 570 |
501 def Test_disassemble_channel() | 571 def Test_disassemble_channel() |
502 CheckFeature channel | 572 CheckFeature channel |
503 | 573 |
504 let instr = execute('disassemble WithChannel') | 574 let instr = execute('disassemble WithChannel') |
505 assert_match('WithChannel.*' .. | 575 assert_match('WithChannel\_s*' .. |
506 'let job1: job.*' .. | 576 'let job1: job\_s*' .. |
507 '\d PUSHJOB "no process".*' .. | 577 '\d PUSHJOB "no process"\_s*' .. |
508 '\d STORE $0.*' .. | 578 '\d STORE $0\_s*' .. |
509 'let job2: job = job_start("donothing").*' .. | 579 'let job2: job = job_start("donothing")\_s*' .. |
510 '\d PUSHS "donothing".*' .. | 580 '\d PUSHS "donothing"\_s*' .. |
511 '\d BCALL job_start(argc 1).*' .. | 581 '\d BCALL job_start(argc 1)\_s*' .. |
512 '\d STORE $1.*' .. | 582 '\d STORE $1\_s*' .. |
513 'let chan1: channel.*' .. | 583 'let chan1: channel\_s*' .. |
514 '\d PUSHCHANNEL 0.*' .. | 584 '\d PUSHCHANNEL 0\_s*' .. |
515 '\d STORE $2.*' .. | 585 '\d STORE $2\_s*' .. |
516 '\d PUSHNR 0.*' .. | 586 '\d PUSHNR 0\_s*' .. |
517 '\d RETURN.*', | 587 '\d RETURN', |
518 instr) | 588 instr) |
519 enddef | 589 enddef |
520 | 590 |
521 def WithLambda(): string | 591 def WithLambda(): string |
522 let F = {a -> "X" .. a .. "X"} | 592 let F = {a -> "X" .. a .. "X"} |
524 enddef | 594 enddef |
525 | 595 |
526 def Test_disassemble_lambda() | 596 def Test_disassemble_lambda() |
527 assert_equal("XxX", WithLambda()) | 597 assert_equal("XxX", WithLambda()) |
528 let instr = execute('disassemble WithLambda') | 598 let instr = execute('disassemble WithLambda') |
529 assert_match('WithLambda.*' .. | 599 assert_match('WithLambda\_s*' .. |
530 'let F = {a -> "X" .. a .. "X"}.*' .. | 600 'let F = {a -> "X" .. a .. "X"}\_s*' .. |
531 ' FUNCREF <lambda>\d\+.*' .. | 601 '\d FUNCREF <lambda>\d\+ $1\_s*' .. |
532 'PUSHS "x".*' .. | 602 '\d STORE $0\_s*' .. |
533 ' LOAD $0.*' .. | 603 'return F("x")\_s*' .. |
534 ' PCALL (argc 1).*' .. | 604 '\d PUSHS "x"\_s*' .. |
535 ' CHECKTYPE string stack\[-1].*', | 605 '\d LOAD $0\_s*' .. |
606 '\d PCALL (argc 1)\_s*' .. | |
607 '\d CHECKTYPE string stack\[-1]', | |
536 instr) | 608 instr) |
537 enddef | 609 enddef |
538 | 610 |
539 def AndOr(arg: any): string | 611 def AndOr(arg: any): string |
540 if arg == 1 && arg != 2 || arg == 4 | 612 if arg == 1 && arg != 2 || arg == 4 |
546 def Test_disassemble_and_or() | 618 def Test_disassemble_and_or() |
547 assert_equal("yes", AndOr(1)) | 619 assert_equal("yes", AndOr(1)) |
548 assert_equal("no", AndOr(2)) | 620 assert_equal("no", AndOr(2)) |
549 assert_equal("yes", AndOr(4)) | 621 assert_equal("yes", AndOr(4)) |
550 let instr = execute('disassemble AndOr') | 622 let instr = execute('disassemble AndOr') |
551 assert_match('AndOr.*' .. | 623 assert_match('AndOr\_s*' .. |
552 'if arg == 1 && arg != 2 || arg == 4.*' .. | 624 'if arg == 1 && arg != 2 || arg == 4\_s*' .. |
553 '\d LOAD arg\[-1].*' .. | 625 '\d LOAD arg\[-1]\_s*' .. |
554 '\d PUSHNR 1.*' .. | 626 '\d PUSHNR 1\_s*' .. |
555 '\d COMPAREANY ==.*' .. | 627 '\d COMPAREANY ==\_s*' .. |
556 '\d JUMP_AND_KEEP_IF_FALSE -> \d\+.*' .. | 628 '\d JUMP_AND_KEEP_IF_FALSE -> \d\+\_s*' .. |
557 '\d LOAD arg\[-1].*' .. | 629 '\d LOAD arg\[-1]\_s*' .. |
558 '\d PUSHNR 2.*' .. | 630 '\d PUSHNR 2\_s*' .. |
559 '\d COMPAREANY !=.*' .. | 631 '\d COMPAREANY !=\_s*' .. |
560 '\d JUMP_AND_KEEP_IF_TRUE -> \d\+.*' .. | 632 '\d JUMP_AND_KEEP_IF_TRUE -> \d\+\_s*' .. |
561 '\d LOAD arg\[-1].*' .. | 633 '\d LOAD arg\[-1]\_s*' .. |
562 '\d PUSHNR 4.*' .. | 634 '\d\+ PUSHNR 4\_s*' .. |
563 '\d COMPAREANY ==.*' .. | 635 '\d\+ COMPAREANY ==\_s*' .. |
564 '\d JUMP_IF_FALSE -> \d\+.*', | 636 '\d\+ JUMP_IF_FALSE -> \d\+', |
565 instr) | 637 instr) |
566 enddef | 638 enddef |
567 | 639 |
568 def ForLoop(): list<number> | 640 def ForLoop(): list<number> |
569 let res: list<number> | 641 let res: list<number> |
574 enddef | 646 enddef |
575 | 647 |
576 def Test_disassemble_for_loop() | 648 def Test_disassemble_for_loop() |
577 assert_equal([0, 1, 2], ForLoop()) | 649 assert_equal([0, 1, 2], ForLoop()) |
578 let instr = execute('disassemble ForLoop') | 650 let instr = execute('disassemble ForLoop') |
579 assert_match('ForLoop.*' .. | 651 assert_match('ForLoop\_s*' .. |
580 'let res: list<number>.*' .. | 652 'let res: list<number>\_s*' .. |
581 ' NEWLIST size 0.*' .. | 653 '\d NEWLIST size 0\_s*' .. |
582 '\d STORE $0.*' .. | 654 '\d STORE $0\_s*' .. |
583 'for i in range(3).*' .. | 655 'for i in range(3)\_s*' .. |
584 '\d STORE -1 in $1.*' .. | 656 '\d STORE -1 in $1\_s*' .. |
585 '\d PUSHNR 3.*' .. | 657 '\d PUSHNR 3\_s*' .. |
586 '\d BCALL range(argc 1).*' .. | 658 '\d BCALL range(argc 1)\_s*' .. |
587 '\d FOR $1 -> \d\+.*' .. | 659 '\d FOR $1 -> \d\+\_s*' .. |
588 '\d STORE $2.*' .. | 660 '\d STORE $2\_s*' .. |
589 'res->add(i).*' .. | 661 'res->add(i)\_s*' .. |
590 '\d LOAD $0.*' .. | 662 '\d LOAD $0\_s*' .. |
591 '\d LOAD $2.*' .. | 663 '\d LOAD $2\_s*' .. |
592 '\d BCALL add(argc 2).*' .. | 664 '\d\+ BCALL add(argc 2)\_s*' .. |
593 '\d DROP.*' .. | 665 '\d\+ DROP\_s*' .. |
594 'endfor.*' .. | 666 'endfor\_s*' .. |
595 '\d JUMP -> \d\+.*' .. | 667 '\d\+ JUMP -> \d\+\_s*' .. |
596 '\d DROP.*', | 668 '\d\+ DROP', |
597 instr) | 669 instr) |
598 enddef | 670 enddef |
599 | 671 |
600 let g:number = 42 | 672 let g:number = 42 |
601 | 673 |