Mercurial > octave
annotate libinterp/corefcn/interpreter.h @ 23092:0fed4c678795
additional restructuring of startup and shutdown
* main-window.h, main-window.cc (main_window::~main_window):
Don't delete _octave_qt_link here.
(main_window::exit_app): Delete.
(main_window::construct_octave_qt_link): Delete connection from
octave_qt_link::exit_app_signal to main_window::exit_app slot.
Call octave_link::connect_link immediately after constructing new
octave_qt_link_object.
* octave-interpreter.h, octave-interpreter.cc
(octave_interpreter::m_exit_status): Delete unused data member.
(octave_interpreter::execute): Call qApp->exit here.
* octave-link.h (octave_link::do_exit): Delete.
(octave_link::exit): Delete.
(octave_link::disconnect_link, octave_link::enable,
octave_link::disable, octave_link::do_enable,
octave_link::do_disable): New functions.
(octave_link::process_events): Call do_disable instead of accessing link_enabled directly.
(octave_link::confirm_shutdown): Check enabled, not instance_ok.
* octave-qt-link.h, octave-qt-link.cc (octave_qt_link::do_exit):
Delete.
(octave_qt_link::exit_app_signal): Delete.
* interpreter.h, interpreter.cc (interpreter::execute_internal):
New function. Perform interpreter::execute actions here. Simply handle
If not in persist mode, simply return status from
execute_eval_option_code and execute_command_line_file.
Simply return status from main_loop. Don't set m_quitting_gracefully here.
(interpreter::execute): Wrap interpreter::execute_internal in
try-catch block. If exit_exception is caught, process octave_link
events and disconnect link here. Call cleanup here, not from destructor.
(interpreter::m_quitting_gracefully): Delete data member and all uses.
(safe_source_file, execute_pkg_add): Don't catch index_exception.
Dopn't display message for execution_exception.
(initialize_load_path, execute_startup_files):
Return status from safe_source_file. Don't fail, but preserve any
non-zero status.
(interpreter::execute_eval_option_code):
Don't catch exit_exception here.
(interpreter::main_loop): Don't print extra newline when interactive
main loop is done.
(interpreter::cleanup): Don't call raw_mode.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 26 Jan 2017 08:26:46 -0500 |
parents | 9f406f0b36da |
children | 373771419d51 |
rev | line source |
---|---|
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
3 Copyright (C) 2002-2016 John W. Eaton |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #if ! defined (octave_interpreter_h) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 #define octave_interpreter_h 1 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #include "octave-config.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include <string> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "quit.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "str-vec.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
33 #include "pt-eval.h" |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
34 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 extern OCTINTERP_API bool quit_allowed; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 extern OCTINTERP_API bool quitting_gracefully; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 extern OCTINTERP_API void recover_from_exception (void); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 extern OCTINTERP_API void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 octave_add_atexit_function (const std::string& fname); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 extern OCTINTERP_API bool |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 octave_remove_atexit_function (const std::string& fname); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 // TRUE means we are ready to interpret commands, but not everything |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 // is ready for interactive use. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 extern OCTINTERP_API bool octave_interpreter_ready; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 // TRUE means we've processed all the init code and we are good to go. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 extern OCTINTERP_API bool octave_initialized; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 // Call a function with exceptions handled to avoid problems with |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 // errors while shutting down. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
57 #define OCTAVE_IGNORE_EXCEPTION(E) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
58 catch (E) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
59 { \ |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 std::cerr << "error: ignoring " #E " while preparing to exit" << std::endl; \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
61 recover_from_exception (); \ |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
64 #define OCTAVE_SAFE_CALL(F, ARGS) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
65 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
66 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
67 try \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
68 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
69 octave::unwind_protect frame; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
70 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
71 frame.protect_var (Vdebug_on_error); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
72 frame.protect_var (Vdebug_on_warning); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
73 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
74 Vdebug_on_error = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
75 Vdebug_on_warning = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
76 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
77 F ARGS; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
78 } \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
79 OCTAVE_IGNORE_EXCEPTION (const octave::interrupt_exception&) \ |
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
80 OCTAVE_IGNORE_EXCEPTION (const octave::execution_exception&) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
81 OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
82 } \ |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 while (0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 namespace octave |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 { |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
87 extern tree_evaluator *current_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
88 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 // The application object contains a pointer to the current |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 // interpreter and the interpreter contains a pointer back to the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 // application context so we need a forward declaration for one (or |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 // both) of them... |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 class application; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 class OCTINTERP_API interpreter |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 public: |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 interpreter (application *app_context = 0, bool embedded = false); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
102 // No copying, at least not yet... |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
103 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
104 interpreter (const interpreter&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
105 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
106 interpreter& operator = (const interpreter&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
107 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
108 ~interpreter (void); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 int execute (void); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 int execute_eval_option_code (const std::string& code); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
114 int execute_command_line_file (const std::string& fname); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 bool interactive (void) const { return m_interactive; } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 void interactive (bool arg) { m_interactive = arg; } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 private: |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 |
23092
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
121 int execute_internal (void); |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
122 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 int main_loop (void); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
125 void cleanup (void); |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
126 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 application *m_app_context; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
129 tree_evaluator *m_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22157
diff
changeset
|
130 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 bool m_embedded; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 // TRUE means this is an interactive interpreter (forced or not). |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 bool m_interactive; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 }; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 #endif |