changeset 33246:106a4a07742a bytecode-interpreter

maint: Merge default to bytecode-interpreter
author Arun Giridhar <arungiridhar@gmail.com>
date Sun, 24 Mar 2024 16:53:18 -0400
parents 39b6d6ca3831 (current diff) 399be7cc310f (diff)
children 737ab816cb7b
files libinterp/corefcn/module.mk libinterp/octave-value/ov.h
diffstat 8 files changed, 130 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/corefcn/error.cc	Sun Mar 24 16:53:18 2024 -0400
@@ -1113,25 +1113,6 @@
   va_end (args);
 }
 
-OCTAVE_NORETURN
-void
-vpanic (const char *fmt, va_list args)
-{
-  octave::error_system& es = octave::__get_error_system__ ();
-
-  es.vpanic (fmt, args);
-}
-
-OCTAVE_NORETURN
-void
-panic (const char *fmt, ...)
-{
-  va_list args;
-  va_start (args, fmt);
-  vpanic (fmt, args);
-  va_end (args);
-}
-
 OCTAVE_BEGIN_NAMESPACE(octave)
 
 void
--- a/libinterp/corefcn/error.h	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/corefcn/error.h	Sun Mar 24 16:53:18 2024 -0400
@@ -35,6 +35,10 @@
 #include "unwind-prot.h"
 
 #include "oct-map.h"
+// Include panic.h here for backward compatibility with previous
+// versions of Octave that declared the global panic functions and
+// macros here.
+#include "panic.h"
 
 class octave_value_list;
 
@@ -489,32 +493,6 @@
 extern OCTINTERP_API void
 parse_error_with_id (const char *id, const char *fmt, ...);
 
-OCTAVE_NORETURN
-extern OCTINTERP_API void vpanic (const char *fmt, va_list args);
-
-OCTAVE_FORMAT_PRINTF (1, 2)
-OCTAVE_NORETURN
-extern OCTINTERP_API void panic (const char *fmt, ...);
-
-// To allow the __FILE__ and __LINE__ macros to work as expected, the
-// panic_impossible, panic_if, panic_unless, error_impossible, error_if,
-// and error_unless symbols must be defined as macros.
-
-#define panic_impossible()                                              \
-  ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
-
-#if defined (NDEBUG)
-#  define panic_if(cond)
-#else
-#  define panic_if(cond) do { if (cond) panic_impossible (); } while (0)
-#endif
-
-#if defined (NDEBUG)
-#  define panic_unless(cond)
-#else
-#  define panic_unless(cond) panic_if (! (cond))
-#endif
-
 #define error_impossible()                                              \
   ::error ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
 
--- a/libinterp/corefcn/module.mk	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/corefcn/module.mk	Sun Mar 24 16:53:18 2024 -0400
@@ -79,6 +79,7 @@
   %reldir%/oct.h \
   %reldir%/octave-default-image.h \
   %reldir%/pager.h \
+  %reldir%/panic.h \
   %reldir%/pr-flt-fmt.h \
   %reldir%/pr-output.h \
   %reldir%/procstream.h \
@@ -236,6 +237,7 @@
   %reldir%/ordqz.cc \
   %reldir%/ordschur.cc \
   %reldir%/pager.cc \
+  %reldir%/panic.cc \
   %reldir%/perms.cc \
   %reldir%/pinv.cc \
   %reldir%/pow2.cc \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/panic.cc	Sun Mar 24 16:53:18 2024 -0400
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 1993-2024 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include "error.h"
+#include "interpreter-private.h"
+#include "panic.h"
+
+OCTAVE_NORETURN
+void
+vpanic (const char *fmt, va_list args)
+{
+  octave::error_system& es = octave::__get_error_system__ ();
+
+  es.vpanic (fmt, args);
+}
+
+OCTAVE_NORETURN
+void
+panic (const char *fmt, ...)
+{
+  va_list args;
+  va_start (args, fmt);
+  vpanic (fmt, args);
+  va_end (args);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libinterp/corefcn/panic.h	Sun Mar 24 16:53:18 2024 -0400
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////
+//
+// Copyright (C) 2024 The Octave Project Developers
+//
+// See the file COPYRIGHT.md in the top-level directory of this
+// distribution or <https://octave.org/copyright/>.
+//
+// This file is part of Octave.
+//
+// Octave is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Octave is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Octave; see the file COPYING.  If not, see
+// <https://www.gnu.org/licenses/>.
+//
+////////////////////////////////////////////////////////////////////////
+
+#if ! defined (octave_panic_h)
+#define octave_panic_h 1
+
+#include "octave-config.h"
+
+#include <cstdarg>
+
+OCTAVE_NORETURN
+extern OCTINTERP_API void vpanic (const char *fmt, va_list args);
+
+OCTAVE_FORMAT_PRINTF (1, 2)
+OCTAVE_NORETURN
+extern OCTINTERP_API void panic (const char *fmt, ...);
+
+// To allow the __FILE__ and __LINE__ macros to work as expected, the
+// panic_impossible, panic_if, panic_unless, error_impossible, error_if,
+// and error_unless symbols must be defined as macros.
+
+#define panic_impossible()                                              \
+  ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
+
+#if defined (NDEBUG)
+#  define panic_if(cond)
+#else
+#  define panic_if(cond) do { if (cond) panic_impossible (); } while (0)
+#endif
+
+#if defined (NDEBUG)
+#  define panic_unless(cond)
+#else
+#  define panic_unless(cond) panic_if (! (cond))
+#endif
+
+#endif
--- a/libinterp/octave-value/ov.h	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/octave-value/ov.h	Sun Mar 24 16:53:18 2024 -0400
@@ -36,6 +36,8 @@
 #include <memory>
 #include <map>
 
+#include "panic.h"
+
 #include "data-conv.h"
 #include "idx-vector.h"
 #include "mach-info.h"
@@ -1813,11 +1815,10 @@
 extern OCTINTERP_API void install_types (octave::type_info&);
 
 // Templated value extractors.
-// FIXME: would be more consistent to use panic_impossible(), rather than
-//        assert(), but including "error.h" leads to compilation errors.
+
 template <typename Value>
 inline Value octave_value_extract (const octave_value&)
-{ assert (false); }
+{ panic_impossible (); }
 
 #define DEF_VALUE_EXTRACTOR(VALUE,MPREFIX)                              \
   template <>                                                           \
@@ -1888,7 +1889,7 @@
   template <>                                                           \
   inline VALUE octave_value_extract<VALUE> (const octave_value&)        \
   {                                                                     \
-    assert (false);                                                     \
+    panic_impossible ();                                                \
     return DEFVAL;                                                      \
   }
 
--- a/libinterp/parse-tree/bp-table.cc	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/parse-tree/bp-table.cc	Sun Mar 24 16:53:18 2024 -0400
@@ -486,8 +486,6 @@
             {
               if (args(pos).is_string ())
                 {
-                  bool skip = false;
-
                   std::string str = args(pos).string_value ();
 
                   try
--- a/libinterp/parse-tree/lex.ll	Sat Mar 23 12:19:59 2024 -0400
+++ b/libinterp/parse-tree/lex.ll	Sun Mar 24 16:53:18 2024 -0400
@@ -2358,7 +2358,7 @@
     else
       len = max_size > m_chars_left ? m_chars_left : max_size;
 
-    assert (len > 0);
+    panic_unless (len > 0);
     memcpy (buf, m_buffer.c_str () + m_offset, len);
 
     m_chars_left -= len;
@@ -3106,9 +3106,10 @@
 
     nread = sscanf (tmptxt, "%lf", &value);
 
-    // If yytext doesn't contain a valid number, we are in deep doo doo.
-
-    assert (nread == 1);
+    // Panic instead of error because if yytext doesn't contain a valid
+    // number, we are in deep doo doo.
+
+    panic_unless (nread == 1);
 
     octave_value ov_value;
 
@@ -3213,12 +3214,12 @@
         return syntax_error (msg);
       }
 
-    // Assert here because if yytext doesn't contain a valid number, we
-    // are in deep doo doo.
+    // Panic instead of error here because if yytext doesn't contain a
+    // valid number, we are in deep doo doo.
 
     uintmax_t long_int_val;
     int status = sscanf (yytxt.c_str (), "%jx", &long_int_val);
-    assert (status);
+    panic_unless (status);
 
     octave_value ov_value
       = make_integer_value (long_int_val, unsigned_val, bytes);
@@ -4052,7 +4053,7 @@
         // input_buffer::copy_chunk, simply insert the marker directly
         // in BUF.
 
-        assert (max_size > 0);
+        panic_unless (max_size > 0);
 
         buf[0] = static_cast<char> (1);
         status = 1;