changeset 33314:3e3a10b70fcd bytecode-interpreter

maint: merge default to bytecode-interpreter
author John W. Eaton <jwe@octave.org>
date Thu, 04 Apr 2024 03:27:57 -0400
parents ac3633dd67d1 (current diff) c1ab55458c3a (diff)
children 302c3a1d12d7
files
diffstat 2 files changed, 68 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Thu Apr 04 01:00:08 2024 -0400
+++ b/libinterp/parse-tree/oct-parse.yy	Thu Apr 04 03:27:57 2024 -0400
@@ -490,15 +490,9 @@
                 ;
 
 fcn_list1       : function
-                  {
-                    octave::tree_statement *stmt = parser.make_statement ($1);
-                    $$ = parser.make_statement_list (stmt);
-                  }
+                  { $$ = parser.make_function_def_list ($1); }
                 | fcn_list1 opt_sep function
-                  {
-                    octave::tree_statement *stmt = parser.make_statement ($3);
-                    $$ = parser.append_statement_list ($1, $2, stmt, false);
-                  }
+                  { $$ = parser.append_function_def_list ($1, $2, $3); }
                 ;
 
 statement       : expression
@@ -519,12 +513,12 @@
 
 word_list_cmd   : identifier word_list
                   {
-                    $$ = parser.make_index_expression ($1, nullptr, $2, nullptr, '(');
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, nullptr, $2, nullptr, '(')))
                       {
                         // make_index_expression deleted $1 and $2.
                         YYABORT;
                       }
+
                     $$->mark_word_list_cmd ();
                   }
                 ;
@@ -571,9 +565,7 @@
 matrix_rows     : cell_or_matrix_row
                   { $$ = parser.make_matrix ($1); }
                 | matrix_rows ';' cell_or_matrix_row
-                  {
-                    $$ = parser.append_matrix_row ($1, $2, $3);
-                  }
+                  { $$ = parser.append_matrix_row ($1, $2, $3); }
                 ;
 
 cell            : '{' cell_rows '}'
@@ -583,9 +575,7 @@
 cell_rows       : cell_or_matrix_row
                   { $$ = parser.make_cell ($1); }
                 | cell_rows ';' cell_or_matrix_row
-                  {
-                    $$ = parser.append_cell_row ($1, $2, $3);
-                  }
+                  { $$ = parser.append_cell_row ($1, $2, $3); }
                 ;
 
 // tree_argument_list objects can't be empty or have leading or trailing
@@ -636,8 +626,7 @@
 
 anon_fcn_handle : '@' param_list anon_fcn_begin expression
                   {
-                    $$ = parser.make_anon_fcn_handle ($1, $2, $4);
-                    if (! $$)
+                    if (! ($$ = parser.make_anon_fcn_handle ($1, $2, $4)))
                       {
                         // make_anon_fcn_handle deleted $2 and $4.
                         YYABORT;
@@ -653,6 +642,7 @@
                     lexer.m_parsing_anon_fcn_body = false;
 
                     $$ = nullptr;
+
                     parser.bison_error ("anonymous function bodies must be single expressions");
                     YYABORT;
                   }
@@ -676,9 +666,7 @@
                 | superclass_identifier
                   { $$ = $1; }
                 | '(' expression ')'
-                  {
-                    $$ = $2->mark_in_delims (*($1), *($3));
-                  }
+                  { $$ = $2->mark_in_delims (*($1), *($3)); }
                 ;
 
 magic_colon     : ':'
@@ -686,9 +674,7 @@
                 ;
 
 magic_tilde     : '~'
-                  {
-                    $$ = parser.make_black_hole ($1);
-                  }
+                  { $$ = parser.make_black_hole ($1); }
                 ;
 
 arg_list        : expression
@@ -698,17 +684,11 @@
                 | magic_tilde
                   { $$ = parser.make_argument_list ($1); }
                 | arg_list ',' magic_colon
-                  {
-                    $$ = parser.append_argument_list ($1, $2, $3);
-                  }
+                  { $$ = parser.append_argument_list ($1, $2, $3); }
                 | arg_list ',' magic_tilde
-                  {
-                    $$ = parser.append_argument_list ($1, $2, $3);
-                  }
+                  { $$ = parser.append_argument_list ($1, $2, $3); }
                 | arg_list ',' expression
-                  {
-                    $$ = parser.append_argument_list ($1, $2, $3);
-                  }
+                  { $$ = parser.append_argument_list ($1, $2, $3); }
                 ;
 
 indirect_ref_op : '.'
@@ -726,9 +706,7 @@
                   { $$ = parser.make_postfix_op ($1, $2); }
                 | oper_expr '(' ')'
                   {
-                    $$ = parser.make_index_expression ($1, $2, nullptr, $3, '(');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, nullptr, $3, '(')))
                       {
                         // make_index_expression deleted $1.
                         YYABORT;
@@ -736,9 +714,7 @@
                   }
                 | oper_expr '(' arg_list ')'
                   {
-                    $$ = parser.make_index_expression ($1, $2, $3, $4, '(');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, $3, $4, '(')))
                       {
                         // make_index_expression deleted $1 and $3.
                         YYABORT;
@@ -746,9 +722,7 @@
                   }
                 | oper_expr '{' '}'
                   {
-                    $$ = parser.make_index_expression ($1, $2, nullptr, $3, '{');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, nullptr, $3, '{')))
                       {
                         // make_index_expression deleted $1.
                         YYABORT;
@@ -756,9 +730,7 @@
                   }
                 | oper_expr '{' arg_list '}'
                   {
-                    $$ = parser.make_index_expression ($1, $2, $3, $4, '{');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, $3, $4, '{')))
                       {
                         // make_index_expression deleted $1 and $3.
                         YYABORT;
@@ -814,9 +786,7 @@
                   { $$ = parser.make_postfix_op ($1, $2); }
                 | power_expr '(' ')'
                   {
-                    $$ = parser.make_index_expression ($1, $2, nullptr, $3, '(');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, nullptr, $3, '(')))
                       {
                         // make_index_expression deleted $1.
                         YYABORT;
@@ -824,9 +794,7 @@
                   }
                 | power_expr '(' arg_list ')'
                   {
-                    $$ = parser.make_index_expression ($1, $2, $3, $4, '(');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, $3, $4, '(')))
                       {
                         // make_index_expression deleted $1 and $3.
                         YYABORT;
@@ -834,9 +802,7 @@
                   }
                 | power_expr '{' '}'
                   {
-                    $$ = parser.make_index_expression ($1, $2, nullptr, $3, '{');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, nullptr, $3, '{')))
                       {
                         // make_index_expression deleted $1.
                         YYABORT;
@@ -844,9 +810,7 @@
                   }
                 | power_expr '{' arg_list '}'
                   {
-                    $$ = parser.make_index_expression ($1, $2, $3, $4, '{');
-
-                    if (! $$)
+                    if (! ($$ = parser.make_index_expression ($1, $2, $3, $4, '{')))
                       {
                         // make_index_expression deleted $1 and $3.
                         YYABORT;
@@ -872,9 +836,7 @@
 
 colon_expr      : oper_expr ':' oper_expr
                   {
-                    $$ = parser.make_colon_expression ($1, $2, $3);
-
-                    if (! $$)
+                    if (! ($$ = parser.make_colon_expression ($1, $2, $3)))
                       {
                         // make_colon_expression deleted $1 and $3.
                         YYABORT;
@@ -882,9 +844,7 @@
                   }
                 | oper_expr ':' oper_expr ':' oper_expr
                   {
-                    $$ = parser.make_colon_expression ($1, $2, $3, $4, $5);
-
-                    if (! $$)
+                    if (! ($$ = parser.make_colon_expression ($1, $2, $3, $4, $5)))
                       {
                         // make_colon_expression deleted $1, $3, and $5.
                         YYABORT;
@@ -920,15 +880,13 @@
 
 assign_lhs      : simple_expr
                   {
-                    $$ = parser.validate_matrix_for_assignment ($1);
-
-                    if ($$)
-                      { lexer.m_looking_at_matrix_or_assign_lhs = false; }
-                    else
+                    if (! ($$ = parser.validate_matrix_for_assignment ($1)))
                       {
                         // validate_matrix_for_assignment deleted $1.
                         YYABORT;
                       }
+
+                    lexer.m_looking_at_matrix_or_assign_lhs = false;
                   }
                 ;
 
@@ -1311,7 +1269,6 @@
                     lexer.m_looking_at_parameter_list = false;
                     lexer.m_arguments_is_keyword = true;
                     lexer.m_looking_for_object_index = false;
-
                     $$ = $1;
                   }
                 ;
@@ -1362,9 +1319,7 @@
 param_list2     : param_list_elt
                   { $$ = parser.make_parameter_list (octave::tree_parameter_list::in, $1); }
                 | param_list2 ',' param_list_elt
-                  {
-                    $$ = parser.append_parameter_list ($1, $2, $3);
-                  }
+                  { $$ = parser.append_parameter_list ($1, $2, $3); }
                 ;
 
 param_list_elt  : decl_elt
@@ -1421,13 +1376,9 @@
                 ;
 
 return_list1    : identifier
-                  {
-                    $$ = parser.make_parameter_list (octave::tree_parameter_list::out, $1);
-                  }
+                  { $$ = parser.make_parameter_list (octave::tree_parameter_list::out, $1); }
                 | return_list1 ',' identifier
-                  {
-                    $$ = parser.append_parameter_list ($1, $2, $3);
-                  }
+                  { $$ = parser.append_parameter_list ($1, $2, $3); }
                 ;
 
 // =======================
@@ -1502,10 +1453,10 @@
 
 function_beg    : push_fcn_symtab FUNCTION
                   {
+                    if (lexer.m_reading_classdef_file || lexer.m_parsing_classdef)
+                      lexer.m_maybe_classdef_get_set_method = true;
+
                     $$ = $2;
-                    if (lexer.m_reading_classdef_file
-                        || lexer.m_parsing_classdef)
-                      lexer.m_maybe_classdef_get_set_method = true;
                   }
                 ;
 
@@ -1600,9 +1551,7 @@
                 ;
 
 function_body   : at_first_executable_stmt opt_list
-                  {
-                    $$ = $2;
-                  }
+                  { $$ = $2; }
                 | function_body1 opt_sep at_first_executable_stmt opt_list
                   {
                     OCTAVE_YYUSE ($2);
@@ -1613,9 +1562,7 @@
 
 at_first_executable_stmt
                 : // empty
-                  {
-                    lexer.m_arguments_is_keyword = false;
-                  }
+                  { lexer.m_arguments_is_keyword = false; }
                 ;
 
 function_body1  : arguments_block
@@ -1793,32 +1740,23 @@
 attr_list1      : attr
                   { $$ = parser.make_classdef_attribute_list ($1); }
                 | attr_list1 ',' attr
-                  {
-                    $$ = parser.append_classdef_attribute ($1, $2, $3);
-                  }
+                  { $$ = parser.append_classdef_attribute ($1, $2, $3); }
                 ;
 
 attr            : identifier
                   { $$ = parser.make_classdef_attribute ($1); }
                 | identifier '=' expression
-                  {
-                    $$ = parser.make_classdef_attribute ($1, $2, $3);
-                  }
+                  { $$ = parser.make_classdef_attribute ($1, $2, $3); }
                 | '~' identifier
-                  {
-                    $$ = parser.make_not_classdef_attribute ($1, $2);
-                  }
+                  { $$ = parser.make_not_classdef_attribute ($1, $2); }
                 | '!' identifier
-                  {
-                    $$ = parser.make_not_classdef_attribute ($1, $2);
-                  }
+                  { $$ = parser.make_not_classdef_attribute ($1, $2); }
                 ;
 
 superclass_list : // empty
                   {
                     lexer.m_parsing_classdef_decl = false;
                     lexer.m_parsing_classdef_superclass = false;
-
                     $$ = nullptr;
                   }
                 | superclass_list1 opt_sep
@@ -1827,20 +1765,15 @@
 
                     lexer.m_parsing_classdef_decl = false;
                     lexer.m_parsing_classdef_superclass = false;
-
                     $$ = $1;
                   }
                 ;
 
 superclass_list1
                 : EXPR_LT superclass
-                  {
-                    $$ = parser.make_classdef_superclass_list ($1, $2);
-                  }
+                  { $$ = parser.make_classdef_superclass_list ($1, $2); }
                 | superclass_list1 EXPR_AND superclass
-                  {
-                    $$ = parser.append_classdef_superclass ($1, $2, $3);
-                  }
+                  { $$ = parser.append_classdef_superclass ($1, $2, $3); }
                 ;
 
 superclass      : FQ_IDENT
@@ -1999,9 +1932,7 @@
                 ;
 
 method_decl     : method_decl1
-                  {
-                    $$ = parser.finish_classdef_external_method ($1);
-                  }
+                  { $$ = parser.finish_classdef_external_method ($1); }
                 | return_list '='
                   {
                     lexer.m_defining_fcn++;
@@ -2137,9 +2068,7 @@
                 ;
 
 class_enum      : identifier '(' expression ')'
-                  {
-                    $$ = parser.make_classdef_enum ($1, $2, $3, $4);
-                  }
+                  { $$ = parser.make_classdef_enum ($1, $2, $3, $4); }
                 ;
 
 // =============
@@ -5075,6 +5004,22 @@
     return list_append (list, stmt);
   }
 
+  tree_statement_list *
+  base_parser::make_function_def_list (tree_function_def *fcn_def)
+  {
+    tree_statement *stmt = make_statement (fcn_def);
+
+    return new tree_statement_list (stmt);
+  }
+
+  tree_statement_list *
+  base_parser::append_function_def_list (tree_statement_list *list, char, tree_function_def *fcn_def)
+  {
+    tree_statement *stmt = make_statement (fcn_def);
+
+    return list_append (list, stmt);
+  }
+
   tree_argument_list *
   base_parser::make_argument_list (tree_expression *expr)
   {
--- a/libinterp/parse-tree/parse.h	Thu Apr 04 01:00:08 2024 -0400
+++ b/libinterp/parse-tree/parse.h	Thu Apr 04 03:27:57 2024 -0400
@@ -607,8 +607,16 @@
 
   // Append a statement to an existing statement list.
   OCTINTERP_API tree_statement_list *
-  append_statement_list (tree_statement_list *list, char sep,
-                         tree_statement *stmt, bool warn_missing_semi);
+  append_statement_list (tree_statement_list *list, char sep, tree_statement *stmt, bool warn_missing_semi);
+
+  // Create a statement list containing only function_def commands.
+  OCTINTERP_API tree_statement_list *
+  make_function_def_list (tree_function_def *fcn_def);
+
+  // Append a function_def command to an existing statement list (that
+  // should contain only other function_def commands).
+  OCTINTERP_API tree_statement_list *
+  append_function_def_list (tree_statement_list *list, char sep, tree_function_def *fcn_def);
 
   OCTINTERP_API tree_argument_list *
   make_argument_list (tree_expression *expr);