Mercurial > octave
diff libinterp/corefcn/variables.cc @ 23553:14723784b9f2
don't use singleton for call_stack
* call-stack.h, call-stack.cc (class call_stack):
Don't use singleton pattern. Store reference to parent intepreter
object in call stack.
* pt-eval.h, pt-eval.cc (tree_evaluator::m_call_stack): New data
member.
(tree_evaluator::get_call_stack): New function.
* interpreter-private.h, interpreter-private.cc (__get_call_stack__):
New function.
* interpreter.h, interpreter.cc (interpreter::get_call_stack):
New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 Jun 2017 02:13:05 -0400 |
parents | 5da300c55e89 |
children | 7b47b7c2d6c7 |
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc Wed Jun 07 02:08:22 2017 -0400 +++ b/libinterp/corefcn/variables.cc Wed Jun 07 02:13:05 2017 -0400 @@ -740,7 +740,9 @@ template <typename T> bool try_local_protect (T& var) { - octave_user_code *curr_usr_code = octave::call_stack::caller_user_code (); + octave::call_stack& cs = octave::__get_call_stack__ ("try_local_protect"); + + octave_user_code *curr_usr_code = cs.caller_user_code (); octave_user_function *curr_usr_fcn = nullptr; if (curr_usr_code && curr_usr_code->is_user_function ()) curr_usr_fcn = dynamic_cast<octave_user_function *> (curr_usr_code); @@ -1633,11 +1635,13 @@ }; static octave_value -do_who (int argc, const string_vector& argv, bool return_list, - bool verbose = false, std::string msg = "") +do_who (octave::interpreter& interp, int argc, const string_vector& argv, + bool return_list, bool verbose = false, std::string msg = "") { octave_value retval; + octave::call_stack& cs = interp.get_call_stack (); + std::string my_name = argv[0]; bool global_only = false; @@ -1668,8 +1672,8 @@ symbol_table::set_scope (tmp_scope); - octave::call_stack::push (tmp_scope, 0); - frame.add_fcn (octave::call_stack::pop); + cs.push (tmp_scope, 0); + frame.add_method (cs, &octave::call_stack::pop); frame.add_fcn (symbol_table::clear_variables); @@ -1678,7 +1682,7 @@ std::string newmsg = std::string ("Variables in the file ") + nm + ":\n\n"; - retval = do_who (i, argv, return_list, verbose, newmsg); + retval = do_who (interp, i, argv, return_list, verbose, newmsg); return retval; } @@ -1790,7 +1794,7 @@ if (verbose) { std::string caller_function_name; - octave_function *caller = octave::call_stack::caller (); + octave_function *caller = cs.caller (); if (caller) caller_function_name = caller->name (); @@ -1824,8 +1828,8 @@ return retval; } -DEFUN (who, args, nargout, - doc: /* -*- texinfo -*- +DEFMETHOD (who, interp, args, nargout, + doc: /* -*- texinfo -*- @deftypefn {} {} who @deftypefnx {} {} who pattern @dots{} @deftypefnx {} {} who option pattern @dots{} @@ -1863,11 +1867,11 @@ string_vector argv = args.make_argv ("who"); - return do_who (argc, argv, nargout == 1); + return do_who (interp, argc, argv, nargout == 1); } -DEFUN (whos, args, nargout, - doc: /* -*- texinfo -*- +DEFMETHOD (whos, interp, args, nargout, + doc: /* -*- texinfo -*- @deftypefn {} {} whos @deftypefnx {} {} whos pattern @dots{} @deftypefnx {} {} whos option pattern @dots{} @@ -1934,7 +1938,7 @@ string_vector argv = args.make_argv ("whos"); - return do_who (argc, argv, nargout == 1, true); + return do_who (interp, argc, argv, nargout == 1, true); } // Defining variables. @@ -1980,7 +1984,9 @@ void mlock (void) { - octave_function *fcn = octave::call_stack::current (); + octave::call_stack& cs = octave::__get_call_stack__ ("mlock"); + + octave_function *fcn = cs.current (); if (! fcn) error ("mlock: invalid use outside a function"); @@ -2020,8 +2026,8 @@ return retval; } -DEFUN (mlock, args, , - doc: /* -*- texinfo -*- +DEFMETHOD (mlock, interp, args, , + doc: /* -*- texinfo -*- @deftypefn {} {} mlock () Lock the current function into memory so that it can't be cleared. @seealso{munlock, mislocked, persistent} @@ -2030,7 +2036,9 @@ if (args.length () != 0) print_usage (); - octave_function *fcn = octave::call_stack::caller (); + octave::call_stack& cs = interp.get_call_stack (); + + octave_function *fcn = cs.caller (); if (! fcn) error ("mlock: invalid use outside a function"); @@ -2040,8 +2048,8 @@ return ovl (); } -DEFUN (munlock, args, , - doc: /* -*- texinfo -*- +DEFMETHOD (munlock, interp, args, , + doc: /* -*- texinfo -*- @deftypefn {} {} munlock () @deftypefnx {} {} munlock (@var{fcn}) Unlock the named function @var{fcn}. @@ -2063,7 +2071,9 @@ } else { - octave_function *fcn = octave::call_stack::caller (); + octave::call_stack& cs = interp.get_call_stack (); + + octave_function *fcn = cs.caller (); if (! fcn) error ("munlock: invalid use outside a function"); @@ -2074,8 +2084,8 @@ return ovl (); } -DEFUN (mislocked, args, , - doc: /* -*- texinfo -*- +DEFMETHOD (mislocked, interp, args, , + doc: /* -*- texinfo -*- @deftypefn {} {} mislocked () @deftypefnx {} {} mislocked (@var{fcn}) Return true if the named function @var{fcn} is locked. @@ -2099,7 +2109,9 @@ } else { - octave_function *fcn = octave::call_stack::caller (); + octave::call_stack& cs = interp.get_call_stack (); + + octave_function *fcn = cs.caller (); if (! fcn) error ("mislocked: invalid use outside a function");