# HG changeset patch # User Petter T. # Date 1707863925 -3600 # Tue Feb 13 23:38:45 2024 +0100 # Branch bytecode-interpreter # Node ID 0cf8eaef6f4e0ee4a9f2e98c956d5eff8c82dbd2 # Parent 19973af3ac4287abde785754d3e0ef53707a5d49 wipwip fix more than 255 args to index operation diff -r 19973af3ac42 -r 0cf8eaef6f4e libinterp/parse-tree/pt-bytecode-vm.cc --- a/libinterp/parse-tree/pt-bytecode-vm.cc Sun Feb 11 09:40:35 2024 -0500 +++ b/libinterp/parse-tree/pt-bytecode-vm.cc Tue Feb 13 23:38:45 2024 +0100 @@ -452,8 +452,8 @@ CASE_START (END_OBJ) PSLOT () PCHAR () PCHAR () CASE_END () - CASE_START (WORDCMD_NX) PSLOT () PCHAR () CASE_END () - CASE_START (WORDCMD) PSLOT () PCHAR () PCHAR () CASE_END () + CASE_START (WORDCMD_NX) PSLOT () PSHORT () CASE_END () + CASE_START (WORDCMD) PSLOT () PCHAR () PSHORT () CASE_END () CASE_START (SET_IGNORE_OUTPUTS) PCHAR () @@ -4215,14 +4215,14 @@ wordcmd_nx: slot = arg0; nargout = bsp[0].i; - n_args_on_stack = *ip++; + n_args_on_stack = POP_CODE_USHORT (); } else if (0) { wordcmd: slot = arg0; nargout = *ip++; - n_args_on_stack = *ip++; + n_args_on_stack = POP_CODE_USHORT (); } // The object to index is before the args on the stack @@ -6016,7 +6016,7 @@ int nargout = arg0; int has_slot = *ip++; int slot = POP_CODE_USHORT (); - int n_args_on_stack = *ip++; + int n_args_on_stack = POP_CODE_USHORT (); char type = *ip++; // The object to index is before the args on the stack diff -r 19973af3ac42 -r 0cf8eaef6f4e libinterp/parse-tree/pt-bytecode-walk.cc --- a/libinterp/parse-tree/pt-bytecode-walk.cc Sun Feb 11 09:40:35 2024 -0500 +++ b/libinterp/parse-tree/pt-bytecode-walk.cc Tue Feb 13 23:38:45 2024 +0100 @@ -5193,6 +5193,8 @@ tree_argument_list *args = *arg_lists_it; + bool many_args = args ? args->size () > 255 : false; + if (is_wordcmd) { CHECK (e->is_identifier ()); @@ -5207,7 +5209,7 @@ // The vm need the name of the identifier for function lookups PUSH_SLOT (slot); // Push nargin - PUSH_CODE (args ? args->size () : 0); + PUSH_CODE_SHORT (args ? args->size () : 0); } else { @@ -5216,10 +5218,10 @@ PUSH_SLOT (slot); PUSH_CODE (nargout); // Push nargin - PUSH_CODE (args ? args->size () : 0); + PUSH_CODE_SHORT (args ? args->size () : 0); } } - else if (e->is_identifier () && !(type == '.' && !struct_is_id_dot_id)) + else if (! many_args && e->is_identifier () && !(type == '.' && !struct_is_id_dot_id)) { std::string id_name = e->name (); int slot = SLOT (id_name); @@ -5323,19 +5325,28 @@ } else { - // We are not indexing an id, but e.g.: + // We either indexing an temporary object, e.g. // (foo).() - // I.e. a temporary object. + // or an id with more than 255 arguments. + + int slot = 0; + + if (e->is_identifier ()) + { + std::string id_name = e->name (); + slot = SLOT (id_name); + } + MAYBE_PUSH_ANON_NARGOUT_OPEXT (nargout); PUSH_CODE (INSTR::INDEX_OBJ); PUSH_CODE (nargout); // This is arg0, not used if EXT_NARGOUT is used - PUSH_CODE (0); // "has slot" - PUSH_WSLOT (0); // The w/e slot TODO: Remove? + PUSH_CODE (slot != 0); // "has slot" + PUSH_WSLOT (slot); // Push nargin if (type == '.') - PUSH_CODE (1); // Nargin always one for struct indexing + PUSH_CODE_SHORT (1); // Nargin always one for struct indexing else - PUSH_CODE (args ? args->size () : 0); + PUSH_CODE_SHORT (args ? args->size () : 0); PUSH_CODE (type); }