# HG changeset patch # User Petter T. # Date 1687208478 14400 # Node ID 18c6b6997055e3deca1abc7333754927b5695dff # Parent 00740c1f8e82c7dca9face78d7759cb894dddba7 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. diff -r 00740c1f8e82 -r 18c6b6997055 libinterp/corefcn/call-stack.cc --- 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 call_stack::pop_return () +{ + if (!m_cs.empty ()) + { + std::shared_ptr 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 ()) diff -r 00740c1f8e82 -r 18c6b6997055 libinterp/corefcn/call-stack.h --- 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 pop_return (); + void clear (); symbol_info_list all_variables (); diff -r 00740c1f8e82 -r 18c6b6997055 libinterp/parse-tree/pt-eval.cc --- 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 +tree_evaluator::pop_return_stack_frame () +{ + return m_call_stack.pop_return (); +} + int tree_evaluator::current_line () const { return m_call_stack.current_line (); diff -r 00740c1f8e82 -r 18c6b6997055 libinterp/parse-tree/pt-eval.h --- 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 pop_return_stack_frame (); + std::shared_ptr get_current_stack_frame () const { return m_call_stack.get_current_stack_frame ();