changeset 32440:b36ac2c31cb2

Add function to octave_value:s that decides dispath type for ()-indexing New function vm_dispatch_call that returns the dispatch type the bytecode interpreter is expected to for a call. * ov-base-diag.h: New function * ov-base-mat.h: Dito ... * ov-base-scalar.h * ov-base-sparse.h * ov-base.cc * ov-base.h * ov-cell.h * ov-classdef.h * ov-colon.h * ov-fcn-handle.h * ov-struct.h * ov.h
author Petter T.
date Fri, 27 Oct 2023 18:19:32 +0200
parents e77f4f571c73
children 030cf510f141
files libinterp/octave-value/ov-base-diag.h libinterp/octave-value/ov-base-mat.h libinterp/octave-value/ov-base-scalar.h libinterp/octave-value/ov-base-sparse.h libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-cell.h libinterp/octave-value/ov-classdef.h libinterp/octave-value/ov-colon.h libinterp/octave-value/ov-fcn-handle.h libinterp/octave-value/ov-fcn.h libinterp/octave-value/ov-struct.h libinterp/octave-value/ov.h
diffstat 13 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base-diag.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base-diag.h	Fri Oct 27 18:19:32 2023 +0200
@@ -247,6 +247,7 @@
 
   OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
 protected:
 
   DMT m_matrix;
--- a/libinterp/octave-value/ov-base-mat.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base-mat.h	Fri Oct 27 18:19:32 2023 +0200
@@ -219,6 +219,7 @@
   octave_value
   checked_full_matrix_elem (octave_idx_type i, octave_idx_type j) const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
 protected:
 
   MT m_matrix;
--- a/libinterp/octave-value/ov-base-scalar.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base-scalar.h	Fri Oct 27 18:19:32 2023 +0200
@@ -179,6 +179,8 @@
   bool vm_need_dispatch_assign_lhs (void) { return false; }
   bool vm_need_dispatch_push (void) { return false; }
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 protected:
 
   // The value of this scalar.
--- a/libinterp/octave-value/ov-base-sparse.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base-sparse.h	Fri Oct 27 18:19:32 2023 +0200
@@ -242,6 +242,8 @@
 
   OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 protected:
 
   OCTINTERP_API octave_value
--- a/libinterp/octave-value/ov-base.cc	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base.cc	Fri Oct 27 18:19:32 2023 +0200
@@ -962,6 +962,23 @@
   return nullptr;
 }
 
+octave_base_value::vm_call_dispatch_type
+octave_base_value::vm_dispatch_call (void)
+{
+  // This is the fallback way to determine the dispatch type
+  // for octave_base_value classes that does not implement vm_dispatch_call ()
+
+  bool has_function_cache = this->has_function_cache ();
+  bool is_defined = this->is_defined ();
+
+  if (! has_function_cache && is_defined)
+    return vm_call_dispatch_type::SUBSREF;
+  else if (has_function_cache)
+      return vm_call_dispatch_type::CALL;
+  else
+      return vm_call_dispatch_type::FN_LOOKUP;
+}
+
 octave_value_ref *
 octave_base_value::ref_rep ()
 {
--- a/libinterp/octave-value/ov-base.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-base.h	Fri Oct 27 18:19:32 2023 +0200
@@ -814,6 +814,16 @@
   virtual bool vm_need_dispatch_assign_lhs (void) { return true; }
   virtual bool vm_need_dispatch_push (void) { return true; }
 
+  enum class vm_call_dispatch_type {
+    SUBSREF,
+    FN_LOOKUP,
+    CALL,
+    HANDLE,
+    OBJECT,
+  };
+
+  virtual vm_call_dispatch_type vm_dispatch_call (void);
+
   virtual bool is_ref () const { return false; }
 
   virtual octave_value_ref * ref_rep ();
--- a/libinterp/octave-value/ov-cell.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-cell.h	Fri Oct 27 18:19:32 2023 +0200
@@ -178,6 +178,8 @@
   // You should not use it anywhere else.
   const void * mex_get_data () const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 private:
 
   void clear_cellstr_cache () const
--- a/libinterp/octave-value/ov-classdef.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-classdef.h	Fri Oct 27 18:19:32 2023 +0200
@@ -230,6 +230,8 @@
 
   OCTINTERP_API std::string file_name () const;
 
+    vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 private:
 
   octave::cdef_meta_object m_object;
--- a/libinterp/octave-value/ov-colon.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-colon.h	Fri Oct 27 18:19:32 2023 +0200
@@ -76,6 +76,8 @@
   OCTINTERP_API void print_raw (std::ostream& os,
                                 bool pr_as_read_syntax = false) const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 private:
 
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
--- a/libinterp/octave-value/ov-fcn-handle.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-fcn-handle.h	Fri Oct 27 18:19:32 2023 +0200
@@ -377,6 +377,13 @@
   get_cached_fcn (const octave_value_list& args) { return m_rep->get_cached_fcn (args); }
   bool has_function_cache (void) const { return m_rep->has_function_cache (); }
 
+  vm_call_dispatch_type vm_dispatch_call (void)
+  {
+    if (m_rep->has_function_cache ())
+      return vm_call_dispatch_type::CALL;
+    return vm_call_dispatch_type::SUBSREF;
+  }
+
   void compile () { m_rep->compile (); }
 private:
 
--- a/libinterp/octave-value/ov-fcn.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-fcn.h	Fri Oct 27 18:19:32 2023 +0200
@@ -65,6 +65,8 @@
 
   bool has_function_cache (void) const { return true; }
 
+  vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::CALL; }
+
   octave_function *
   get_cached_fcn (const octave_value_list& args);
 
@@ -315,6 +317,7 @@
   execute (octave::tree_evaluator& tw, int nargout = 0,
            const octave_value_list& args = octave_value_list ()) = 0;
 
+  vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::CALL; }
 protected:
 
   octave_function (const std::string& nm,
--- a/libinterp/octave-value/ov-struct.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov-struct.h	Fri Oct 27 18:19:32 2023 +0200
@@ -165,6 +165,8 @@
   bool
   fast_elem_insert (octave_idx_type n, const octave_value& x);
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 protected:
 
   // The associative array used to manage the structure data.
@@ -290,6 +292,8 @@
 
   bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call (void) { return vm_call_dispatch_type::SUBSREF; }
+
 protected:
 
   // The associative array used to manage the structure data.
--- a/libinterp/octave-value/ov.h	Fri Oct 27 18:19:27 2023 +0200
+++ b/libinterp/octave-value/ov.h	Fri Oct 27 18:19:32 2023 +0200
@@ -1603,6 +1603,11 @@
     return m_rep->vm_need_dispatch_push ();
   }
 
+  octave_base_value::vm_call_dispatch_type vm_dispatch_call ()
+  {
+    return m_rep->vm_dispatch_call ();
+  }
+
   bool same_rep (octave_value &ov) const { return m_rep == ov.m_rep; }
 
   void maybe_call_dtor () { m_rep->maybe_call_dtor (); }