Mercurial > octave
annotate libinterp/corefcn/interpreter.cc @ 23435:c452180ab672
begin refactoring parse tree evaluator
* libinterp/parse-tree/pt-tm-const.cc,
libinterp/parse-tree/pt-tm-const.h:
New files, extracted from pt-mat.h and pt-mat.cc.
* libinterp/parse-tree/module.mk: Update.
* interpreter.cc, ov-class.cc, ov-classdef.cc, ov-classdef.h,
ov-fcn-handle.cc, ov-fcn-handle.h, ov-usr-fcn.cc, oct-parse.in.yy,
pt-arg-list.cc, pt-arg-list.h, pt-array-list.h, pt-assign.cc,
pt-assign.h, pt-binop.cc, pt-binop.h, pt-cbinop.cc, pt-cbinop.h,
pt-cell.cc, pt-cell.h, pt-classdef.cc, pt-classdef.h, pt-cmd.cc,
pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h,
pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h,
pt-funcall.cc, pt-funcall.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h,
pt-jit.cc, pt-jump.cc, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-select.cc, pt-select.h,
pt-stmt.cc, pt-stmt.h, pt-unop.cc, pt-unop.h:
Use tree_evaluator class to walk the parse tree instead of rvalue
methods in the parse tree classes. Maintain a stack in the evaluator
class to accumulate results.
Pass pointer to evaluator to function objects and other classes as
needed for evaluation.
This is a work in progress that is not yet complete. The ultimate
goal is to move all evaluation into the tree_evaluator class instead
of spreading that work among many different classes. The global
pointer to the current evaluator should also be eliminated.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 21 Apr 2017 18:07:40 -0400 |
parents | 945b53af4655 |
children | d24d01273bd0 |
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 |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1993-2017 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:
22718
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:
22718
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22718
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:
22718
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:
22718
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22718
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22718
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 (HAVE_CONFIG_H) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 # include "config.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #include <string> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include <iostream> |
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 "cmd-edit.h" |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
31 #include "cmd-hist.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "file-ops.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include "file-stat.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "fpucw-wrappers.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
35 #include "lo-blas-proto.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include "lo-error.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "oct-env.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 #include "str-vec.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "signal-wrappers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 #include "unistd-wrappers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include "builtins.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include "defaults.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "Cell.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 #include "defun.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "display.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #include "error.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 #include "file-io.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 #include "graphics.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 #include "interpreter.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 #include "load-path.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 #include "load-save.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 #include "octave-link.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 #include "octave.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 #include "oct-hist.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 #include "oct-map.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 #include "oct-mutex.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 #include "ops.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 #include "ovl.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 #include "ov.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 #include "ov-classdef.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 #include "parse.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 #include "pt-eval.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 #include "pt-jump.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23117
diff
changeset
|
65 #include "pt-mat.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 #include "pt-stmt.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 #include "sighandlers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 #include "sysdep.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 #include "unwind-prot.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 #include "utils.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 #include "variables.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 #include <version.h> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 // TRUE means the quit() call is allowed. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 bool quit_allowed = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 // 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
|
78 // is ready for interactive use. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 bool octave_interpreter_ready = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 // 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
|
82 bool octave_initialized = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 DEFUN (__version_info__, args, , |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 @deftypefn {} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 Undocumented internal function. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 static octave_map vinfo; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 int nargin = args.length (); |
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 if (nargin != 0 && nargin != 4) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 print_usage (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 octave_value retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 if (nargin == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 retval = vinfo; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 else if (nargin == 4) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 if (vinfo.nfields () == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 vinfo.assign ("Name", args(0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 vinfo.assign ("Version", args(1)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 vinfo.assign ("Release", args(2)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 vinfo.assign ("Date", args(3)); |
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 else |
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 octave_idx_type n = vinfo.numel () + 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 vinfo.resize (dim_vector (n, 1)); |
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 octave_value idx (n); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 vinfo.assign (idx, "Name", Cell (octave_value (args(0)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 vinfo.assign (idx, "Version", Cell (octave_value (args(1)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 vinfo.assign (idx, "Release", Cell (octave_value (args(2)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 vinfo.assign (idx, "Date", Cell (octave_value (args(3)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 initialize_version_info (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 octave_value_list args; |
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 args(3) = OCTAVE_RELEASE_DATE; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 args(2) = OCTAVE_RELEASE; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 args(1) = OCTAVE_VERSION; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 args(0) = "GNU Octave"; |
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 F__version_info__ (args, 0); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 OCTAVE_NORETURN static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 lo_error_handler (const char *fmt, ...) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 va_list args; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 va_start (args, fmt); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 verror_with_cfn (fmt, args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 va_end (args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 octave_throw_execution_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 OCTAVE_NORETURN static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 lo_error_with_id_handler (const char *id, const char *fmt, ...) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
155 va_list args; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 va_start (args, fmt); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 verror_with_id_cfn (id, fmt, args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 va_end (args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 octave_throw_execution_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 initialize_error_handlers () |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 set_liboctave_error_handler (lo_error_handler); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 set_liboctave_error_with_id_handler (lo_error_with_id_handler); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 set_liboctave_warning_handler (warning); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 set_liboctave_warning_with_id_handler (warning_with_id); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
170 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 // What internal options get configured by --traditional. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 maximum_braindamage (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 FPS1 (octave_value (">> ")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 FPS2 (octave_value ("")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 FPS4 (octave_value ("")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 Fbeep_on_error (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
181 Fconfirm_recursive_rmdir (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 Fcrash_dumps_octave_core (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
183 Fdisable_diagonal_matrix (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 Fdisable_permutation_matrix (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 Fdisable_range (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 Ffixed_point_format (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 Fpage_screen_output (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 Fprint_empty_dimensions (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 Fsave_default_options (octave_value ("-mat-binary")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
191 Fstruct_levels_to_print (octave_value (0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 disable_warning ("Octave:abbreviated-property-match"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 disable_warning ("Octave:data-file-in-path"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 disable_warning ("Octave:function-name-clash"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 disable_warning ("Octave:possible-matlab-short-circuit-operator"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 DEFUN (quit, args, , |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 @deftypefn {} {} exit |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
202 @deftypefnx {} {} exit (@var{status}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 @deftypefnx {} {} quit |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 @deftypefnx {} {} quit (@var{status}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 Exit the current Octave session. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
206 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 If the optional integer value @var{status} is supplied, pass that value to |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 the operating system as Octave's exit status. The default value is zero. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
210 When exiting, Octave will attempt to run the m-file @file{finish.m} if it |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
211 exists. User commands to save the workspace or clean up temporary files |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
212 may be placed in that file. Alternatively, another m-file may be scheduled |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
213 to run using @code{atexit}. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 @seealso{atexit} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 // Confirm OK to shutdown. Note: A dynamic function installation similar |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 // to overriding polymorphism for which the GUI can install its own "quit" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 // yet call this base "quit" could be nice. No link would be needed here. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 if (! octave_link::confirm_shutdown ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 return ovl (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
223 if (! quit_allowed) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 error ("quit: not supported in embedded mode"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 int exit_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
227 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 if (args.length () > 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 exit_status = args(0).nint_value (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 // Instead of simply calling exit, we thrown an exception so that no |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 // matter where the call to quit occurs, we will run the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 // unwind_protect stack, clear the OCTAVE_LOCAL_BUFFER allocations, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 // etc. before exiting. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
236 throw octave::exit_exception (exit_status); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 return ovl (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
240 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 DEFALIAS (exit, quit); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
243 DEFUN (atexit, args, nargout, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 @deftypefn {} {} atexit (@var{fcn}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 @deftypefnx {} {} atexit (@var{fcn}, @var{flag}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 Register a function to be called when Octave exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 For example, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 @example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
252 @group |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 function last_words () |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 disp ("Bye bye"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 endfunction |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 atexit ("last_words"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 @end group |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
258 @end example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 @noindent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 will print the message @qcode{"Bye bye"} when Octave exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
262 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 The additional argument @var{flag} will register or unregister @var{fcn} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 from the list of functions to be called when Octave exits. If @var{flag} is |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 true, the function is registered, and if @var{flag} is false, it is |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 unregistered. For example, after registering the function @code{last_words} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 above, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 @example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 atexit ("last_words", false); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
271 @end example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 @noindent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 will remove the function from the list and Octave will not call |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
275 @code{last_words} when it exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
277 Note that @code{atexit} only removes the first occurrence of a function |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
278 from the list, so if a function was placed in the list multiple times with |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
279 @code{atexit}, it must also be removed from the list multiple times. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
280 @seealso{quit} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
281 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 int nargin = args.length (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
285 if (nargin < 1 || nargin > 2) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 print_usage (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
287 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
288 std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
289 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
290 bool add_mode = (nargin == 2) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
291 ? args(1).xbool_value ("atexit: FLAG argument must be a logical value") |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
292 : true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
294 octave_value_list retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
295 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
296 if (add_mode) |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
297 octave::interpreter::add_atexit_function (arg); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
298 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
299 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
300 bool found = octave::interpreter::remove_atexit_function (arg); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
301 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
302 if (nargout > 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
303 retval = ovl (found); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
304 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
307 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
308 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
309 // Execute commands from a file and catch potential exceptions in a consistent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
310 // way. This function should be called anywhere we might parse and execute |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22133
diff
changeset
|
311 // commands from a file before we have entered the main loop in |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
312 // toplev.cc. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
313 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
314 static int |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
315 safe_source_file (const std::string& file_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
316 const std::string& context = "", |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
317 bool verbose = false, bool require_file = true, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
318 const std::string& warn_for = "") |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
322 octave::source_file (file_name, context, verbose, require_file, warn_for); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
323 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
324 catch (const octave::interrupt_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
325 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
326 octave::interpreter::recover_from_exception (); |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
327 |
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
328 return 1; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
329 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
330 catch (const octave::execution_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
331 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
332 octave::interpreter::recover_from_exception (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
333 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
334 return 1; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
335 } |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
336 |
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
337 return 0; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 execute_pkg_add (const std::string& dir) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
342 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 std::string file_name = octave::sys::file_ops::concat (dir, "PKG_ADD"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 load_path::execute_pkg_add (dir); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
349 catch (const octave::interrupt_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
351 octave::interpreter::recover_from_exception (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
353 catch (const octave::execution_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
355 octave::interpreter::recover_from_exception (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 namespace octave |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 { |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
361 tree_evaluator *current_evaluator = 0; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
362 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
363 // Create an interpreter object and perform initialization up to the |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
364 // point of setting reading command history and setting the load |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
365 // path. |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
366 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
367 interpreter::interpreter (application *app_context) |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
368 : m_app_context (app_context), m_evaluator (new tree_evaluator (this)), |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
369 m_interactive (false), m_read_site_files (true), |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
370 m_read_init_files (m_app_context != 0), m_verbose (false), |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
371 m_inhibit_startup_message (false), m_load_path_initialized (false), |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
372 m_history_initialized (false), m_initialized (false) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 { |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
374 current_evaluator = m_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
375 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
376 // This should probably happen early. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
377 sysdep_init (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
378 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
379 // Need to have global Vfoo variables defined early. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
380 install_defaults (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
381 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
383 setlocale (LC_NUMERIC, "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
384 setlocale (LC_TIME, "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 octave::sys::env::putenv ("LC_NUMERIC", "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
386 octave::sys::env::putenv ("LC_TIME", "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 // Initialize the default floating point unit control state. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
389 octave_set_default_fpucw (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
390 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23011
diff
changeset
|
391 octave::thread::init (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 set_default_prompts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
394 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 // Initialize default warning state before --traditional option |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 // that may reset them. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 initialize_default_warning_state (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
399 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
400 octave_ieee_init (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
402 octave_prepare_hdf5 (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 // The idea here is to force xerbla to be referenced so that we will link to |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 // our own version instead of the one provided by the BLAS library. But |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 // octave::numeric_limits<double>::NaN () should never be -1, so we |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 // should never actually call xerbla. FIXME (again!): If this |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 // becomes a constant expression the test might be optimized away and |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 // then the reference to the function might also disappear. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 if (octave::numeric_limits<double>::NaN () == -1) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
412 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 initialize_error_handlers (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
416 if (m_app_context) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 octave::install_signal_handlers (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
418 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 quit_allowed = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 initialize_file_io (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 install_types (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
424 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 install_ops (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
427 install_builtins (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23396
diff
changeset
|
429 install_classdef (m_evaluator); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
431 bool line_editing = false; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
432 bool traditional = false; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
434 if (m_app_context) |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
435 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
436 // Embedded interpeters don't execute command line options or |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
437 const cmdline_options& options = m_app_context->options (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
439 // Make all command-line arguments available to startup files, |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
440 // including PKG_ADD files. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
442 m_app_context->intern_argv (options.all_args ()); |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
443 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
444 bool is_octave_program = m_app_context->is_octave_program (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
445 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
446 std::list<std::string> command_line_path = options.command_line_path (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
448 for (const auto& pth : command_line_path) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
449 load_path::set_command_line_path (pth); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
451 std::string exec_path = options.exec_path (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
452 if (! exec_path.empty ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
453 set_exec_path (exec_path); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
454 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
455 std::string image_path = options.image_path (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
456 if (! image_path.empty ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
457 set_image_path (image_path); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
458 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
459 if (options.no_window_system ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
460 display_info::no_window_system (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
461 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
462 // Is input coming from a terminal? If so, we are probably |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
463 // interactive. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
464 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
465 // If stdin is not a tty, then we are reading commands from a |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
466 // pipe or a redirected file. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
467 bool stdin_is_tty = octave_isatty_wrapper (fileno (stdin)); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
469 m_interactive = (! is_octave_program && stdin_is_tty |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
470 && octave_isatty_wrapper (fileno (stdout))); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
471 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
472 // Check if the user forced an interactive session. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
473 if (options.forced_interactive ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
474 m_interactive = true; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
476 line_editing = options.line_editing (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
477 if ((! m_interactive || options.forced_interactive ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
478 && ! options.forced_line_editing ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
479 line_editing = false; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
481 traditional = options.traditional (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
482 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 // Force default line editor if we don't want readline editing. |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
485 if (line_editing) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
486 initialize_command_input (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
487 else |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 octave::command_editor::force_default_editor (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 // These can come after command line args since none of them set any |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 // defaults that might be changed by command line options. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 initialize_version_info (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
495 // This should be done before initializing the load path because |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
496 // some PKG_ADD files might need --traditional behavior. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
497 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
498 if (traditional) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
499 maximum_braindamage (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
500 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
501 octave_interpreter_ready = true; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
504 interpreter::~interpreter (void) |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
505 { |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
506 cleanup (); |
23105
3b58b08d764a
delay cleanup for embedded interpreter until destructor is called
John W. Eaton <jwe@octave.org>
parents:
23104
diff
changeset
|
507 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
508 current_evaluator = 0; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
509 |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
510 delete m_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
511 } |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
512 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
513 // Read the history file unless a command-line option inhibits that. |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
514 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
515 void interpreter::initialize_history (bool read_history_file) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 { |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
517 if (! m_history_initialized) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
518 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
519 // Allow command-line option to override. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
521 if (m_app_context) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
522 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
523 const cmdline_options& options = m_app_context->options (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
524 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
525 read_history_file = options.read_history_file (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
526 } |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
527 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
528 ::initialize_history (read_history_file); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
529 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
530 if (! m_app_context) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
531 octave::command_history::ignore_entries (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
532 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
533 m_history_initialized = true; |
23092
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
534 } |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
535 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
537 // Set the initial path to the system default unless command-line |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
538 // option says to leave it empty. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
540 void interpreter::initialize_load_path (bool set_initial_path) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
541 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
542 if (! m_load_path_initialized) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
544 // Allow command-line option to override. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
546 if (m_app_context) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
548 const cmdline_options& options = m_app_context->options (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
550 set_initial_path = options.set_initial_path (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
551 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
553 // Temporarily set the execute_pkg_add function to one that |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
554 // catches exceptions. This is better than wrapping |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
555 // load_path::initialize in a try-catch block because it will |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
556 // not stop executing PKG_ADD files at the first exception. |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
557 // It's also better than changing the default execute_pkg_add |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
558 // function to use safe_source file because that will normally |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
559 // be evaluated from the normal intepreter loop where exceptions |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
560 // are already handled. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
561 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
562 octave::unwind_protect frame; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
563 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
564 frame.add_fcn (load_path::set_add_hook, load_path::get_add_hook ()); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
565 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
566 load_path::set_add_hook (execute_pkg_add); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
567 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
568 load_path::initialize (set_initial_path); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
569 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
570 m_load_path_initialized = true; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
571 } |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
572 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
574 // This may be called separately from execute |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
575 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
576 int interpreter::initialize (void) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
577 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
578 if (m_initialized) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
579 return 0; |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
580 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
581 display_startup_message (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
583 // Wait to read the history file until the interpreter reads input |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
584 // files and begins evaluating commands. |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
585 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
586 initialize_history (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
587 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
588 // Initializing the load path may execute PKG_ADD files, so can't be |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
589 // done until the interpreter is ready to execute commands. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
590 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
591 // Deferring it to the execute step also allows the path to be |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
592 // initialized between creating and execute the interpreter, for |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
593 // example, to set a custom path for an embedded interpreter. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
595 initialize_load_path (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
596 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
597 // We ignore errors in startup files. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
598 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
599 execute_startup_files (); |
23092
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
600 |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
601 int exit_status = 0; |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
602 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
603 if (m_app_context) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
604 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
605 const cmdline_options& options = m_app_context->options (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
606 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
607 if (m_app_context->have_eval_option_code ()) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
608 { |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
609 int status = execute_eval_option_code (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
610 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
611 if (status ) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
612 exit_status = status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
613 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
614 if (! options.persist ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
615 return exit_status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
616 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
617 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
618 // If there is an extra argument, see if it names a file to |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
619 // read. Additional arguments are taken as command line options |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
620 // for the script. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
621 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
622 if (m_app_context->have_script_file ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
623 { |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
624 int status = execute_command_line_file (); |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
625 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
626 if (status) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
627 exit_status = status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
628 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
629 if (! options.persist ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
630 return exit_status; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
631 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
632 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
633 // Force input to be echoed if not really interactive, |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
634 // but the user has forced interactive behavior. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
635 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
636 if (options.forced_interactive ()) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
637 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
638 octave::command_editor::blink_matching_paren (false); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
640 // FIXME: is this the right thing to do? |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
641 Fecho_executing_commands (octave_value (ECHO_CMD_LINE)); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
642 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
643 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
644 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
645 // Avoid counting commands executed from startup or script files. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
647 octave::command_editor::reset_current_command_number (1); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
649 m_initialized = true; |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
650 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
651 return exit_status; |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
652 } |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
653 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
654 int interpreter::execute (void) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
655 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
656 try |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
657 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
658 int status = initialize (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
659 |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
660 if (! m_initialized) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
661 return status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
663 return main_loop (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
664 } |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
665 catch (const octave::exit_exception& ex) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
666 { |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
667 return ex.exit_status (); |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
668 } |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
669 } |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
670 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
671 void interpreter::display_startup_message (void) const |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
672 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
673 bool inhibit_startup_message = false; |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
674 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
675 if (m_app_context) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
677 const cmdline_options& options = m_app_context->options (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
678 |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
679 inhibit_startup_message = options.inhibit_startup_message (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
680 } |
23396
945b53af4655
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
681 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
682 if (m_interactive && ! inhibit_startup_message) |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
683 std::cout << octave_startup_message () << "\n" << std::endl; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
684 } |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
685 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
686 // Initialize by reading startup files. Return non-zero if an exception |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
687 // occurs when reading any of them, but don't exit early because of an |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
688 // exception. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
690 int interpreter::execute_startup_files (void) const |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
691 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
692 bool read_site_files = m_read_site_files; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
693 bool read_init_files = m_read_init_files; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
694 bool verbose = m_verbose; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
695 bool inhibit_startup_message = m_inhibit_startup_message; |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
696 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
697 if (m_app_context) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
698 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
699 const cmdline_options& options = m_app_context->options (); |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
700 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
701 read_site_files = options.read_site_files (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
702 read_init_files = options.read_init_files (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
703 verbose = options.verbose_flag (); |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
704 inhibit_startup_message = options.inhibit_startup_message (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
705 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
707 verbose = (verbose && ! inhibit_startup_message); |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
708 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
709 bool require_file = false; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
710 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
711 std::string context; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
712 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
713 int exit_status = 0; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
714 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
715 if (read_site_files) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
716 { |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
717 // Execute commands from the site-wide configuration file. |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
718 // First from the file $(prefix)/lib/octave/site/m/octaverc |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
719 // (if it exists), then from the file |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
720 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
721 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
722 int status = safe_source_file (Vlocal_site_defaults_file, context, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
723 verbose, require_file); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
724 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
725 if (status) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
726 exit_status = status; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
727 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
728 status = safe_source_file (Vsite_defaults_file, context, verbose, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
729 require_file); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
730 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
731 if (status) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
732 exit_status = status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
734 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
735 if (read_init_files) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
736 { |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
737 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
738 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
739 // .octaverc is assumed. |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
740 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
741 bool home_rc_already_executed = false; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
742 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
743 std::string initfile = octave::sys::env::getenv ("OCTAVE_INITFILE"); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
744 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
745 if (initfile.empty ()) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
746 initfile = ".octaverc"; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
747 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
748 std::string home_dir = octave::sys::env::get_home_directory (); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
749 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
750 std::string home_rc = octave::sys::env::make_absolute (initfile, home_dir); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
751 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
752 std::string local_rc; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
753 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
754 if (! home_rc.empty ()) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
755 { |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
756 int status = safe_source_file (home_rc, context, verbose, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
757 require_file); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
758 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
759 if (status) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
760 exit_status = status; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
761 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
762 // Names alone are not enough. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
763 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
764 octave::sys::file_stat fs_home_rc (home_rc); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
765 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
766 if (fs_home_rc) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
767 { |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
768 // We want to check for curr_dir after executing home_rc |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
769 // because doing that may change the working directory. |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
770 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
771 local_rc = octave::sys::env::make_absolute (initfile); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
772 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
773 home_rc_already_executed = same_file (home_rc, local_rc); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
774 } |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
775 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
776 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
777 if (! home_rc_already_executed) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
778 { |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
779 if (local_rc.empty ()) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
780 local_rc = octave::sys::env::make_absolute (initfile); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
781 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
782 int status = safe_source_file (local_rc, context, verbose, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
783 require_file); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
784 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
785 if (status) |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
786 exit_status = status; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
787 } |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
788 } |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
789 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
790 if (m_interactive && verbose) |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
791 std::cout << std::endl; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
792 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
793 return exit_status; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
794 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
795 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
796 // Execute any code specified with --eval 'CODE' |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
797 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
798 int interpreter::execute_eval_option_code (void) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
799 { |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
800 const cmdline_options& options = m_app_context->options (); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
801 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
802 std::string code_to_eval = options.code_to_eval (); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
803 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
804 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
805 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
806 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
807 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
808 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
809 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
810 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
811 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
812 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
813 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
814 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
815 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
816 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
817 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
818 frame.add_method (this, &interpreter::interactive, m_interactive); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
819 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
820 m_interactive = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
821 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
822 int parse_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
823 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
824 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
825 { |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
826 eval_string (code_to_eval, false, parse_status, 0); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
827 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
828 catch (const octave::interrupt_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
829 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
830 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
831 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
832 return 1; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
833 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
834 catch (const octave::execution_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
835 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
836 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
837 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
838 return 1; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
839 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
840 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
841 return parse_status; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
842 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
843 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
844 int interpreter::execute_command_line_file (void) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 { |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
846 const cmdline_options& options = m_app_context->options (); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
847 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
848 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
849 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
850 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
851 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
852 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
854 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
855 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
857 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
858 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
859 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
860 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
861 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
862 frame.add_method (this, &interpreter::interactive, m_interactive); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
863 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
864 frame.add_method (m_app_context, |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
865 &application::intern_argv, |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
866 options.all_args ()); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
867 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
868 frame.add_method (m_app_context, |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
869 &application::program_invocation_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
870 application::program_invocation_name ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
871 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
872 frame.add_method (m_app_context, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 &application::program_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
874 application::program_name ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
875 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
876 m_interactive = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
877 |
23102
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
878 // If we are running an executable script (#! /bin/octave) then |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
879 // we should only see the args passed to the script. |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
880 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
881 string_vector script_args = options.remaining_args (); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
882 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
883 m_app_context->intern_argv (script_args); |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
884 |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
885 std::string fname = script_args[0]; |
373771419d51
refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents:
23100
diff
changeset
|
886 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
887 m_app_context->set_program_names (fname); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
888 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
889 std::string context; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
890 bool verbose = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
891 bool require_file = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
892 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
893 return safe_source_file (fname, context, verbose, require_file, "octave"); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
894 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
895 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
896 int interpreter::main_loop (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
897 { |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
898 if (! m_app_context) |
23104
2805cc365a86
fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents:
23102
diff
changeset
|
899 return 0; |
2805cc365a86
fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents:
23102
diff
changeset
|
900 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
901 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
902 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
903 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
904 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
905 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
906 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
907 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
908 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
909 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
910 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
911 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
912 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 // The big loop. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
914 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
915 octave::lexer *lxr = (octave::application::interactive () |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
916 ? new octave::lexer () |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
917 : new octave::lexer (stdin)); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
918 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
919 octave::parser parser (*lxr); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
920 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
921 int retval = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
922 do |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
923 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
925 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
926 reset_error_handler (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
927 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
928 parser.reset (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
929 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
930 if (symbol_table::at_top_level ()) |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
931 octave::tree_evaluator::reset_debug_state (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
932 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
933 retval = parser.run (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
934 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
935 if (retval == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
937 if (parser.stmt_list) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
938 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 parser.stmt_list->accept (*current_evaluator); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
940 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
941 octave_quit (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
942 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
943 if (! octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
944 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
945 bool quit = (tree_return_command::returning |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
946 || tree_break_command::breaking); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
947 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
948 if (tree_return_command::returning) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
949 tree_return_command::returning = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
950 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
951 if (tree_break_command::breaking) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
952 tree_break_command::breaking--; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
953 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
954 if (quit) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
955 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
956 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
957 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
958 if (octave_completion_matches_called) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
959 octave_completion_matches_called = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
960 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
961 octave::command_editor::increment_current_command_number (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
962 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
963 else if (parser.lexer.end_of_input) |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
964 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
965 retval = EOF; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
966 break; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
967 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
968 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
969 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
970 catch (const octave::interrupt_exception&) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
971 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
972 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
973 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
974 // Required newline when the user does Ctrl+C at the prompt. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
975 if (octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
976 octave_stdout << "\n"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
977 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
978 catch (const octave::index_exception& e) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
979 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
980 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
981 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
982 std::cerr << "error: unhandled index exception: " |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
983 << e.message () << " -- trying to return to prompt" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
984 << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
985 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
986 catch (const octave::execution_exception& e) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
987 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
988 std::string stack_trace = e.info (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
989 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
990 if (! stack_trace.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
991 std::cerr << stack_trace; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
992 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
993 if (octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
994 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
995 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
996 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
997 // We should exit with a nonzero status. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
998 retval = 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
999 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1000 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1001 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1002 catch (const std::bad_alloc&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1003 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1004 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1005 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1006 std::cerr << "error: out of memory -- trying to return to prompt" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1007 << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1008 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1009 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1010 #if defined (DBSTOP_NANINF) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1011 if (Vdebug_on_naninf) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1012 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1013 if (setjump (naninf_jump) != 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1014 debug_or_throw_exception (true); // true = stack trace |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1015 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1016 #endif |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1017 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1018 while (retval == 0); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1019 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1020 if (retval == EOF) |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1021 { |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1022 if (octave::application::interactive ()) |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1023 octave_stdout << "\n"; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1024 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1025 retval = 0; |
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1026 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1027 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1028 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1029 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1030 |
23106
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1031 // Call a function with exceptions handled to avoid problems with |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1032 // errors while shutting down. |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1033 |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1034 #define OCTAVE_IGNORE_EXCEPTION(E) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1035 catch (E) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1036 { \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1037 recover_from_exception (); \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1038 \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1039 std::cerr << "error: ignoring " #E " while preparing to exit" \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1040 << std::endl; \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1041 } |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1042 |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1043 #define OCTAVE_SAFE_CALL(F, ARGS) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1044 do \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1045 { \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1046 try \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1047 { \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1048 octave::unwind_protect frame; \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1049 \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1050 frame.protect_var (Vdebug_on_error); \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1051 frame.protect_var (Vdebug_on_warning); \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1052 \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1053 Vdebug_on_error = false; \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1054 Vdebug_on_warning = false; \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1055 \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1056 F ARGS; \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1057 } \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1058 OCTAVE_IGNORE_EXCEPTION (const octave::exit_exception&) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1059 OCTAVE_IGNORE_EXCEPTION (const octave::interrupt_exception&) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1060 OCTAVE_IGNORE_EXCEPTION (const octave::execution_exception&) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1061 OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1062 } \ |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1063 while (0) |
1a53f9d42ec1
move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents:
23105
diff
changeset
|
1064 |
23087
9f406f0b36da
rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
1065 void interpreter::cleanup (void) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1066 { |
23092
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
1067 // If we are attached to a GUI, process pending events and |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
1068 // disconnect the link. |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
1069 |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
1070 octave_link::process_events (true); |
0fed4c678795
additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents:
23087
diff
changeset
|
1071 octave_link::disconnect_link (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1072 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1073 OCTAVE_SAFE_CALL (remove_input_event_hook_functions, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1074 |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1075 while (! atexit_functions.empty ()) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1076 { |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1077 std::string fcn = atexit_functions.front (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1078 |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1079 atexit_functions.pop_front (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1080 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1081 OCTAVE_SAFE_CALL (reset_error_handler, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1082 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23060
diff
changeset
|
1083 OCTAVE_SAFE_CALL (octave::feval, (fcn, octave_value_list (), 0)); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1084 |
23060
baf03cdb28b5
move pager and diary classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23057
diff
changeset
|
1085 OCTAVE_SAFE_CALL (octave::flush_stdout, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1086 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1087 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1088 // Do this explicitly so that destructors for mex file objects |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1089 // are called, so that functions registered with mexAtExit are |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1090 // called. |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1091 OCTAVE_SAFE_CALL (clear_mex_functions, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1092 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1093 OCTAVE_SAFE_CALL (octave::command_editor::restore_terminal_state, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1094 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1095 OCTAVE_SAFE_CALL (octave_history_write_timestamp, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1096 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1097 if (! octave::command_history::ignoring_entries ()) |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1098 OCTAVE_SAFE_CALL (octave::command_history::clean_up_and_save, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1099 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1100 OCTAVE_SAFE_CALL (gh_manager::close_all_figures, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1101 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1102 OCTAVE_SAFE_CALL (gtk_manager::unload_all_toolkits, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1103 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1104 OCTAVE_SAFE_CALL (close_files, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1105 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1106 OCTAVE_SAFE_CALL (cleanup_tmp_files, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1107 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1108 OCTAVE_SAFE_CALL (symbol_table::cleanup, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1109 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1110 OCTAVE_SAFE_CALL (sysdep_cleanup, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1111 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1112 OCTAVE_SAFE_CALL (octave_finalize_hdf5, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1113 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1114 OCTAVE_SAFE_CALL (octave::flush_stdout, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1115 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1116 // Don't call singleton_cleanup_list::cleanup until we have the |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1117 // problems with registering/unregistering types worked out. For |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1118 // example, uncomment the following line, then use the make_int |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1119 // function from the examples directory to create an integer |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1120 // object and then exit Octave. Octave should crash with a |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1121 // segfault when cleaning up the typinfo singleton. We need some |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1122 // way to force new octave_value_X types that are created in |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1123 // .oct files to be unregistered when the .oct file shared library |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1124 // is unloaded. |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1125 // |
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1126 // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1127 |
23117
17a3567a7b01
separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents:
23111
diff
changeset
|
1128 OCTAVE_SAFE_CALL (octave::chunk_buffer::clear, ()); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1129 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1130 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1131 void interpreter::recover_from_exception (void) |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1132 { |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1133 octave::can_interrupt = true; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1134 octave_interrupt_immediately = 0; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1135 octave_interrupt_state = 0; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1136 octave_signal_caught = 0; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1137 octave_exception_state = octave_no_exception; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1138 octave_restore_signal_mask (); |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1139 octave::catch_interrupts (); |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1140 } |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1141 |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1142 // Functions to call when the interpreter exits. |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1143 |
23111
252975fdc444
more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents:
23110
diff
changeset
|
1144 std::list<std::string> interpreter::atexit_functions; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1145 |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1146 void interpreter::add_atexit_function (const std::string& fname) |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1147 { |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1148 atexit_functions.push_front (fname); |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1149 } |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1150 |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1151 bool interpreter::remove_atexit_function (const std::string& fname) |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1152 { |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1153 bool found = false; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1154 |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1155 for (auto it = atexit_functions.begin (); |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1156 it != atexit_functions.end (); it++) |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1157 { |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1158 if (*it == fname) |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1159 { |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1160 atexit_functions.erase (it); |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1161 found = true; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1162 break; |
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1163 } |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1164 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1165 |
23110
af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23109
diff
changeset
|
1166 return found; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1167 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1168 } |