# HG changeset patch # User pt # Date 1686820297 -7200 # Thu Jun 15 11:11:37 2023 +0200 # Node ID 4748b6302e99f4c1532679e2e08735beb5fe923e # Parent 59681cc864e761c3470894575d6857f99148543d Fixed varargin bug in VM * libinterp/parse-tree/pt-bytecode-vm.cc: Expand cs-lists into arguments properly * test/compile/bytecode.tst: Updated tests * test/compile/bytecode_varargin.m diff -r 59681cc864e7 -r 4748b6302e99 libinterp/parse-tree/pt-bytecode-vm.cc --- a/libinterp/parse-tree/pt-bytecode-vm.cc Fri Jun 23 20:51:51 2023 +0200 +++ b/libinterp/parse-tree/pt-bytecode-vm.cc Thu Jun 15 11:11:37 2023 +0200 @@ -4112,7 +4112,7 @@ { cs_args = arg.list_value (); cs_args_idx = 0; - for (int j = 0; j < cs_args.length () && n_args_on_callee_stack < n_args_before_varargin; j++) + for (int j = 0; j < cs_args.length () && n_args_on_callee_stack < n_args_callee - 1; j++) { PUSH_OV (cs_args (j)); n_args_on_callee_stack++; diff -r 59681cc864e7 -r 4748b6302e99 test/compile/bytecode.tst --- a/test/compile/bytecode.tst Fri Jun 23 20:51:51 2023 +0200 +++ b/test/compile/bytecode.tst Thu Jun 15 11:11:37 2023 +0200 @@ -283,12 +283,12 @@ %!test %! __enable_vm_eval__ (0, "local"); %! clear all -%! key = "2 3 1 2 1 1 1 1 1 2 3 4 1 4 4 0 0 0 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 0 0 1 0 0 0 2 1 1 1 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 2 1 2 4 1 2 3 4 3 3 2 1 0 "; +%! key = "2 3 1 2 1 1 1 1 1 2 3 4 1 4 4 0 0 0 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 0 0 1 0 0 0 2 1 1 1 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 2 1 2 4 1 2 0 0 2 1 nob 0 0 1 noa nob 0 0 0 2 1 2 4 1 2 3 4 3 3 2 1 0 "; %! %! __compile bytecode_varargin clear; %! bytecode_varargin (1,2,3); %! assert (__prog_output_assert__ (key)); -%! +%! %! __enable_vm_eval__ (1, "local"); %! assert (__compile ("bytecode_varargin")); %! bytecode_varargin (1,2,3); @@ -296,7 +296,7 @@ %! %! __enable_vm_eval__ (0, "local"); %! clear all -%! key = "0 0 1 1 1 1 1 2 3 4 1 4 4 0 0 0 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 0 0 1 0 0 0 2 1 1 1 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 2 1 2 4 1 2 3 4 1 3 2 1 0 "; +%! key = "0 0 1 1 1 1 1 2 3 4 1 4 4 0 0 0 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 0 0 1 0 0 0 2 1 1 1 1 2 3 4 1 3 4 2 3 4 1 3 3 2 2 3 4 1 4 4 1 2 1 2 4 1 2 0 0 2 1 nob 0 0 1 noa nob 0 0 0 2 1 2 4 1 2 3 4 1 3 2 1 0 "; %! %! __compile bytecode_varargin clear; %! bytecode_varargin (1); diff -r 59681cc864e7 -r 4748b6302e99 test/compile/bytecode_varargin.m --- a/test/compile/bytecode_varargin.m Fri Jun 23 20:51:51 2023 +0200 +++ b/test/compile/bytecode_varargin.m Thu Jun 15 11:11:37 2023 +0200 @@ -12,6 +12,14 @@ cslist = {1,2,3,4}; varg2 (cslist{:}); + varg3 (cslist{:}); + cslist = {1, 2}; + varg3 (cslist{:}); + cslist = {1}; + varg3 (cslist{:}); + cslist = {}; + varg3 (cslist{:}); + justnamenotpos (1, 2); out = inout (1,2,3,4); @@ -41,6 +49,21 @@ varg1 (2, varargin{:}) end +function varg3 (a, b, varargin) + if exist ("a") + __printf_assert__ ("%d ", a); + else + __printf_assert__ ("noa "); + end + if exist ("b") % TODO: Why does not "if exist b" work here in either VM or tree walker? + __printf_assert__ ("%d ", b); + else + __printf_assert__ ("nob "); + end + __printf_assert__ ("%d ", size (varargin)); + __printf_assert__ ("%d ", nargin); +end + function justnamenotpos (varargin, a) __printf_assert__ ("%d ", a); __printf_assert__ ("%d ", varargin);