comparison src/testdir/test_vim9_disassemble.vim @ 34472:5c1a025192ed v9.1.0148

patch 9.1.0148: Vim9: can't call internal methods with objects Commit: https://github.com/vim/vim/commit/d3eae7bc116297f70220f21ded436ed0a88066d8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Mar 3 16:26:58 2024 +0100 patch 9.1.0148: Vim9: can't call internal methods with objects Problem: Vim9: can't call internal methods with objects Solution: Add support for empty(), len() and string() function calls for objects (Yegappan Lakshmanan) closes: #14129 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Mar 2024 16:45:06 +0100
parents ab6a70fad5b5
children 7ff3c277377f
comparison
equal deleted inserted replaced
34471:7f6302969e3d 34472:5c1a025192ed
3271 '2 DEFER 0 args\_s*' .. 3271 '2 DEFER 0 args\_s*' ..
3272 '3 RETURN void', g:instr) 3272 '3 RETURN void', g:instr)
3273 unlet g:instr 3273 unlet g:instr
3274 enddef 3274 enddef
3275 3275
3276 " Disassemble instructions for calls to a string() function in an object
3277 def Test_disassemble_object_string()
3278 var lines =<< trim END
3279 vim9script
3280 class A
3281 def string(): string
3282 return 'A'
3283 enddef
3284 endclass
3285 def Bar()
3286 var a = A.new()
3287 var s = string(a)
3288 s = string(A)
3289 enddef
3290 g:instr = execute('disassemble Bar')
3291 END
3292 v9.CheckScriptSuccess(lines)
3293 assert_match('<SNR>\d*_Bar\_s*' ..
3294 'var a = A.new()\_s*' ..
3295 '0 DCALL new(argc 0)\_s*' ..
3296 '1 STORE $0\_s*' ..
3297 'var s = string(a)\_s*' ..
3298 '2 LOAD $0\_s*' ..
3299 '3 METHODCALL A.string(argc 0)\_s*' ..
3300 '4 STORE $1\_s*' ..
3301 's = string(A)\_s*' ..
3302 '5 LOADSCRIPT A-0 from .*\_s*' ..
3303 '6 BCALL string(argc 1)\_s*' ..
3304 '7 STORE $1\_s*' ..
3305 '8 RETURN void', g:instr)
3306 unlet g:instr
3307
3308 # Use the default string() function for a class
3309 lines =<< trim END
3310 vim9script
3311 class A
3312 endclass
3313 def Bar()
3314 var a = A.new()
3315 var s = string(a)
3316 s = string(A)
3317 enddef
3318 g:instr = execute('disassemble Bar')
3319 END
3320 v9.CheckScriptSuccess(lines)
3321 assert_match('<SNR>\d*_Bar\_s*' ..
3322 'var a = A.new()\_s*' ..
3323 '0 DCALL new(argc 0)\_s*' ..
3324 '1 STORE $0\_s*' ..
3325 'var s = string(a)\_s*' ..
3326 '2 LOAD $0\_s*' ..
3327 '3 BCALL string(argc 1)\_s*' ..
3328 '4 STORE $1\_s*' ..
3329 's = string(A)\_s*' ..
3330 '5 LOADSCRIPT A-0 from .*\_s*' ..
3331 '6 BCALL string(argc 1)\_s*' ..
3332 '7 STORE $1\_s*' ..
3333 '8 RETURN void', g:instr)
3334 unlet g:instr
3335 enddef
3336
3337 " Disassemble instructions for calls to a empty() function in an object
3338 def Test_disassemble_object_empty()
3339 var lines =<< trim END
3340 vim9script
3341 class A
3342 def empty(): bool
3343 return true
3344 enddef
3345 endclass
3346 def Bar()
3347 var a = A.new()
3348 var s = empty(a)
3349 enddef
3350 g:instr = execute('disassemble Bar')
3351 END
3352 v9.CheckScriptSuccess(lines)
3353 assert_match('<SNR>\d*_Bar\_s*' ..
3354 'var a = A.new()\_s*' ..
3355 '0 DCALL new(argc 0)\_s*' ..
3356 '1 STORE $0\_s*' ..
3357 'var s = empty(a)\_s*' ..
3358 '2 LOAD $0\_s*' ..
3359 '3 METHODCALL A.empty(argc 0)\_s*' ..
3360 '4 STORE $1\_s*' ..
3361 '5 RETURN void', g:instr)
3362 unlet g:instr
3363
3364 # Use the default empty() function for a class
3365 lines =<< trim END
3366 vim9script
3367 class A
3368 endclass
3369 def Bar()
3370 var a = A.new()
3371 var s = empty(a)
3372 enddef
3373 g:instr = execute('disassemble Bar')
3374 END
3375 v9.CheckScriptSuccess(lines)
3376 assert_match('<SNR>\d*_Bar\_s*' ..
3377 'var a = A.new()\_s*' ..
3378 '0 DCALL new(argc 0)\_s*' ..
3379 '1 STORE $0\_s*' ..
3380 'var s = empty(a)\_s*' ..
3381 '2 LOAD $0\_s*' ..
3382 '3 BCALL empty(argc 1)\_s*' ..
3383 '4 STORE $1\_s*' ..
3384 '5 RETURN void', g:instr)
3385 unlet g:instr
3386 enddef
3387
3388 " Disassemble instructions for calls to a len() function in an object
3389 def Test_disassemble_object_len()
3390 var lines =<< trim END
3391 vim9script
3392 class A
3393 def len(): number
3394 return 10
3395 enddef
3396 endclass
3397 def Bar()
3398 var a = A.new()
3399 var s = len(a)
3400 enddef
3401 g:instr = execute('disassemble Bar')
3402 END
3403 v9.CheckScriptSuccess(lines)
3404 assert_match('<SNR>\d*_Bar\_s*' ..
3405 'var a = A.new()\_s*' ..
3406 '0 DCALL new(argc 0)\_s*' ..
3407 '1 STORE $0\_s*' ..
3408 'var s = len(a)\_s*' ..
3409 '2 LOAD $0\_s*' ..
3410 '3 METHODCALL A.len(argc 0)\_s*' ..
3411 '4 STORE $1\_s*' ..
3412 '5 RETURN void', g:instr)
3413 unlet g:instr
3414
3415 # Use the default len() function for a class
3416 lines =<< trim END
3417 vim9script
3418 class A
3419 endclass
3420 def Bar()
3421 var a = A.new()
3422 var s = len(a)
3423 enddef
3424 g:instr = execute('disassemble Bar')
3425 END
3426 v9.CheckScriptSuccess(lines)
3427 assert_match('<SNR>\d*_Bar\_s*' ..
3428 'var a = A.new()\_s*' ..
3429 '0 DCALL new(argc 0)\_s*' ..
3430 '1 STORE $0\_s*' ..
3431 'var s = len(a)\_s*' ..
3432 '2 LOAD $0\_s*' ..
3433 '3 BCALL len(argc 1)\_s*' ..
3434 '4 STORE $1\_s*' ..
3435 '5 RETURN void', g:instr)
3436 unlet g:instr
3437 enddef
3438
3276 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 3439 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker