Mercurial > octave
diff libinterp/corefcn/interpreter.cc @ 29846:78cb255c78a4 stable
move top-level REPL from interpreter to evaluator
* pt-eval.h, pt-eval.cc (tree_evaluator::m_in_top_level_repl):
New member variable.
(tree_evaluator::in_top_level_repl): New function.
(tree_evaluator::repl): New function, adapted from interepreter::main_loop.
* interpreter.h interpreter.cc (interpreter::m_in_top_level_repl): Delete.
(interpreter::in_top_level_repl): Forward to tree_evaluator::in_top_level_repl.
(interpreter::main_loop): Forward to tree_evaluator::repl.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Jul 2021 09:38:48 -0400 |
parents | 841ca9987302 |
children | 449599fdbad8 |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Thu Jul 01 13:24:03 2021 +0200 +++ b/libinterp/corefcn/interpreter.cc Fri Jul 02 09:38:48 2021 -0400 @@ -466,7 +466,6 @@ m_inhibit_startup_message (false), m_load_path_initialized (false), m_history_initialized (false), - m_in_top_level_repl (false), m_cancel_quit (false), m_executing_finish_script (false), m_executing_atexit (false), @@ -1207,132 +1206,7 @@ int interpreter::main_loop (void) { - // The big loop. Read, Eval, Print, Loop. Normally user - // interaction at the command line in a terminal session, but we may - // also end up here when reading from a pipe or when stdin is - // connected to a file by the magic of input redirection. - - int exit_status = 0; - - // FIXME: should this choice be a command-line option? Note that we - // intend that the push parser interface only be used for - // interactive sessions. - -#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) - static bool use_command_line_push_parser = true; -#else - static bool use_command_line_push_parser = false; -#endif - - // The following logic is written as it is to allow easy transition - // to setting USE_COMMAND_LINE_PUSH_PARSER at run time and to - // simplify the logic of the main loop below by using the same - // base_parser::run interface for both push and pull parsers. - - std::shared_ptr<base_parser> repl_parser; - - if (m_interactive) - { - if (use_command_line_push_parser) - { - push_parser *pp = new push_parser (*this, new input_reader (*this)); - repl_parser = std::shared_ptr<base_parser> (pp); - } - else - { - parser *pp = new parser (new lexer (*this)); - repl_parser = std::shared_ptr<base_parser> (pp); - } - } - else - { - parser *pp = new parser (new lexer (stdin, *this)); - repl_parser = std::shared_ptr<base_parser> (pp); - } - - do - { - try - { - unwind_protect_var<bool> upv (m_in_top_level_repl, true); - - repl_parser->reset (); - - if (m_evaluator.at_top_level ()) - { - m_evaluator.dbstep_flag (0); - m_evaluator.reset_debug_state (); - } - - exit_status = repl_parser->run (); - - if (exit_status == 0) - { - std::shared_ptr<tree_statement_list> - stmt_list = repl_parser->statement_list (); - - if (stmt_list) - { - command_editor::increment_current_command_number (); - - m_evaluator.eval (stmt_list, m_interactive); - } - else if (repl_parser->at_end_of_input ()) - { - exit_status = EOF; - break; - } - } - } - catch (const interrupt_exception&) - { - recover_from_exception (); - - // Required newline when the user does Ctrl+C at the prompt. - if (m_interactive) - octave_stdout << "\n"; - } - catch (const index_exception& e) - { - recover_from_exception (); - - std::cerr << "error: unhandled index exception: " - << e.message () << " -- trying to return to prompt" - << std::endl; - } - catch (const execution_exception& ee) - { - m_error_system.save_exception (ee); - m_error_system.display_exception (ee, std::cerr); - - if (m_interactive) - recover_from_exception (); - else - { - // We should exit with a nonzero status. - exit_status = 1; - break; - } - } - catch (const std::bad_alloc&) - { - recover_from_exception (); - - std::cerr << "error: out of memory -- trying to return to prompt" - << std::endl; - } - } - while (exit_status == 0); - - if (exit_status == EOF) - { - if (m_interactive) - octave_stdout << "\n"; - - exit_status = 0; - } - - return exit_status; + return m_evaluator.repl (); } tree_evaluator& interpreter::get_evaluator (void)