diff libinterp/octave-value/ov-fcn-handle.h @ 28430:5bfa8e018704 stable

store local init vars for anonymous functions in handle, not function object This change is step toward revamping function handles by storing variable init values for anonymous functions in function handle objects instead of in the corresponding functions. * call-stack.h, call-stack.cc (call_stack::push): New overload that accepts local variable map in addition to function object. * stack-frame.h (user_fcn_stack_frame::user_fcn_stack_frame): New constructor that accepts local variable map in addition to function object. (stack_frame::local_vars_map): New typedef. * ov-fcn-handle.h, ov-fcn-handle.cc (octave_fcn_handle::m_local_vars): New data member. (octave_fcn_handle::octave_fcn_handle): Update existing constructors and provide new one to construct handle from function object and local variable map. (octave_fcn_handle::call): If m_local_vars is defined, push stack frame with that info and execute function here. (octave_fcn_handle::workspace): Create workspace struct from m_local_vars instead of getting that info from the function object. (octave_fcn_handle::parse_anon_fcn_handle): Copy m_local_vars from new function handle object. (octave_fcn_handle::save_ascii, octave_fcn_handle::save_binary, octave_fcn_handle::save_hdf5): Use m_local_vars instead of getting info from function object. * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_function::local_vars_map): Delete typedef. (octave_user_function::m_local_var_init_vals): Delete data member and all uses. (octave_user_function::local_var_init_vals): Delete. * pt-eval.h, pt-eval.cc (tree_evaluator::push_stack_frame): New overload that accepts local variable map and user function. (tree_evaluator::init_local_fcn_vars): Delete function and all uses. * pt-fcn-handle.cc (tree_anon_fcn_handle::evaluate): Store local variables in function handle object instead of function object.
author John W. Eaton <jwe@octave.org>
date Mon, 30 Mar 2020 15:14:10 -0400
parents 9a3deb17b4ea
children d05a4194f1ad
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.h	Mon Mar 30 10:43:47 2020 -0400
+++ b/libinterp/octave-value/ov-fcn-handle.h	Mon Mar 30 15:14:10 2020 -0400
@@ -35,12 +35,12 @@
 #include "ov-base.h"
 #include "ov-fcn.h"
 #include "ov-typeinfo.h"
+#include "stack-frame.h"
 #include "symscope.h"
 
 namespace octave
 {
   class interpreter;
-  class stack_frame;
   class tree_evaluator;
 }
 
@@ -56,21 +56,22 @@
 
   octave_fcn_handle (void)
     : m_fcn (), m_obj (), m_name (), m_scope (), m_is_nested (false),
-      m_closure_frames (), m_dispatch_class ()
+      m_closure_frames (), m_local_vars (nullptr), m_dispatch_class ()
   { }
 
   octave_fcn_handle (const octave::symbol_scope& scope, const std::string& n);
 
   octave_fcn_handle (const octave::symbol_scope& scope,
-                     const octave_value& f,
-                     const std::string& n = anonymous);
+                     const octave_value& f, const std::string& n);
+
+  octave_fcn_handle (const octave_value& f, const std::string& n);
 
   octave_fcn_handle (const octave_value& f,
-                     const std::string& n = anonymous);
+                     const octave::stack_frame::local_vars_map& local_vars);
 
-  octave_fcn_handle (const octave_fcn_handle& fh) = default;
+  octave_fcn_handle (const octave_fcn_handle& fh);
 
-  ~octave_fcn_handle (void) = default;
+  ~octave_fcn_handle (void);
 
   octave_base_value * clone (void) const
   { return new octave_fcn_handle (*this); }
@@ -186,6 +187,9 @@
   // functions indirectly through handles.
   std::shared_ptr<octave::stack_frame> m_closure_frames;
 
+  // List of captured variable values for anonymous fucntions.
+  octave::stack_frame::local_vars_map *m_local_vars;
+
   // The name of the class in which this handle was created, if any.
   // Used to determine access permission when the referenced function is
   // called.