Mercurial > octave
changeset 32146:18c6b6997055
new function to pop and return top of call stack
* call-stack.h, call-stack.cc (call_stack::pop_return): New function.
* pt-eval.h, pt-eval.cc (tree_evaluator::pop_return_stack_frame):
New function.
author | Petter T. <petter.vilhelm@gmail.com> |
---|---|
date | Mon, 19 Jun 2023 17:01:18 -0400 |
parents | 00740c1f8e82 |
children | 8763a313ab91 |
files | libinterp/corefcn/call-stack.cc libinterp/corefcn/call-stack.h libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h |
diffstat | 4 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.cc Mon Jun 19 15:28:32 2023 -0400 +++ b/libinterp/corefcn/call-stack.cc Mon Jun 19 17:01:18 2023 -0400 @@ -772,6 +772,24 @@ } } +std::shared_ptr<stack_frame> call_stack::pop_return () +{ + if (!m_cs.empty ()) + { + std::shared_ptr<stack_frame> elt = std::move (m_cs.back ()); + m_cs.pop_back (); + + m_curr_frame = elt->parent_frame_index (); + + if (elt->is_closure_context ()) + elt->break_closure_cycles (elt); + + return elt; + } + + return nullptr; +} + void call_stack::clear () { while (! m_cs.empty ())
--- a/libinterp/corefcn/call-stack.h Mon Jun 19 15:28:32 2023 -0400 +++ b/libinterp/corefcn/call-stack.h Mon Jun 19 17:01:18 2023 -0400 @@ -242,6 +242,8 @@ void pop (); + std::shared_ptr<stack_frame> pop_return (); + void clear (); symbol_info_list all_variables ();
--- a/libinterp/parse-tree/pt-eval.cc Mon Jun 19 15:28:32 2023 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Mon Jun 19 17:01:18 2023 -0400 @@ -2465,6 +2465,12 @@ m_call_stack.pop (); } +std::shared_ptr<stack_frame> +tree_evaluator::pop_return_stack_frame () +{ + return m_call_stack.pop_return (); +} + int tree_evaluator::current_line () const { return m_call_stack.current_line ();
--- a/libinterp/parse-tree/pt-eval.h Mon Jun 19 15:28:32 2023 -0400 +++ b/libinterp/parse-tree/pt-eval.h Mon Jun 19 17:01:18 2023 -0400 @@ -438,6 +438,8 @@ void pop_stack_frame (); + std::shared_ptr<stack_frame> pop_return_stack_frame (); + std::shared_ptr<stack_frame> get_current_stack_frame () const { return m_call_stack.get_current_stack_frame ();