annotate libinterp/corefcn/interpreter.cc @ 23717:06579337237b

move configuration variables inside octave::config namespace * defaults.h, defaults.in.cc: Define access functions for configuration variables inside octave::config namespace and make variables static inside defaults.cc, effectively making these values read-only for users. Change all uses. A few variables that may be modified by users remain in the global namespace. These may be moved later.
author John W. Eaton <jwe@octave.org>
date Thu, 29 Jun 2017 02:33:19 -0400
parents b95c430c0649
children 69a111259a2c
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
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1993-2017 John W. Eaton
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
10 (at your option) any later version.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
15 GNU General Public License for more details.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 # include "config.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <string>
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include <iostream>
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "cmd-edit.h"
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
31 #include "cmd-hist.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "file-ops.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "file-stat.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "fpucw-wrappers.h"
22322
93b3cdd36854 move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents: 22196
diff changeset
35 #include "lo-blas-proto.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "lo-error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "oct-env.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "str-vec.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "signal-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "unistd-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
42 #include "builtin-defun-decls.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "builtins.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "defaults.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "Cell.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
46 #include "call-stack.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "defun.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "display.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "file-io.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "graphics.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 "ops.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 #include "ovl.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 #include "ov.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 #include "ov-classdef.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 #include "parse.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 #include "pt-eval.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 #include "pt-jump.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23117
diff changeset
68 #include "pt-mat.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 #include "pt-stmt.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 #include "sighandlers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 #include "sysdep.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 #include "unwind-prot.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 #include "utils.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 #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
75 #include "version.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 // TRUE means the quit() call is allowed.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 bool quit_allowed = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 // 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
81 // is ready for interactive use.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 bool octave_interpreter_ready = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 // 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
85 bool octave_initialized = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 DEFUN (__version_info__, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 @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
90 Undocumented internal function.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 static octave_map vinfo;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 if (nargin != 0 && nargin != 4)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 print_usage ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 octave_value retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 if (nargin == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 retval = vinfo;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 else if (nargin == 4)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 if (vinfo.nfields () == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 vinfo.assign ("Name", args(0));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 vinfo.assign ("Version", args(1));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 vinfo.assign ("Release", args(2));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 vinfo.assign ("Date", args(3));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 octave_idx_type n = vinfo.numel () + 1;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 vinfo.resize (dim_vector (n, 1));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 octave_value idx (n);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 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
122 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
123 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
124 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
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 return retval;
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 initialize_version_info (void)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 octave_value_list args;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 args(3) = OCTAVE_RELEASE_DATE;
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
137 args(2) = octave::config::release ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 args(1) = OCTAVE_VERSION;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 args(0) = "GNU Octave";
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 F__version_info__ (args, 0);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 OCTAVE_NORETURN static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 lo_error_handler (const char *fmt, ...)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 va_list args;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 va_start (args, fmt);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 verror_with_cfn (fmt, args);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 va_end (args);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 octave_throw_execution_exception ();
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 OCTAVE_NORETURN static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 lo_error_with_id_handler (const char *id, const char *fmt, ...)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 va_list args;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 va_start (args, fmt);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 verror_with_id_cfn (id, fmt, args);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 va_end (args);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 octave_throw_execution_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 initialize_error_handlers ()
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 set_liboctave_error_handler (lo_error_handler);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 set_liboctave_error_with_id_handler (lo_error_with_id_handler);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 set_liboctave_warning_handler (warning);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 set_liboctave_warning_with_id_handler (warning_with_id);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 // What internal options get configured by --traditional.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 maximum_braindamage (void)
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 FPS1 (octave_value (">> "));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 FPS2 (octave_value (""));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 FPS4 (octave_value (""));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 Fbeep_on_error (octave_value (true));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 Fconfirm_recursive_rmdir (octave_value (false));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 Fcrash_dumps_octave_core (octave_value (false));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 Fdisable_diagonal_matrix (octave_value (true));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 Fdisable_permutation_matrix (octave_value (true));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 Fdisable_range (octave_value (true));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 Ffixed_point_format (octave_value (true));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%"));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 Fpage_screen_output (octave_value (false));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 Fprint_empty_dimensions (octave_value (false));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 Fsave_default_options (octave_value ("-mat-binary"));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 Fstruct_levels_to_print (octave_value (0));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 disable_warning ("Octave:abbreviated-property-match");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 disable_warning ("Octave:data-file-in-path");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 disable_warning ("Octave:function-name-clash");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 disable_warning ("Octave:possible-matlab-short-circuit-operator");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 DEFUN (quit, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 @deftypefn {} {} exit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 @deftypefnx {} {} exit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 @deftypefnx {} {} quit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 @deftypefnx {} {} quit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 Exit the current Octave session.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 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
211 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
212
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 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
214 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
215 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
216 to run using @code{atexit}.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 @seealso{atexit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 // 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
221 // 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
222 // 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
223 if (! octave_link::confirm_shutdown ())
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 if (! quit_allowed)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 error ("quit: not supported in embedded mode");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 int exit_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 if (args.length () > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 exit_status = args(0).nint_value ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 // 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
235 // 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
236 // 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
237 // etc. before exiting.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
239 throw octave::exit_exception (exit_status);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 DEFALIAS (exit, quit);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 DEFUN (atexit, args, nargout,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 @deftypefn {} {} atexit (@var{fcn})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 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
251
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 For example,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 @group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 function last_words ()
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 disp ("Bye bye");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 endfunction
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 atexit ("last_words");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 @end group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 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
265
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266 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
267 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
268 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
269 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
270 above,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 atexit ("last_words", false);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277 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
278 @code{last_words} when it exits.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 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
281 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
282 @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
283 @seealso{quit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 if (nargin < 1 || nargin > 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 print_usage ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 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
292
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 bool add_mode = (nargin == 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 ? 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
295 : true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 octave_value_list retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 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
300 octave::interpreter::add_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
303 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
304
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 if (nargout > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 retval = ovl (found);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 // Execute commands from a file and catch potential exceptions in a consistent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 // way. This function should be called anywhere we might parse and execute
22173
8de49f15e182 doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 22133
diff changeset
314 // commands from a file before we have entered the main loop in
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 // toplev.cc.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
317 static int
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 safe_source_file (const std::string& file_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 const std::string& context = "",
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 bool verbose = false, bool require_file = true,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 const std::string& warn_for = "")
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23060
diff changeset
325 octave::source_file (file_name, context, verbose, require_file, warn_for);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
327 catch (const octave::interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
329 octave::interpreter::recover_from_exception ();
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
330
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
331 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 }
23537
94968aa621a8 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23533
diff changeset
333 catch (const octave::execution_exception& e)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 {
23537
94968aa621a8 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23533
diff changeset
335 std::string stack_trace = e.info ();
23536
14b61de53028 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
336
14b61de53028 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
337 if (! stack_trace.empty ())
14b61de53028 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
338 std::cerr << stack_trace;
14b61de53028 show stack trace for errors in command line and startup files (bug #49346)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
339
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
340 octave::interpreter::recover_from_exception ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
342 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 }
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
344
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
345 return 0;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348 static void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349 execute_pkg_add (const std::string& dir)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351 std::string file_name = octave::sys::file_ops::concat (dir, "PKG_ADD");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
353 octave::load_path& lp = octave::__get_load_path__ ("execute_pkg_add");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
354
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356 {
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
357 lp.execute_pkg_add (dir);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
359 catch (const octave::interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
361 octave::interpreter::recover_from_exception ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
363 catch (const octave::execution_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
365 octave::interpreter::recover_from_exception ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369 namespace octave
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
371 // 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
372 // 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
373 // path.
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
374
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
375 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
376 : m_app_context (app_context),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
377 m_dynamic_loader (*this),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
378 m_load_path (),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
379 m_symbol_table (),
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
380 m_evaluator (*this),
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23630
diff changeset
381 m_cdef_manager (*this),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
382 m_interactive (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
383 m_read_site_files (true),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
384 m_read_init_files (m_app_context != 0),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
385 m_verbose (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
386 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
387 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
388 m_history_initialized (false),
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
389 m_initialized (false)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
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
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
393 ("only one Octave interpreter object 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 set_default_prompts ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 // Initialize default warning state before --traditional option
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 // that may reset them.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413 initialize_default_warning_state ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
415 octave_ieee_init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
417 octave_prepare_hdf5 ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 // The idea here is to force xerbla to be referenced so that we will link to
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 // our own version instead of the one provided by the BLAS library. But
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
421 // numeric_limits<double>::NaN () should never be -1, so we
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 // should never actually call xerbla. FIXME (again!): If this
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 // becomes a constant expression the test might be optimized away and
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 // then the reference to the function might also disappear.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
426 if (numeric_limits<double>::NaN () == -1)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429 initialize_error_handlers ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
431 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
432 install_signal_handlers ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 quit_allowed = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 initialize_file_io ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 install_types ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440 install_ops ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 install_builtins ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23630
diff changeset
444 m_cdef_manager.initialize ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
446 bool line_editing = false;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
447 bool traditional = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
449 if (m_app_context)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
450 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
451 // 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
452 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
453
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
454 // 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
455 // including PKG_ADD files.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
457 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
458
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
459 m_app_context->intern_argv (args);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
460 intern_nargin (args.numel () - 1);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
461
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
462 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
463
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
464 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
465
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
466 for (const auto& pth : command_line_path)
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
467 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
468
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
469 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
470 if (! exec_path.empty ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
471 set_exec_path (exec_path);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
472
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
473 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
474 if (! image_path.empty ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
475 set_image_path (image_path);
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
476
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
477 if (options.no_window_system ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
478 display_info::no_window_system ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
480 // 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
481 // interactive.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
482
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
483 // 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
484 // pipe or a redirected file.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
485 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
486
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
487 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
488 && octave_isatty_wrapper (fileno (stdout)));
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
489
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
490 // 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
491 if (options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
492 m_interactive = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
494 line_editing = options.line_editing ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
495 if ((! m_interactive || options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
496 && ! options.forced_line_editing ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
497 line_editing = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
498
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
499 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
500
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
501 // 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
502 // 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
503
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
504 if (options.echo_commands ())
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 int val = ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE;
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
507 Fecho_executing_commands (octave_value (val));
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
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
510 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
511 if (! docstrings_file.empty ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
512 Fbuilt_in_docstrings_file (octave_value (docstrings_file));
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
513
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
514 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
515 if (! doc_cache_file.empty ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
516 Fdoc_cache_file (octave_value (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
517
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
518 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
519 if (! info_file.empty ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
520 Finfo_file (octave_value (info_file));
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
521
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
522 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
523 if (! info_program.empty ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
524 Finfo_program (octave_value (info_program));
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
525
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
526 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
527 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
528
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
529 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
530 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
531
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
532 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
533 if (! texi_macros_file.empty ())
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
534 Ftexi_macros_file (octave_value (texi_macros_file));
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
535 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
537 // Force default line editor if we don't want readline editing.
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
538 if (line_editing)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
539 initialize_command_input ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
540 else
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
541 command_editor::force_default_editor ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543 // 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
544 // 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
545
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 initialize_version_info ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
548 // 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
549 // 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
550
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
551 if (traditional)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
552 maximum_braindamage ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
554 octave_interpreter_ready = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
556
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
557 interpreter *interpreter::instance = nullptr;
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
558
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
559 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
560 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
561 cleanup ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
562 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
563
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
564 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
565 {
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
566 // FIXME: should this explicitly be top_scope?
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
567 symbol_table::scope *scope = m_symbol_table.current_scope ();
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
568
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
569 if (scope)
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
570 {
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
571 scope->assign (".nargin.", nargs);
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
572 scope->mark_hidden (".nargin.");
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23609
diff changeset
573 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
574 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
575
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
576 // 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
577
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
578 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
579 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
580 if (! m_history_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
581 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
582 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
584 if (m_app_context)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
585 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
586 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
587
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
588 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
589
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
590 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
591 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
592 }
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
593
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
594 ::initialize_history (read_history_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
595
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
596 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
597 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
598
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
599 m_history_initialized = true;
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
600 }
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
601 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
603 // 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
604 // option says to leave it empty.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
605
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
606 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
607 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
608 if (! m_load_path_initialized)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
610 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
611
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
612 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
614 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
615
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
616 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
617 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
618
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
619 // 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
620 // 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
621 // 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
622 // 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
623 // 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
624 // 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
625 // 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
626 // are already handled.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
627
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
628 unwind_protect frame;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
629
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
630 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
631 m_load_path.get_add_hook ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
632
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
633 m_load_path.set_add_hook (execute_pkg_add);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
634
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
635 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
636
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
637 m_load_path_initialized = true;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
638 }
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
639 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
640
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
641 // 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
642
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
643 int interpreter::initialize (void)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
644 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
645 if (m_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
646 return 0;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
647
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
648 display_startup_message ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
650 // 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
651 // files and begins evaluating commands.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
652
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
653 initialize_history ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
654
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
655 // 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
656 // 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
657
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
658 // 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
659 // 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
660 // 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
661
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
662 initialize_load_path ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
663
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
664 // We ignore errors in startup files.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
666 execute_startup_files ();
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
667
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
668 int exit_status = 0;
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
669
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
670 if (m_app_context)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
671 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
672 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
673
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
674 if (m_app_context->have_eval_option_code ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
675 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
676 int status = execute_eval_option_code ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
677
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
678 if (status )
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
679 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
680
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
681 if (! options.persist ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
682 return exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
683 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
684
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
685 // If there is an extra argument, see if it names a file to
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
686 // read. Additional arguments are taken as command line options
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
687 // for the script.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
688
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
689 if (m_app_context->have_script_file ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
690 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
691 int status = execute_command_line_file ();
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
692
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
693 if (status)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
694 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
695
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
696 if (! options.persist ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
697 return exit_status;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
698 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
700 // Force input to be echoed if not really interactive,
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
701 // but the user has forced interactive behavior.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
702
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
703 if (options.forced_interactive ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
704 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
705 command_editor::blink_matching_paren (false);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
706
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
707 // FIXME: is this the right thing to do?
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
708 Fecho_executing_commands (octave_value (ECHO_CMD_LINE));
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
709 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
710 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
711
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
712 // Avoid counting commands executed from startup or script files.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
713
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
714 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
715
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
716 m_initialized = true;
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
717
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
718 return exit_status;
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
719 }
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
720
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
721 int interpreter::execute (void)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
722 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
723 try
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
724 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
725 int status = initialize ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
726
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
727 if (! m_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
728 return status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
729
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
730 return main_loop ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
731 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
732 catch (const exit_exception& ex)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
733 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
734 return ex.exit_status ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
735 }
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
736 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
737
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
738 void interpreter::display_startup_message (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
739 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
740 bool inhibit_startup_message = false;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
741
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
742 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
743 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
744 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
745
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
746 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
747 }
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
748
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
749 if (m_interactive && ! inhibit_startup_message)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
750 std::cout << octave_startup_message () << "\n" << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
751 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
752
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
753 // 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
754 // 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
755 // exception.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
756
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
757 int interpreter::execute_startup_files (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
758 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
759 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
760 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
761 bool verbose = m_verbose;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
762 bool inhibit_startup_message = m_inhibit_startup_message;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
763
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
764 if (m_app_context)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
765 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
766 const cmdline_options& options = m_app_context->options ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
767
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
768 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
769 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
770 verbose = options.verbose_flag ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
771 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
772 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
773
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
774 verbose = (verbose && ! inhibit_startup_message);
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 bool require_file = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
777
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
778 std::string context;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
779
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
780 int exit_status = 0;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
781
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
782 if (read_site_files)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
783 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
784 // Execute commands from the site-wide configuration file.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
785 // First from the file $(prefix)/lib/octave/site/m/octaverc
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
786 // (if it exists), then from the file
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
787 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
788
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
789 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
790 context, verbose, require_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
791
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
792 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
793 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
794
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
795 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
796 context, verbose, require_file);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
797
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
798 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
799 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
800 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
801
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
802 if (read_init_files)
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 // Try to execute commands from $HOME/$OCTAVE_INITFILE and
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
805 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
806 // .octaverc is assumed.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
807
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
808 bool home_rc_already_executed = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
809
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
810 std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
811
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
812 if (initfile.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
813 initfile = ".octaverc";
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
814
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
815 std::string home_dir = sys::env::get_home_directory ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
816
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
817 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
818
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
819 std::string local_rc;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
820
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
821 if (! home_rc.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
822 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
823 int status = safe_source_file (home_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
824 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
825
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
826 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
827 exit_status = status;
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 // Names alone are not enough.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
830
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
831 sys::file_stat fs_home_rc (home_rc);
23102
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 if (fs_home_rc)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
834 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
835 // 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
836 // because doing that may change the working directory.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
837
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
838 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
839
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
840 home_rc_already_executed = same_file (home_rc, local_rc);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
841 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
842 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
843
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
844 if (! home_rc_already_executed)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
845 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
846 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
847 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
848
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
849 int status = safe_source_file (local_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
850 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
851
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
852 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
853 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
854 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
855 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
856
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
857 if (m_interactive && verbose)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
858 std::cout << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
859
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
860 return exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
862
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
863 // Execute any code specified with --eval 'CODE'
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
864
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
865 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
866 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
867 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
868
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
869 std::string code_to_eval = options.code_to_eval ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
870
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
871 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
872
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
873 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
875 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
876
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
877 octave_signal_hook = signal_handler;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
878 octave_interrupt_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879 octave_bad_alloc_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
881 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
883 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
884
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
885 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
886
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
887 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
888
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
889 int parse_status = 0;
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 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
893 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
894 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
895 catch (const interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
896 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
899 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
900 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
901 catch (const execution_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
904
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
905 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
906 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
907
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
908 return parse_status;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
909 }
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 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
912 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
913 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
914
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
915 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
916
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
917 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
919 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
920
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
921 octave_signal_hook = signal_handler;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
922 octave_interrupt_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
923 octave_bad_alloc_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
924
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
925 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
926
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
927 octave_initialized = true;
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 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
930
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
931 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
932
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
933 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
934
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
935 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
936
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
937 frame.add_method (m_app_context,
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
938 &application::program_invocation_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939 application::program_invocation_name ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
941 frame.add_method (m_app_context,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942 &application::program_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
943 application::program_name ());
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 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
946
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
947 // If we are running an executable script (#! /bin/octave) then
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
948 // we should only see the args passed to the script.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
949
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
950 string_vector script_args = options.remaining_args ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
951
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
952 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
953 intern_nargin (script_args.numel () - 1);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
954
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
955 std::string fname = script_args[0];
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
956
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957 m_app_context->set_program_names (fname);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
959 std::string context;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
960 bool verbose = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961 bool require_file = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
962
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
963 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
964 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
965
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
966 int interpreter::main_loop (void)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
967 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
968 if (! m_app_context)
23104
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
969 return 0;
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
970
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
971 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
972
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
973 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
974
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
975 octave_signal_hook = signal_handler;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
976 octave_interrupt_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
977 octave_bad_alloc_hook = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
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 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
980
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
981 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
982
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
983 // The big loop.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
984
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
985 lexer *lxr = (application::interactive ()
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
986 ? new lexer ()
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
987 : new lexer (stdin));
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
988
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
989 parser parser (*lxr);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
990
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
991 int retval = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
992 do
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
993 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
994 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 reset_error_handler ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
998 parser.reset ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
999
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1000 if (m_symbol_table.at_top_level ())
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1001 tree_evaluator::reset_debug_state ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1002
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1003 retval = parser.run ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1004
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005 if (retval == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1006 {
23694
4a62da62af09 use m_ prefix for member variables in parser
John W. Eaton <jwe@octave.org>
parents: 23651
diff changeset
1007 if (parser.m_stmt_list)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1008 {
23694
4a62da62af09 use m_ prefix for member variables in parser
John W. Eaton <jwe@octave.org>
parents: 23651
diff changeset
1009 parser.m_stmt_list->accept (m_evaluator);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1010
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1011 octave_quit ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1012
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1013 if (! application::interactive ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1014 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1015 bool quit = (tree_return_command::returning
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1016 || tree_break_command::breaking);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1018 if (tree_return_command::returning)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1019 tree_return_command::returning = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1020
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1021 if (tree_break_command::breaking)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1022 tree_break_command::breaking--;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1023
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1024 if (quit)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1025 break;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1026 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1027
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1028 if (octave_completion_matches_called)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1029 octave_completion_matches_called = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1030 else
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1031 command_editor::increment_current_command_number ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032 }
23694
4a62da62af09 use m_ prefix for member variables in parser
John W. Eaton <jwe@octave.org>
parents: 23651
diff changeset
1033 else if (parser.m_lexer.end_of_input)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1034 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1035 retval = EOF;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1036 break;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1037 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1038 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1039 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1040 catch (const interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1042 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1043
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1044 // Required newline when the user does Ctrl+C at the prompt.
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1045 if (application::interactive ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1046 octave_stdout << "\n";
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1047 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1048 catch (const index_exception& e)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1049 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1050 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1051
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1052 std::cerr << "error: unhandled index exception: "
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1053 << e.message () << " -- trying to return to prompt"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1054 << std::endl;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1055 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1056 catch (const execution_exception& e)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1057 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1058 std::string stack_trace = e.info ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1059
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1060 if (! stack_trace.empty ())
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1061 std::cerr << stack_trace;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1062
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1063 if (application::interactive ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1064 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1065 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1066 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1067 // We should exit with a nonzero status.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1068 retval = 1;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1069 break;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1070 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1071 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1072 catch (const std::bad_alloc&)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1073 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1074 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1075
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1076 std::cerr << "error: out of memory -- trying to return to prompt"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1077 << std::endl;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1078 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1079
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1080 #if defined (DBSTOP_NANINF)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1081 if (Vdebug_on_naninf)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1082 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083 if (setjump (naninf_jump) != 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084 debug_or_throw_exception (true); // true = stack trace
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1085 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1086 #endif
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1087 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1088 while (retval == 0);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1089
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1090 if (retval == EOF)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1091 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1092 if (application::interactive ())
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1093 octave_stdout << "\n";
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1094
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1095 retval = 0;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1096 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1097
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1098 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1099 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1100
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1101 // 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
1102 // errors while shutting down.
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1103
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1104 #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
1105 catch (E) \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1106 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1107 recover_from_exception (); \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1108 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1109 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
1110 << std::endl; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1111 }
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1112
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1113 #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
1114 do \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1115 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1116 try \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1117 { \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1118 unwind_protect frame; \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1119 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1120 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
1121 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
1122 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1123 Vdebug_on_error = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1124 Vdebug_on_warning = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1125 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1126 F ARGS; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1127 } \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1128 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
1129 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
1130 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
1131 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
1132 } \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1133 while (0)
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1134
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
1135 void interpreter::cleanup (void)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1136 {
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1137 // 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
1138 // disconnect the link.
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1139
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1140 octave_link::process_events (true);
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1141 octave_link::disconnect_link ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1142
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1143 OCTAVE_SAFE_CALL (remove_input_event_hook_functions, ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1144
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1145 while (! atexit_functions.empty ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1146 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1147 std::string fcn = atexit_functions.front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1148
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1149 atexit_functions.pop_front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1150
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1151 OCTAVE_SAFE_CALL (reset_error_handler, ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1153 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
1154
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1155 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1156 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1157
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1158 // 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
1159 // 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
1160 // called.
23699
b29904962d2d deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
1161 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
1162
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1163 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
1164
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1165 OCTAVE_SAFE_CALL (octave_history_write_timestamp, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1166
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1167 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
1168 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
1169
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1170 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
1171
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1172 OCTAVE_SAFE_CALL (gtk_manager::unload_all_toolkits, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1173
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1174 OCTAVE_SAFE_CALL (close_files, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1176 OCTAVE_SAFE_CALL (cleanup_tmp_files, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1177
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1178 // 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
1179 // 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
1180 // 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
1181 m_symbol_table.cleanup ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1183 OCTAVE_SAFE_CALL (sysdep_cleanup, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1184
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1185 OCTAVE_SAFE_CALL (octave_finalize_hdf5, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1186
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1187 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1188
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1189 // 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
1190 // 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
1191 // 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
1192 // 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
1193 // 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
1194 // 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
1195 // 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
1196 // .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
1197 // is unloaded.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1198 //
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1199 // 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
1200
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1201 OCTAVE_SAFE_CALL (chunk_buffer::clear, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1202 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1203
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1204 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
1205 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1206 return m_evaluator;
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1207 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1208
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1209 symbol_table::scope *
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1210 interpreter::get_current_scope (void)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1211 {
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1212 return m_symbol_table.current_scope ();
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1213 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1214
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1215 symbol_table::scope *
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1216 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
1217 {
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1218 symbol_table::scope *scope = get_current_scope ();
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1219
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1220 if (! scope)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1221 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
1222
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1223 return scope;
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1224 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1225
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1226 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
1227 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1228 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
1229 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1230
23703
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1231 void interpreter::mlock (void)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1232 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1233 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
1234
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1235 octave_function *fcn = cs.current ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1236
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1237 if (! fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1238 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
1239
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1240 fcn->lock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1241 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1242
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1243 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
1244 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1245 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
1246
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1247 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1248 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1249 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
1250
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1251 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1252 fcn->unlock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1253 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1254 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1255
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1256 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
1257 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1258 bool retval = false;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1259
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1260 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
1261
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1262 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1263 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1264 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
1265
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1266 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1267 retval = fcn->islocked ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1268 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1269
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1270 return retval;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1271 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1272
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1273 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
1274 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1275 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
1276 octave_interrupt_immediately = 0;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1277 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
1278 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
1279 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
1280 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
1281 catch_interrupts ();
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1282 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1283
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1284 // 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
1285
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1286 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
1287
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1288 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
1289 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1290 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
1291 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1292
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1293 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
1294 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1295 bool found = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1296
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1297 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
1298 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
1299 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1300 if (*it == fname)
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1301 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1302 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
1303 found = true;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1304 break;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1305 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1306 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1307
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1308 return found;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1309 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1310 }