changeset 27211:8c27802a76c4

store reference to evaluator instead of call stack in stack frame * pt-eval.h, pt-eval.cc (tree_evaluator::max_stack_depth, tree_evaluator::global_varref, tree_evaluator::display_call_stack): New functions. * call-stack.cc (display_call_stack): Delete. (call_stack::push): Use evaluator instead of call_stack to create stack_frame object. (Fmax_stack_depth): Eliminate direct access of call stack. * stack-frame.h, stack-frame.cc (stack_frame::install_variable, script_stack_frame::varval, script_stack_frame::varref, user_fcn_stack_frame::varval, usr_fcn_stack_frame::varref, scope_stack_frame::varval, scope_stack_frame::varref): Access global values through evaluator to eliminate direct access to call stack. (stack_frame::m_call_stack): Delete. (stack_frame::m_evaluator): New member variable. Update constructors.
author John W. Eaton <jwe@octave.org>
date Tue, 02 Apr 2019 11:51:24 +0000
parents bd684aad1821
children f84c5528e932
files libinterp/corefcn/call-stack.cc libinterp/corefcn/stack-frame.cc libinterp/corefcn/stack-frame.h libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h
diffstat 5 files changed, 59 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.cc	Mon Apr 01 21:33:22 2019 +0000
+++ b/libinterp/corefcn/call-stack.cc	Tue Apr 02 11:51:24 2019 +0000
@@ -352,7 +352,7 @@
     stack_frame *slink = get_static_link (prev_frame);
 
     stack_frame *new_frame
-      = new scope_stack_frame (*this, scope, m_curr_frame, slink);
+      = new scope_stack_frame (m_evaluator, scope, m_curr_frame, slink);
 
     m_cs.push_back (new_frame);
   }
@@ -370,7 +370,7 @@
     stack_frame *slink = get_static_link (prev_frame);
 
     stack_frame *new_frame
-      = new user_fcn_stack_frame (*this, fcn, up_frame, m_curr_frame,
+      = new user_fcn_stack_frame (m_evaluator, fcn, up_frame, m_curr_frame,
                                   slink, closure_frames);
 
     m_cs.push_back (new_frame);
@@ -388,7 +388,8 @@
     stack_frame *slink = get_static_link (prev_frame);
 
     stack_frame *new_frame
-      = new script_stack_frame (*this, script, up_frame, m_curr_frame, slink);
+      = new script_stack_frame (m_evaluator, script, up_frame, m_curr_frame,
+                                slink);
 
     m_cs.push_back (new_frame);
   }
@@ -405,7 +406,7 @@
     stack_frame *slink = get_static_link (prev_frame);
 
     stack_frame *new_frame
-      = new compiled_fcn_stack_frame (*this, fcn, m_curr_frame, slink);
+      = new compiled_fcn_stack_frame (m_evaluator, fcn, m_curr_frame, slink);
 
     m_cs.push_back (new_frame);
   }
@@ -1077,13 +1078,6 @@
       }
   }
 
-  void display_call_stack (void)
-  {
-    call_stack& cs = __get_call_stack__ ("display_call_stack");
-
-    cs.display ();
-  }
-
   void call_stack::set_auto_fcn_var (stack_frame::auto_var_type avt,
                                      const octave_value& val)
   {
@@ -1114,9 +1108,9 @@
 @seealso{max_recursion_depth}
 @end deftypefn */)
 {
-  octave::call_stack& cs = interp.get_call_stack ();
+  octave::tree_evaluator& tw = interp.get_evaluator ();
 
-  return cs.max_stack_depth (args, nargout);
+  return tw.max_stack_depth (args, nargout);
 }
 
 /*
--- a/libinterp/corefcn/stack-frame.cc	Mon Apr 01 21:33:22 2019 +0000
+++ b/libinterp/corefcn/stack-frame.cc	Tue Apr 02 11:51:24 2019 +0000
@@ -27,7 +27,6 @@
 #include "lo-regexp.h"
 #include "str-vec.h"
 
-#include "call-stack.h"
 #include "defun.h"
 #include "interpreter.h"
 #include "interpreter-private.h"
@@ -38,6 +37,7 @@
 #include "ov-usr-fcn.h"
 #include "pager.h"
 #include "parse.h"
+#include "pt-eval.h"
 #include "stack-frame.h"
 #include "stack-frame-walker.h"
 #include "syminfo.h"
@@ -386,7 +386,7 @@
             // global scope, then use the local value as the
             // initial value.  This value will also override any
             // initializer in the global statement.
-            octave_value global_val = m_call_stack.global_varval (nm);
+            octave_value global_val = m_evaluator.global_varval (nm);
 
             if (global_val.is_defined ())
               {
@@ -400,7 +400,7 @@
                 warning_with_id ("Octave:global-local-conflict",
                                  "global: existing local value used to initialize global variable");
 
-                m_call_stack.global_varref (nm) = val;
+                m_evaluator.global_varref (nm) = val;
               }
           }
 
@@ -556,12 +556,12 @@
     sfw.visit_compiled_fcn_stack_frame (*this);
   }
 
-  script_stack_frame::script_stack_frame (call_stack& cs,
+  script_stack_frame::script_stack_frame (tree_evaluator& tw,
                                           octave_user_script *script,
                                           unwind_protect *up_frame,
                                           size_t index,
                                           stack_frame *static_link)
-    : stack_frame (cs, index, static_link, get_access_link (static_link)),
+    : stack_frame (tw, index, static_link, get_access_link (static_link)),
       m_script (script), m_unwind_protect_frame (up_frame),
       m_lexical_frame_offsets (get_num_symbols (script), 1),
       m_value_offsets (get_num_symbols (script), 0)
@@ -1034,7 +1034,7 @@
         }
 
       case GLOBAL:
-        return m_call_stack.global_varval (sym.name ());
+        return m_evaluator.global_varval (sym.name ());
       }
 
     error ("internal error: invalid switch case");
@@ -1070,7 +1070,7 @@
         }
 
       case GLOBAL:
-        return m_call_stack.global_varref (sym.name ());
+        return m_evaluator.global_varref (sym.name ());
       }
 
     error ("internal error: invalid switch case");
@@ -1351,7 +1351,7 @@
         }
 
       case GLOBAL:
-        return m_call_stack.global_varval (sym.name ());
+        return m_evaluator.global_varval (sym.name ());
       }
 
     error ("internal error: invalid switch case");
@@ -1386,7 +1386,7 @@
         }
 
       case GLOBAL:
-        return m_call_stack.global_varref (sym.name ());
+        return m_evaluator.global_varref (sym.name ());
       }
 
     error ("internal error: invalid switch case");
@@ -1484,7 +1484,7 @@
         return m_scope.persistent_varval (data_offset);
 
       case GLOBAL:
-        return m_call_stack.global_varval (sym.name ());
+        return m_evaluator.global_varval (sym.name ());
       }
 
     error ("internal error: invalid switch case");
@@ -1509,7 +1509,7 @@
         return m_scope.persistent_varref (data_offset);
 
       case GLOBAL:
-        return m_call_stack.global_varref (sym.name ());
+        return m_evaluator.global_varref (sym.name ());
       }
 
     error ("internal error: invalid switch case");
--- a/libinterp/corefcn/stack-frame.h	Mon Apr 01 21:33:22 2019 +0000
+++ b/libinterp/corefcn/stack-frame.h	Tue Apr 02 11:51:24 2019 +0000
@@ -72,9 +72,9 @@
 //
 // All stack frames also contain the following data:
 //
-//  * a reference to the call stack that contains the frame
+//  * a reference to the evaluator that contains the frame
 //
-//    Global variables are now stored in the call stack and this link
+//    Global variables are now stored in the evaluator and this link
 //    gives us immediate access to them.
 //
 //  * line and column in the source file where the stack frame was created
@@ -97,7 +97,6 @@
 
 namespace octave
 {
-  class call_stack;
   class tree_evaluator;
   class symbol_info_list;
   class unwind_protect;
@@ -115,7 +114,7 @@
 
     // Markers indicating the type of a variable.  Values for local
     // variables are stored in the stack frame.  Values for
-    // global variables are stored in the call_stack object that
+    // global variables are stored in the tree_evaluator object that
     // contains the stack frame.  Values for persistent variables are
     // stored in the function scope corresponding to the stack frame.
 
@@ -141,9 +140,9 @@
 
     stack_frame (void) = delete;
 
-    stack_frame (call_stack& cs, size_t index,
+    stack_frame (tree_evaluator& tw, size_t index,
                  stack_frame *static_link, stack_frame *access_link)
-      : m_call_stack (cs), m_line (-1), m_column (-1), m_index (index),
+      : m_evaluator (tw), m_line (-1), m_column (-1), m_index (index),
         m_static_link (static_link), m_access_link (access_link),
         m_dispatch_class ()
     { }
@@ -558,7 +557,7 @@
     // Reference to the call stack that contains this frame.  Global
     // variables are stored in the call stack.  This link gives us
     // immediate access to them.
-    call_stack& m_call_stack;
+    tree_evaluator& m_evaluator;
 
     // The line and column of the source file where this stack frame
     // was created.  Used to print stack traces.
@@ -588,9 +587,9 @@
 
     compiled_fcn_stack_frame (void) = delete;
 
-    compiled_fcn_stack_frame (call_stack& cs, octave_function *fcn,
+    compiled_fcn_stack_frame (tree_evaluator& tw, octave_function *fcn,
                               size_t index, stack_frame *static_link)
-      : stack_frame (cs, index, static_link, static_link->access_link ()),
+      : stack_frame (tw, index, static_link, static_link->access_link ()),
         m_fcn (fcn)
     { }
 
@@ -709,7 +708,7 @@
 
     script_stack_frame (void) = delete;
 
-    script_stack_frame (call_stack& cs, octave_user_script *script,
+    script_stack_frame (tree_evaluator& tw, octave_user_script *script,
                         unwind_protect *up_frame, size_t index,
                         stack_frame *static_link);
 
@@ -819,10 +818,10 @@
 
     base_value_stack_frame (void) = delete;
 
-    base_value_stack_frame (call_stack& cs, size_t num_symbols,
+    base_value_stack_frame (tree_evaluator& tw, size_t num_symbols,
                             size_t index, stack_frame *static_link,
                             stack_frame *access_link)
-      : stack_frame (cs, index, static_link, access_link),
+      : stack_frame (tw, index, static_link, access_link),
         m_values (num_symbols, octave_value ()),
         m_flags (num_symbols, LOCAL),
         m_auto_vars (NUM_AUTO_VARS, octave_value ())
@@ -895,7 +894,7 @@
     // value.  This array is indexed by the data_offset value stored
     // in the symbol_record objects of the scope associated with this
     // stack frame.  Local values are found in the M_VALUES array.
-    // Global values are stored in the call_stack object that contains
+    // Global values are stored in the tree_evaluator object that contains
     // the stack frame.  Persistent values are stored in the function
     // scope corresponding to the stack frame.
     std::vector<scope_flags> m_flags;
@@ -923,11 +922,11 @@
 
     user_fcn_stack_frame (void) = delete;
 
-    user_fcn_stack_frame (call_stack& cs, octave_user_function *fcn,
+    user_fcn_stack_frame (tree_evaluator& tw, octave_user_function *fcn,
                           unwind_protect *up_frame, size_t index,
                           stack_frame *static_link,
                           stack_frame *access_link = nullptr)
-      : base_value_stack_frame (cs, get_num_symbols (fcn), index, static_link,
+      : base_value_stack_frame (tw, get_num_symbols (fcn), index, static_link,
                                 (access_link
                                  ? access_link
                                  : get_access_link (fcn, static_link))),
@@ -1010,9 +1009,9 @@
 
     scope_stack_frame (void) = delete;
 
-    scope_stack_frame (call_stack& cs, const symbol_scope& scope,
-                        size_t index, stack_frame *static_link)
-      : base_value_stack_frame (cs, scope.num_symbols (), index,
+    scope_stack_frame (tree_evaluator& tw, const symbol_scope& scope,
+                       size_t index, stack_frame *static_link)
+      : base_value_stack_frame (tw, scope.num_symbols (), index,
                                 static_link, nullptr),
         m_scope (scope)
     { }
--- a/libinterp/parse-tree/pt-eval.cc	Mon Apr 01 21:33:22 2019 +0000
+++ b/libinterp/parse-tree/pt-eval.cc	Tue Apr 02 11:51:24 2019 +0000
@@ -1340,6 +1340,12 @@
     return m_call_stack.global_varval (name);
   }
 
+  octave_value&
+  tree_evaluator::global_varref (const std::string& name)
+  {
+    return m_call_stack.global_varref (name);
+  }
+
   void
   tree_evaluator::global_assign (const std::string& name,
                                  const octave_value& val)
@@ -2037,6 +2043,17 @@
     return m_call_stack.current_scope ();
   }
 
+  octave_value
+  tree_evaluator::max_stack_depth (const octave_value_list& args, int nargout)
+  {
+    return m_call_stack.max_stack_depth (args, nargout);
+  }
+
+  void tree_evaluator::display_call_stack (void) const
+  {
+    m_call_stack.display ();
+  }
+
   octave_value tree_evaluator::find (const std::string& name)
   {
     const stack_frame& frame = m_call_stack.get_current_stack_frame ();
--- a/libinterp/parse-tree/pt-eval.h	Mon Apr 01 21:33:22 2019 +0000
+++ b/libinterp/parse-tree/pt-eval.h	Tue Apr 02 11:51:24 2019 +0000
@@ -398,6 +398,8 @@
 
     octave_value global_varval (const std::string& name) const;
 
+    octave_value& global_varref (const std::string& name);
+
     void global_assign (const std::string& name,
                         const octave_value& val = octave_value ());
 
@@ -553,6 +555,11 @@
     symbol_scope get_top_scope (void) const;
     symbol_scope get_current_scope (void) const;
 
+    octave_value max_stack_depth (const octave_value_list& args, int nargout);
+
+    // Useful for debugging
+    void display_call_stack (void) const;
+
     octave_value find (const std::string& name);
 
     void clear_objects (void);