diff options
Diffstat (limited to '')
-rw-r--r-- | src/testdir/test_vim9_disassemble.vim | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim index 1a192cc..1daef22 100644 --- a/src/testdir/test_vim9_disassemble.vim +++ b/src/testdir/test_vim9_disassemble.vim @@ -3273,4 +3273,199 @@ def Test_funcref_with_class() unlet g:instr enddef +" Disassemble instructions for calls to a string() function in an object +def Test_disassemble_object_string() + var lines =<< trim END + vim9script + class A + def string(): string + return 'A' + enddef + endclass + def Bar() + var a = A.new() + var s = string(a) + s = string(A) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = string(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 METHODCALL A.string(argc 0)\_s*' .. + '4 STORE $1\_s*' .. + 's = string(A)\_s*' .. + '5 LOADSCRIPT A-0 from .*\_s*' .. + '6 BCALL string(argc 1)\_s*' .. + '7 STORE $1\_s*' .. + '8 RETURN void', g:instr) + unlet g:instr + + # Use the default string() function for a class + lines =<< trim END + vim9script + class A + endclass + def Bar() + var a = A.new() + var s = string(a) + s = string(A) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = string(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 BCALL string(argc 1)\_s*' .. + '4 STORE $1\_s*' .. + 's = string(A)\_s*' .. + '5 LOADSCRIPT A-0 from .*\_s*' .. + '6 BCALL string(argc 1)\_s*' .. + '7 STORE $1\_s*' .. + '8 RETURN void', g:instr) + unlet g:instr +enddef + +" Disassemble instructions for calls to a empty() function in an object +def Test_disassemble_object_empty() + var lines =<< trim END + vim9script + class A + def empty(): bool + return true + enddef + endclass + def Bar() + var a = A.new() + var s = empty(a) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = empty(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 METHODCALL A.empty(argc 0)\_s*' .. + '4 STORE $1\_s*' .. + '5 RETURN void', g:instr) + unlet g:instr + + # Use the default empty() function for a class + lines =<< trim END + vim9script + class A + endclass + def Bar() + var a = A.new() + var s = empty(a) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = empty(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 BCALL empty(argc 1)\_s*' .. + '4 STORE $1\_s*' .. + '5 RETURN void', g:instr) + unlet g:instr +enddef + +" Disassemble instructions for calls to a len() function in an object +def Test_disassemble_object_len() + var lines =<< trim END + vim9script + class A + def len(): number + return 10 + enddef + endclass + def Bar() + var a = A.new() + var s = len(a) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = len(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 METHODCALL A.len(argc 0)\_s*' .. + '4 STORE $1\_s*' .. + '5 RETURN void', g:instr) + unlet g:instr + + # Use the default len() function for a class + lines =<< trim END + vim9script + class A + endclass + def Bar() + var a = A.new() + var s = len(a) + enddef + g:instr = execute('disassemble Bar') + END + v9.CheckScriptSuccess(lines) + assert_match('<SNR>\d*_Bar\_s*' .. + 'var a = A.new()\_s*' .. + '0 DCALL new(argc 0)\_s*' .. + '1 STORE $0\_s*' .. + 'var s = len(a)\_s*' .. + '2 LOAD $0\_s*' .. + '3 BCALL len(argc 1)\_s*' .. + '4 STORE $1\_s*' .. + '5 RETURN void', g:instr) + unlet g:instr +enddef + +" Disassemble instructions for using a compound operator in a closure +def Test_disassemble_compound_op_in_closure() + var lines =<< trim END + vim9script + class A + var foo: number = 1 + def Foo(): func + var Fn = () => { + this.foo += 1 + } + return Fn + enddef + endclass + var a = A.new() + var Lambda = a.Foo() + var num = matchstr(string(Lambda), '\d\+') + g:instr = execute($'disassemble <lambda>{num}') + END + v9.CheckScriptSuccess(lines) + assert_match('<lambda>\d\+\_s*' .. + 'this.foo += 1\_s*' .. + '0 LOADOUTER level 0 $0\_s*' .. + '1 OBJ_MEMBER 0\_s*' .. + '2 PUSHNR 1\_s*' .. + '3 OPNR +\_s*' .. + '4 PUSHNR 0\_s*' .. + '5 LOADOUTER level 0 $0\_s*' .. + '6 STOREINDEX object\_s*' .. + '7 RETURN void', g:instr) + unlet g:instr +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |