diff libinterp/parse-tree/pt-fcn-handle.cc @ 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/parse-tree/pt-fcn-handle.cc	Mon Mar 30 10:43:47 2020 -0400
+++ b/libinterp/parse-tree/pt-fcn-handle.cc	Mon Mar 30 15:14:10 2020 -0400
@@ -32,6 +32,7 @@
 #include "interpreter-private.h"
 #include "pt-anon-scopes.h"
 #include "pt-fcn-handle.h"
+#include "stack-frame.h"
 
 namespace octave
 {
@@ -130,7 +131,7 @@
 
     std::set<std::string> free_vars = anon_fcn_ctx.free_variables ();
 
-    octave_user_function::local_vars_map local_var_init_vals;
+    stack_frame::local_vars_map local_vars;
 
     call_stack& cs = tw.get_call_stack ();
 
@@ -141,12 +142,12 @@
         octave_value val = frame->varval (name);
 
         if (val.is_defined ())
-          local_var_init_vals[name] = val;
+          local_vars[name] = val;
       }
 
     octave_user_function *af
       = new octave_user_function (new_scope, param_list_dup, ret_list,
-                                  stmt_list, local_var_init_vals);
+                                  stmt_list);
 
     octave_function *curr_fcn = cs.current_function ();
 
@@ -176,8 +177,7 @@
 
     // octave_value fh (octave_fcn_binder::maybe_binder (ov_fcn, m_interpreter));
 
-    return octave_value (new octave_fcn_handle
-                         (ov_fcn, octave_fcn_handle::anonymous));
+    return octave_value (new octave_fcn_handle (ov_fcn, local_vars));
   }
 }