annotate libinterp/corefcn/interpreter.cc @ 26113:8a15f3bace49

move eval_string inside interpreter/evaluator class * tree_evaluator.h, tree_evaluator.cc (tree_evaluator::eval_string): New functions. * interpreter.h, interpreter.cc (interpreter::eval_string): New functions. Forward to evaluator eval_string functions. * parse.h, oct-parse.yy (eval_string): Deprecate and forward to interpreter eval_string functions. Change all uses. * pt.h, pt.cc (tree::meets_bp_condition): Accept reference to tree_evaluator as argument. Change all uses. (tree::is_breakpoint): Split into separate is_breakpoint and is_active_breakpoint functions. Change all uses.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Nov 2018 13:16:50 -0500
parents f881d3e271d2
children 00f796120a6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24833
diff changeset
3 Copyright (C) 1993-2018 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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
diff changeset
19 <https://www.gnu.org/licenses/>.
22094
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-stat.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #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
34 #include "lo-blas-proto.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "lo-error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "oct-env.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "str-vec.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "signal-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "unistd-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
41 #include "builtin-defun-decls.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "defaults.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "Cell.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
44 #include "call-stack.h"
22094
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"
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
50 #include "help.h"
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
51 #include "input.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
52 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 #include "interpreter.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 #include "load-path.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 #include "load-save.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 #include "octave-link.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 #include "octave.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 #include "oct-hist.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 #include "oct-map.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 #include "oct-mutex.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 #include "ovl.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 #include "ov.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 #include "ov-classdef.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 #include "parse.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 #include "pt-eval.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 #include "pt-jump.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 #include "pt-stmt.h"
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
68 #include "settings.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 #include "sighandlers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 #include "sysdep.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 #include "unwind-prot.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 #include "utils.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 #include "variables.h"
23466
5da300c55e89 use "" instead of <> for including defaults.h and version.h
John W. Eaton <jwe@octave.org>
parents: 23460
diff changeset
74 #include "version.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 // TRUE means the quit() call is allowed.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 bool quit_allowed = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 // 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
80 // is ready for interactive use.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 bool octave_interpreter_ready = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 // 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
84 bool octave_initialized = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 DEFUN (__version_info__, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 @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
89 Undocumented internal function.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 @end deftypefn */)
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 static octave_map vinfo;
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 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 if (nargin != 0 && nargin != 4)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 print_usage ();
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 octave_value retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 if (nargin == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 retval = vinfo;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 else if (nargin == 4)
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 if (vinfo.nfields () == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 vinfo.assign ("Name", args(0));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 vinfo.assign ("Version", args(1));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 vinfo.assign ("Release", args(2));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 vinfo.assign ("Date", args(3));
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 else
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 octave_idx_type n = vinfo.numel () + 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 vinfo.resize (dim_vector (n, 1));
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 octave_value idx (n);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 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
121 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
122 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
123 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
124 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 }
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 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 DEFUN (quit, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 @deftypefn {} {} exit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 @deftypefnx {} {} exit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 @deftypefnx {} {} quit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 @deftypefnx {} {} quit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 Exit the current Octave session.
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 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
139 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
140
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 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
142 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
143 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
144 to run using @code{atexit}.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 @seealso{atexit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 // 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
149 // 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
150 // 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
151 if (! octave_link::confirm_shutdown ())
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 if (! quit_allowed)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 error ("quit: not supported in embedded mode");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 int exit_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 if (args.length () > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 exit_status = args(0).nint_value ();
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 // 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
163 // 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
164 // 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
165 // etc. before exiting.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
167 throw octave::exit_exception (exit_status);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 return ovl ();
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 DEFALIAS (exit, quit);
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 DEFUN (atexit, args, nargout,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 @deftypefn {} {} atexit (@var{fcn})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 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
179
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 For example,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 @group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 function last_words ()
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 disp ("Bye bye");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 endfunction
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 atexit ("last_words");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 @end group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 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
193
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 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
195 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
196 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
197 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
198 above,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 atexit ("last_words", false);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 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
206 @code{last_words} when it exits.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 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
209 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
210 @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
211 @seealso{quit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 if (nargin < 1 || nargin > 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 print_usage ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 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
220
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 bool add_mode = (nargin == 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 ? 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
223 : true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 octave_value_list retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 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
228 octave::interpreter::add_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
231 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
232
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 if (nargout > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 retval = ovl (found);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 }
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 namespace octave
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 {
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
242 // Execute commands from a file and catch potential exceptions in a consistent
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
243 // way. This function should be called anywhere we might parse and execute
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
244 // commands from a file before we have entered the main loop in
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
245 // toplev.cc.
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
246
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
247 static int safe_source_file (const std::string& file_name,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
248 const std::string& context = "",
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
249 bool verbose = false,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
250 bool require_file = true,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
251 const std::string& warn_for = "")
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
252 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
253 try
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
254 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
255 source_file (file_name, context, verbose, require_file, warn_for);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
256 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
257 catch (const interrupt_exception&)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
258 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
259 interpreter::recover_from_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
260
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
261 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
262 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
263 catch (const execution_exception& e)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
264 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
265 std::string stack_trace = e.info ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
266
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
267 if (! stack_trace.empty ())
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
268 std::cerr << stack_trace;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
269
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
270 interpreter::recover_from_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
271
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
272 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
273 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
274
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
275 return 0;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
276 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
277
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
278 static void initialize_version_info (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
279 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
280 octave_value_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
281
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
282 args(3) = OCTAVE_RELEASE_DATE;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
283 args(2) = config::release ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
284 args(1) = OCTAVE_VERSION;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
285 args(0) = "GNU Octave";
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
286
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
287 F__version_info__ (args, 0);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
288 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
289
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
290 static void xerbla_abort (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
291 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
292 error ("Fortran procedure terminated by call to XERBLA");
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
293 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
294
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
295 static void initialize_xerbla_error_handler (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
296 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
297 // The idea here is to force xerbla to be referenced so that we will
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
298 // link to our own version instead of the one provided by the BLAS
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
299 // library. But numeric_limits<double>::NaN () should never be -1, so
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
300 // we should never actually call xerbla. FIXME (again!): If this
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
301 // becomes a constant expression the test might be optimized away and
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
302 // then the reference to the function might also disappear.
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
303
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
304 if (numeric_limits<double>::NaN () == -1)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
305 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
306
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
307 typedef void (*xerbla_handler_ptr) (void);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
308
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
309 typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
310
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
311 dynamic_library libs ("");
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
312
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
313 if (libs)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
314 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
315 octave_set_xerbla_handler_ptr octave_set_xerbla_handler
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
316 = reinterpret_cast<octave_set_xerbla_handler_ptr>
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
317 (libs.search ("octave_set_xerbla_handler"));
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
318
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
319 if (octave_set_xerbla_handler)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
320 octave_set_xerbla_handler (xerbla_abort);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
321 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
322 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
323
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
324 OCTAVE_NORETURN static void
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
325 lo_error_handler (const char *fmt, ...)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
326 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
327 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
328 va_start (args, fmt);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
329 verror_with_cfn (fmt, args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
330 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
331
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
332 octave_throw_execution_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
333 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
334
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
335 OCTAVE_NORETURN static void
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
336 lo_error_with_id_handler (const char *id, const char *fmt, ...)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
337 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
338 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
339 va_start (args, fmt);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
340 verror_with_id_cfn (id, fmt, args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
341 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
342
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
343 octave_throw_execution_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
344 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
345
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
346 static void initialize_error_handlers (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
347 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
348 set_liboctave_error_handler (lo_error_handler);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
349 set_liboctave_error_with_id_handler (lo_error_with_id_handler);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
350 set_liboctave_warning_handler (warning);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
351 set_liboctave_warning_with_id_handler (warning_with_id);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
352 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
353
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
354 // 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
355 // 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
356 // path.
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
357
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
358 interpreter::interpreter (application *app_context)
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
359 : m_app_context (app_context),
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
360 m_environment (),
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
361 m_settings (),
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
362 m_help_system (*this),
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
363 m_input_system (*this),
25435
a52e6fb674b1 eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents: 25407
diff changeset
364 m_output_system (*this),
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
365 m_history_system (*this),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
366 m_dynamic_loader (*this),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
367 m_load_path (),
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
368 m_load_save_system (*this),
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24538
diff changeset
369 m_type_info (),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
370 m_symbol_table (),
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
371 m_evaluator (*this),
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
372 m_stream_list (*this),
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24727
diff changeset
373 m_child_list (),
23742
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
374 m_url_handle_manager (),
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23630
diff changeset
375 m_cdef_manager (*this),
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
376 m_gtk_manager (),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
377 m_interactive (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
378 m_read_site_files (true),
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
379 m_read_init_files (m_app_context != nullptr),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
380 m_verbose (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
381 m_inhibit_startup_message (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
382 m_load_path_initialized (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
383 m_history_initialized (false),
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
384 m_initialized (false)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 {
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
386 // FIXME: When thread_local storage is used by default, this message
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
387 // should change to say something like
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
388 //
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
389 // only one Octave interpreter may be active in any given thread
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
390
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
391 if (instance)
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
392 throw std::runtime_error
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
393 ("only one Octave interpreter may be active");
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
394
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
395 instance = this;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 // 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
398 setlocale (LC_NUMERIC, "C");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399 setlocale (LC_TIME, "C");
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
400 sys::env::putenv ("LC_NUMERIC", "C");
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
401 sys::env::putenv ("LC_TIME", "C");
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 // 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
404 octave_set_default_fpucw ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
406 thread::init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 // Initialize default warning state before --traditional option
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 // that may reset them.
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 initialize_default_warning_state ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
413 octave_ieee_init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
415 initialize_xerbla_error_handler ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 initialize_error_handlers ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
419 if (m_app_context)
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
420 install_signal_handlers ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 quit_allowed = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
424 bool line_editing = false;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
425 bool traditional = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
427 if (m_app_context)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
428 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
429 // Embedded interpeters don't execute command line options.
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
430 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
431
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
432 // 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
433 // including PKG_ADD files.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
435 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
436
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
437 m_app_context->intern_argv (args);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
438 intern_nargin (args.numel () - 1);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
439
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
440 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
441
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
442 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
443
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
444 for (const auto& pth : command_line_path)
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
445 m_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
446
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
447 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
448 if (! exec_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
449 m_environment.exec_path (exec_path);
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 image_path = options.image_path ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
452 if (! image_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
453 m_environment.image_path (image_path);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
454
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
455 if (options.no_window_system ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
456 display_info::no_window_system ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
458 // 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
459 // interactive.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
460
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
461 // 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
462 // pipe or a redirected file.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
463 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
464
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
465 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
466 && octave_isatty_wrapper (fileno (stdout)));
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
467
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
468 // 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
469 if (options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
470 m_interactive = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
472 line_editing = options.line_editing ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
473 if ((! m_interactive || options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
474 && ! options.forced_line_editing ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
475 line_editing = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
477 traditional = options.traditional ();
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
478
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
479 // FIXME: if possible, perform the following actions directly
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
480 // instead of using the interpreter-level functions.
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
481
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
482 if (options.echo_commands ())
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
483 m_evaluator.echo
25063
a211e39e59d9 restore '--echo-commands' option to same behavior as 'echo on all' (bug #53453)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
484 (tree_evaluator::ECHO_SCRIPTS | tree_evaluator::ECHO_FUNCTIONS
a211e39e59d9 restore '--echo-commands' option to same behavior as 'echo on all' (bug #53453)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
485 | tree_evaluator::ECHO_ALL);
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
486
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
487 std::string docstrings_file = options.docstrings_file ();
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
488 if (! docstrings_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
489 Fbuilt_in_docstrings_file (*this, octave_value (docstrings_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
490
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
491 std::string doc_cache_file = options.doc_cache_file ();
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
492 if (! doc_cache_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
493 Fdoc_cache_file (*this, octave_value (doc_cache_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
494
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
495 std::string info_file = options.info_file ();
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
496 if (! info_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
497 Finfo_file (*this, octave_value (info_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
498
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
499 std::string info_program = options.info_program ();
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
500 if (! info_program.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
501 Finfo_program (*this, octave_value (info_program));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
502
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
503 if (options.debug_jit ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
504 Fdebug_jit (octave_value (true));
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
505
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
506 if (options.jit_compiler ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
507 Fjit_enable (octave_value (true));
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
508
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
509 std::string texi_macros_file = options.texi_macros_file ();
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
510 if (! texi_macros_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
511 Ftexi_macros_file (*this, octave_value (texi_macros_file));
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
512 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
513
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
514 m_input_system.initialize (line_editing);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 // 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
517 // 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
518
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519 initialize_version_info ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
521 // 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
522 // 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
523
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
524 if (traditional)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
525 maximum_braindamage ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
527 octave_interpreter_ready = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
530 OCTAVE_THREAD_LOCAL interpreter *interpreter::instance = nullptr;
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
531
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
532 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
533 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
534 cleanup ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
535 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
536
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
537 void interpreter::intern_nargin (octave_idx_type nargs)
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
538 {
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
539 // FIXME: should this explicitly be top_scope?
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
540 symbol_scope scope = m_symbol_table.current_scope ();
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
541
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
542 if (scope)
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
543 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
544 scope.assign (".nargin.", nargs);
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
545 scope.mark_hidden (".nargin.");
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
546 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
547 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
548
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
549 // 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
550
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
551 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
552 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
553 if (! m_history_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
554 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
555 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
556
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
557 if (m_app_context)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
558 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
559 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
560
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
561 read_history_file = options.read_history_file ();
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
562
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
563 if (! read_history_file)
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
564 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
565 }
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
566
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
567 m_history_system.initialize (read_history_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
569 if (! m_app_context)
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
570 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
571
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
572 m_history_initialized = true;
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
573 }
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
574 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
576 // 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
577 // option says to leave it empty.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
579 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
580 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
581 if (! m_load_path_initialized)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
582 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
583 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
585 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
586 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
587 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
588
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
589 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
590 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
591
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
592 // 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
593 // 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
594 // 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
595 // 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
596 // 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
597 // 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
598 // 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
599 // are already handled.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
600
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
601 unwind_protect frame;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
602
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
603 frame.add_method (m_load_path, &load_path::set_add_hook,
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
604 m_load_path.get_add_hook ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
605
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
606 m_load_path.set_add_hook ([this] (const std::string& dir)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
607 { this->execute_pkg_add (dir); });
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
609 m_load_path.initialize (set_initial_path);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
610
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
611 m_load_path_initialized = true;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
612 }
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
613 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
614
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
615 // 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
616
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
617 void interpreter::initialize (void)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
618 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
619 if (m_initialized)
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
620 return;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
621
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
622 display_startup_message ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
623
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
624 // 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
625 // files and begins evaluating commands.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
626
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
627 initialize_history ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
628
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
629 // 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
630 // 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
631
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
632 // 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
633 // 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
634 // 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
635
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
636 initialize_load_path ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
637
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
638 m_initialized = true;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
639 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
640
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
641 // FIXME: this function is intended to be executed only once. Should
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
642 // we enforce that restriction?
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
643
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
644 int interpreter::execute (void)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
645 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
646 try
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
647 {
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
648 initialize ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
649
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
650 // We ignore errors in startup files.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
651
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
652 execute_startup_files ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
653
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
654 int exit_status = 0;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
655
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
656 if (m_app_context)
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
657 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
658 const cmdline_options& options = m_app_context->options ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
659
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
660 if (m_app_context->have_eval_option_code ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
661 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
662 int status = execute_eval_option_code ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
663
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
664 if (status )
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
665 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
666
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
667 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
668 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
669 }
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
670
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
671 // If there is an extra argument, see if it names a file to
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
672 // read. Additional arguments are taken as command line options
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
673 // for the script.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
674
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
675 if (m_app_context->have_script_file ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
676 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
677 int status = execute_command_line_file ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
678
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
679 if (status)
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
680 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
681
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
682 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
683 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
684 }
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
685
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
686 if (options.forced_interactive ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
687 command_editor::blink_matching_paren (false);
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
688 }
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
689
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
690 // Avoid counting commands executed from startup or script files.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
691
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
692 command_editor::reset_current_command_number (1);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
693
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
694 return main_loop ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
695 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
696 catch (const exit_exception& ex)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
697 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
698 return ex.exit_status ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
699 }
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
700 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
701
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
702 void interpreter::display_startup_message (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
703 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
704 bool inhibit_startup_message = false;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
705
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
706 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
707 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
708 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
709
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
710 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
711 }
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
712
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
713 if (m_interactive && ! inhibit_startup_message)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
714 std::cout << octave_startup_message () << "\n" << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
715 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
716
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
717 // 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
718 // 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
719 // exception.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
721 int interpreter::execute_startup_files (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
722 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
723 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
724 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
725 bool verbose = m_verbose;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
726 bool inhibit_startup_message = m_inhibit_startup_message;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
727
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
728 if (m_app_context)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
729 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
730 const cmdline_options& options = m_app_context->options ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
731
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
732 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
733 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
734 verbose = options.verbose_flag ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
735 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
736 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
738 verbose = (verbose && ! inhibit_startup_message);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
739
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
740 bool require_file = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
741
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
742 std::string context;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
743
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
744 int exit_status = 0;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
745
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
746 if (read_site_files)
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 // Execute commands from the site-wide configuration file.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
749 // First from the file $(prefix)/lib/octave/site/m/octaverc
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
750 // (if it exists), then from the file
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
751 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
752
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
753 int status = safe_source_file (config::local_site_defaults_file (),
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
754 context, verbose, require_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
755
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
756 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
757 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
758
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
759 status = safe_source_file (config::site_defaults_file (),
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
760 context, verbose, require_file);
23102
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 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
763 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
766 if (read_init_files)
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 // Try to execute commands from $HOME/$OCTAVE_INITFILE and
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
769 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
770 // .octaverc is assumed.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
771
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
772 bool home_rc_already_executed = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
773
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
774 std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
775
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
776 if (initfile.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
777 initfile = ".octaverc";
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
778
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
779 std::string home_dir = sys::env::get_home_directory ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
780
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
781 std::string home_rc = sys::env::make_absolute (initfile, home_dir);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
782
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
783 std::string local_rc;
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 (! home_rc.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
786 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
787 int status = safe_source_file (home_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
788 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
789
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
790 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
791 exit_status = status;
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 // Names alone are not enough.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
794
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
795 sys::file_stat fs_home_rc (home_rc);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
796
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
797 if (fs_home_rc)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
798 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
799 // 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
800 // because doing that may change the working directory.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
801
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
802 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
803
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
804 home_rc_already_executed = same_file (home_rc, local_rc);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
805 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
806 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
807
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
808 if (! home_rc_already_executed)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
809 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
810 if (local_rc.empty ())
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
811 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
812
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
813 int status = safe_source_file (local_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
814 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
815
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
816 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
817 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
818 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
819 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
820
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
821 if (m_interactive && verbose)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
822 std::cout << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
823
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
824 return exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
825 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
826
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
827 // Execute any code specified with --eval 'CODE'
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
828
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
829 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
830 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
831 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
832
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
833 std::string code_to_eval = options.code_to_eval ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
834
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
835 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
836
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
837 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
838
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
839 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
840
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
841 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
842 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
843 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
844
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
845 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
846
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
847 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
848
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
849 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
850
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
851 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
853 int parse_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
854
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
855 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
856 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
857 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
858 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
859 catch (const interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
860 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
862
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
863 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
864 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
865 catch (const execution_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
866 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
867 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
868
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
869 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
870 }
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 return parse_status;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
873 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
875 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
876 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
877 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
878
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
879 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
883 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
884
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
885 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
886 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
887 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
888
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
889 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
890
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
891 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
893 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
894
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
895 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
896
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
897 frame.add_method (m_app_context, &application::intern_argv, args);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
898
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
899 frame.add_method (this, &interpreter::intern_nargin, args.numel () - 1);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
900
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
901 frame.add_method (m_app_context,
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902 &application::program_invocation_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903 application::program_invocation_name ());
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 frame.add_method (m_app_context,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906 &application::program_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
907 application::program_name ());
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 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
911 // If we are running an executable script (#! /bin/octave) then
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
912 // we should only see the args passed to the script.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
913
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
914 string_vector script_args = options.remaining_args ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
915
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
916 m_app_context->intern_argv (script_args);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
917 intern_nargin (script_args.numel () - 1);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
918
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
919 std::string fname = script_args[0];
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
920
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
921 m_app_context->set_program_names (fname);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
922
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
923 std::string context;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
924 bool verbose = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
925 bool require_file = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
926
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
927 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
928 }
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 int interpreter::main_loop (void)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
931 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
932 if (! m_app_context)
23104
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
933 return 0;
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
934
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
935 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
936
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
937 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
938
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
939 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
940 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
941 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
943 catch_interrupts ();
22094
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 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
946
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947 // The big loop.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
948
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
949 return m_evaluator.repl (application::interactive ());
22094
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
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
952 // 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
953 // errors while shutting down.
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
954
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
955 #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
956 catch (E) \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
957 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
958 recover_from_exception (); \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
959 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
960 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
961 << std::endl; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
962 }
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
963
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
964 #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
965 do \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
966 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
967 try \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
968 { \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
969 unwind_protect frame; \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
970 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
971 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
972 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
973 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
974 Vdebug_on_error = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
975 Vdebug_on_warning = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
976 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
977 F ARGS; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
978 } \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
979 OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
980 OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
981 OCTAVE_IGNORE_EXCEPTION (const execution_exception&) \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
982 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
983 } \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
984 while (0)
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
985
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
986 void interpreter::cleanup (void)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
987 {
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
988 // 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
989 // disconnect the link.
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
990
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
991 octave_link::process_events (true);
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
992 octave_link::disconnect_link ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
993
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
994 OCTAVE_SAFE_CALL (m_input_system.clear_input_event_hooks, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
996 while (! atexit_functions.empty ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
998 std::string fcn = atexit_functions.front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
999
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1000 atexit_functions.pop_front ();
22094
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 OCTAVE_SAFE_CALL (reset_error_handler, ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1003
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1004 OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0));
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1006 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1007 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1008
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1009 // 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
1010 // 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
1011 // called.
23699
b29904962d2d deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
1012 OCTAVE_SAFE_CALL (m_symbol_table.clear_mex_functions, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1013
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1014 OCTAVE_SAFE_CALL (command_editor::restore_terminal_state, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1015
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1016 OCTAVE_SAFE_CALL (m_history_system.write_timestamp, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1018 if (! command_history::ignoring_entries ())
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1019 OCTAVE_SAFE_CALL (command_history::clean_up_and_save, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1020
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1021 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
1022
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
1023 m_gtk_manager.unload_all_toolkits ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1024
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1025 OCTAVE_SAFE_CALL (cleanup_tmp_files, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1026
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1027 // FIXME: May still need something like this to ensure that
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1028 // destructors for class objects will run properly. Should that be
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1029 // done earlier? Before or after atexit functions are executed?
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1030 m_symbol_table.cleanup ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1031
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1032 OCTAVE_SAFE_CALL (sysdep_cleanup, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1033
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1034 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1036 // 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
1037 // 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
1038 // 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
1039 // 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
1040 // 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
1041 // 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
1042 // 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
1043 // .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
1044 // is unloaded.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1045 //
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1046 // 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
1047 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1048
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1049 tree_evaluator& interpreter::get_evaluator (void)
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1050 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1051 return m_evaluator;
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1052 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1053
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1054 stream_list& interpreter::get_stream_list (void)
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1055 {
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1056 return m_stream_list;
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1057 }
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1058
23742
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1059 url_handle_manager& interpreter::get_url_handle_manager (void)
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1060 {
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1061 return m_url_handle_manager;
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1062 }
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1063
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1064 symbol_scope
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1065 interpreter::get_current_scope (void)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1066 {
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1067 return m_symbol_table.current_scope ();
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1068 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1069
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1070 symbol_scope
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1071 interpreter::require_current_scope (const std::string& who)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1072 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1073 symbol_scope scope = get_current_scope ();
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1074
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1075 if (! scope)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1076 error ("%s: symbol table scope missing", who.c_str ());
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1077
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1078 return scope;
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1079 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1080
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1081 call_stack& interpreter::get_call_stack (void)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1082 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1083 return m_evaluator.get_call_stack ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1084 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1085
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1086 profiler& interpreter::get_profiler (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1087 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1088 return m_evaluator.get_profiler ();
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1089 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1090
23703
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1091 void interpreter::mlock (void)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1092 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1093 call_stack& cs = get_call_stack ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1094
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1095 octave_function *fcn = cs.current ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1096
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1097 if (! fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1098 error ("mlock: invalid use outside a function");
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1099
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1100 fcn->lock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1101 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1102
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1103 void interpreter::munlock (const std::string& nm)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1104 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1105 octave_value val = m_symbol_table.find_function (nm);
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1106
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1107 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1108 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1109 octave_function *fcn = val.function_value ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1110
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1111 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1112 fcn->unlock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1113 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1114 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1115
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1116 bool interpreter::mislocked (const std::string& nm)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1117 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1118 bool retval = false;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1119
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1120 octave_value val = m_symbol_table.find_function (nm);
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1121
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1122 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1123 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1124 octave_function *fcn = val.function_value ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1125
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1126 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1127 retval = fcn->islocked ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1128 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1129
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1130 return retval;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1131 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1132
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1133 octave_value_list interpreter::eval_string (const std::string& eval_str,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1134 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1135 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1136 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1137 return m_evaluator.eval_string (eval_str, silent, parse_status, nargout);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1138 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1139
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1140 octave_value interpreter::eval_string (const std::string& eval_str,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1141 bool silent, int& parse_status)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1142 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1143 return m_evaluator.eval_string (eval_str, silent, parse_status);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1144 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1145
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1146 octave_value_list interpreter::eval_string (const octave_value& arg,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1147 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1148 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1149 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1150 return m_evaluator.eval_string (arg, silent, parse_status, nargout);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1151 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1152
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1153 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
1154 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1155 can_interrupt = true;
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1156 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
1157 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
1158 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
1159 octave_restore_signal_mask ();
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1160 catch_interrupts ();
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1161 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1162
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1163 // Functions to call when the interpreter exits.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1164
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1165 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
1166
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1167 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
1168 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1169 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
1170 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1171
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1172 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
1173 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1174 bool found = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1176 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
1177 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
1178 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1179 if (*it == fname)
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1180 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1181 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
1182 found = true;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1183 break;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1184 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1185 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1186
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1187 return found;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1188 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1189
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1190 // What internal options get configured by --traditional.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1191
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1192 void interpreter::maximum_braindamage (void)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1193 {
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1194 m_input_system.PS1 (">> ");
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1195 m_input_system.PS2 ("");
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1196
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1197 m_evaluator.PS4 ("");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1198
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1199 m_load_save_system.crash_dumps_octave_core (false);
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1200 m_load_save_system.save_default_options ("-mat-binary");
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1201
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1202 m_history_system.timestamp_format_string ("%%-- %D %I:%M %p --%%");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1203
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1204 Fbeep_on_error (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1205 Fconfirm_recursive_rmdir (octave_value (false));
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1206
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1207 Fdisable_diagonal_matrix (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1208 Fdisable_permutation_matrix (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1209 Fdisable_range (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1210 Ffixed_point_format (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1211 Fprint_empty_dimensions (octave_value (false));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1212 Fstruct_levels_to_print (octave_value (0));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1213
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1214 disable_warning ("Octave:abbreviated-property-match");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1215 disable_warning ("Octave:data-file-in-path");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1216 disable_warning ("Octave:function-name-clash");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1217 disable_warning ("Octave:possible-matlab-short-circuit-operator");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1218 }
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1219
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1220 void interpreter::execute_pkg_add (const std::string& dir)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1221 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1222 try
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1223 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1224 m_load_path.execute_pkg_add (dir);
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1225 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1226 catch (const octave::interrupt_exception&)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1227 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1228 octave::interpreter::recover_from_exception ();
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1229 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1230 catch (const octave::execution_exception&)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1231 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1232 octave::interpreter::recover_from_exception ();
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1233 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1234 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1235 }