changeset 33396:453132956401 bytecode-interpreter

maint: Merge default to bytecode-interpreter
author Arun Giridhar <arungiridhar@gmail.com>
date Sat, 13 Apr 2024 14:31:24 -0400
parents 3607ae0a5d88 (current diff) a258493e726a (diff)
children b4b98a35906e
files configure.ac libinterp/corefcn/variables.cc
diffstat 10 files changed, 67 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Apr 12 18:56:35 2024 -0400
+++ b/configure.ac	Sat Apr 13 14:31:24 2024 -0400
@@ -346,6 +346,8 @@
 
 if test $ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR = yes; then
   OCTAVE_CHECK_STD_PMR_POLYMORPHIC_ALLOCATOR
+else
+  HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR="no"
 fi
 
 ### Determine which C compiler to use (we expect to find gcc or clang).
@@ -3378,7 +3380,7 @@
   Use library visibility flags:         $ENABLE_LIB_VISIBILITY_FLAGS
   64-bit array dims and indexing:       $ENABLE_64
   64-bit BLAS array dims and indexing:  $HAVE_64_BIT_BLAS
-  Use std::pmr::polymorphic_allocator:  $ENABLE_STD_PMR_POLYMORPHIC_ALLOCATOR
+  Use std::pmr::polymorphic_allocator:  $HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR
   OpenMP SMP multithreading:            $ENABLE_OPENMP
   Include support for GNU readline:     $USE_READLINE
   Use push parser in command line REPL: $ENABLE_COMMAND_LINE_PUSH_PARSER
--- a/libinterp/corefcn/cellfun.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/cellfun.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -1991,8 +1991,8 @@
 {
   Cell retval;
 
-  if ((nd != 1 && nd != 2) || a.ndims () != 2)
-    error ("do_mat2cell_2d: A must be two-dimensional, and ND must be 1 or 2");
+  panic_unless (nd == 1 || nd == 2);
+  panic_unless (a.ndims () == 2);
 
   if (mat2cell_mismatch (a.dims (), d, nd))
     return retval;
@@ -2049,8 +2049,7 @@
 {
   Cell retval;
 
-  if (nd < 1)
-    error ("do_mat2cell_nd: ND must be at least 1");
+  panic_unless (nd >= 1);
 
   if (mat2cell_mismatch (a.dims (), d, nd))
     return retval;
@@ -2133,8 +2132,7 @@
 {
   Cell retval;
 
-  if (nd < 1)
-    error ("do_mat2cell: ND must be at least 1");
+  panic_unless (nd >= 1);
 
   if (mat2cell_mismatch (a.dims (), d, nd))
     return retval;
--- a/libinterp/corefcn/daspk.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/daspk.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -68,8 +68,7 @@
 {
   ColumnVector retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("daspk_user_function: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
@@ -120,8 +119,7 @@
 {
   Matrix retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("daspk_user_jacobian: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
--- a/libinterp/corefcn/dasrt.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/dasrt.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -69,8 +69,7 @@
 {
   ColumnVector retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("dasrt_user_f: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
@@ -160,8 +159,7 @@
 {
   Matrix retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("dasrt_user_j: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
--- a/libinterp/corefcn/dassl.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/dassl.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -67,8 +67,7 @@
 {
   ColumnVector retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("dassl_user_function: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
@@ -119,8 +118,7 @@
 {
   Matrix retval;
 
-  if (x.numel () != xdot.numel ())
-    error ("dassl_user_jacobian: X and XDOT must have the same number of elements");
+  panic_unless (x.numel () == xdot.numel ());
 
   octave_value_list args;
 
--- a/libinterp/corefcn/kron.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/kron.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -55,8 +55,8 @@
 static MArray<T>
 kron (const MArray<R>& a, const MArray<T>& b)
 {
-  if (a.ndims () != 2 || b.ndims () != 2)
-    error ("kron: A and B must both be two-dimensional");
+  panic_unless (a.ndims () == 2);
+  panic_unless (b.ndims () == 2);
 
   octave_idx_type nra = a.rows ();
   octave_idx_type nrb = b.rows ();
@@ -86,8 +86,7 @@
 static MArray<T>
 kron (const MDiagArray2<R>& a, const MArray<T>& b)
 {
-  if (b.ndims () != 2)
-    error ("kron: B must be two-dimensional");
+  panic_unless (b.ndims () == 2);
 
   octave_idx_type nra = a.rows ();
   octave_idx_type nrb = b.rows ();
--- a/libinterp/corefcn/pr-output.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/pr-output.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -300,8 +300,7 @@
 pr_max_internal (const MArray<T>& m)
 {
   // We expect a 2-d array.
-  if (m.ndims () != 2)
-    error ("pr_max_internal: M must be two-dimensional");
+  panic_unless (m.ndims () == 2);
 
   octave_idx_type nr = m.rows ();
   octave_idx_type nc = m.columns ();
@@ -682,8 +681,7 @@
 make_matrix_format (const MT& m)
 {
   // We expect a 2-d array.
-  if (m.ndims () != 2)
-    error ("make_matrix_format: M must be two-dimensional");
+  panic_unless (m.ndims () == 2);
 
   if (free_format)
     return float_display_format ();
@@ -1572,8 +1570,7 @@
 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc,
                     bool pr_as_read_syntax)
 {
-  if (nr && nc)
-    error ("print_empty_matrix: at least one of NR and NC must be zero");
+  panic_unless (nr == 0 || nc == 0);
 
   if (pr_as_read_syntax)
     {
@@ -1595,8 +1592,7 @@
 print_empty_nd_array (std::ostream& os, const dim_vector& dims,
                       bool pr_as_read_syntax)
 {
-  if (! dims.any_zero ())
-    error ("print_empty_nd_array: at least one of DIMS must be zero");
+  panic_unless (dims.any_zero ());
 
   if (pr_as_read_syntax)
     os << "zeros (" << dims.str (',') << ')';
--- a/libinterp/corefcn/schur.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/schur.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -46,9 +46,7 @@
   octave_value retval = a;
 
   octave_idx_type n = a.rows ();
-
-  if (a.columns () != n)
-    error ("mark_upper_triangular: A must be a square matrix");
+  panic_unless (a.columns () == n);
 
   const typename Matrix::element_type zero = typename Matrix::element_type ();
 
--- a/libinterp/corefcn/variables.cc	Fri Apr 12 18:56:35 2024 -0400
+++ b/libinterp/corefcn/variables.cc	Sat Apr 13 14:31:24 2024 -0400
@@ -768,8 +768,7 @@
 
   int nargin = args.length ();
 
-  if (var >= nchoices)
-    error ("set_internal_variable: VAR too large for CHOICES");
+  panic_unless (var < nchoices);
 
   if (nargout > 0 || nargin == 0)
     retval = choices[var];
--- a/m4/acinclude.m4	Fri Apr 12 18:56:35 2024 -0400
+++ b/m4/acinclude.m4	Sat Apr 13 14:31:24 2024 -0400
@@ -200,6 +200,47 @@
   AC_CACHE_CHECK([whether std::pmr::polymorphic_allocator is available],
     [octave_cv_std_pmr_polymorphic_allocator],
     [AC_LANG_PUSH(C++)
+    AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+      #include <cstdlib>
+      #include <memory_resource>
+      #include <vector>
+      class mx_memory_resource : public std::pmr::memory_resource
+      {
+      private:
+        void * do_allocate (std::size_t bytes, size_t /*alignment*/)
+        {
+          void *ptr = std::malloc (bytes);
+          if (! ptr)
+            throw std::bad_alloc ();
+            return ptr;
+        }
+        void do_deallocate (void* ptr, std::size_t /*bytes*/,
+                            std::size_t /*alignment*/)
+        {
+          std::free (ptr);
+        }
+        bool do_is_equal (const std::pmr::memory_resource& other) const noexcept
+        {
+          return this == dynamic_cast<const mx_memory_resource *> (&other);
+          return true;
+        }
+      };
+      mx_memory_resource the_mx_memory_resource;
+    ]], [[
+      std::pmr::vector<int> my_int_vec { &the_mx_memory_resource };
+    ]])],
+    octave_cv_std_pmr_polymorphic_allocator=yes,
+    octave_cv_std_pmr_polymorphic_allocator=no,
+    [## On macOS, we need to run an executable to check if polymorphic
+    ## allocators are working.
+    ## When cross-compiling to that target, the following test might succeed
+    ## even if polymorphic allocators are not actually implemented. In that
+    ## case, users would need to manually configure with
+    ## `--disable-std-pmr-polymorphic-allocator`.
+    ## When cross-compiling to any other target, the following test should be
+    ## giving accurate results.
+
+    ## FIXME: Is there a way to not repeat the same code from above?
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
       #include <cstdlib>
       #include <memory_resource>
@@ -230,12 +271,15 @@
       std::pmr::vector<int> my_int_vec { &the_mx_memory_resource };
     ]])],
     octave_cv_std_pmr_polymorphic_allocator=yes,
-    octave_cv_std_pmr_polymorphic_allocator=no)
+    octave_cv_std_pmr_polymorphic_allocator=no)])
     AC_LANG_POP(C++)
   ])
   if test $octave_cv_std_pmr_polymorphic_allocator = yes; then
     AC_DEFINE(OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR, 1,
       [Define to 1 if std::pmr::polymorphic_allocator is available.])
+    HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR="yes"
+  else
+    HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR="no"
   fi
 ])
 dnl