annotate libinterp/corefcn/interpreter.cc @ 27531:478150691336

consolidate initialization code * interpreter.cc (interpreter::initialize): Set up interrupt and signal handling here instead of duplicatin that action in the execute_eval_option_code, execute_command_line_file, and main_loop methods.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Oct 2019 15:40:25 -0400
parents 7a9d2b0e6da8
children 2af853f94b97
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
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3 Copyright (C) 1993-2019 John W. Eaton
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
10 (at your option) any later version.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22718
diff changeset
15 GNU General Public License for more details.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24520
diff changeset
19 <https://www.gnu.org/licenses/>.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #if defined (HAVE_CONFIG_H)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 # include "config.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
27 #include <cstdio>
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
28
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <string>
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <iostream>
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "cmd-edit.h"
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
33 #include "cmd-hist.h"
27408
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
34 #include "file-ops.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "file-stat.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #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
37 #include "lo-blas-proto.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "lo-error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "oct-env.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "str-vec.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "signal-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "unistd-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
44 #include "builtin-defun-decls.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "defaults.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "Cell.h"
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"
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27262
diff changeset
50 #include "event-manager.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "file-io.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 #include "graphics.h"
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
53 #include "help.h"
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
54 #include "input.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
55 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 #include "interpreter.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 #include "load-path.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 #include "load-save.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 #include "octave.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 #include "oct-hist.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 #include "oct-map.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 #include "oct-mutex.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 #include "ovl.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 #include "ov.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 #include "ov-classdef.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 #include "parse.h"
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
67 #include "pt-classdef.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 #include "pt-eval.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 #include "pt-jump.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 #include "pt-stmt.h"
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
71 #include "settings.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 #include "sighandlers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 #include "sysdep.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 #include "unwind-prot.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 #include "utils.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 #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
77 #include "version.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 // TRUE means the quit() call is allowed.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 bool quit_allowed = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 // 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
83 // is ready for interactive use.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 bool octave_interpreter_ready = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 // 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
87 bool octave_initialized = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 DEFUN (__version_info__, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 @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
92 Undocumented internal function.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 @end deftypefn */)
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 static octave_map vinfo;
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 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 if (nargin != 0 && nargin != 4)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 print_usage ();
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 octave_value retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 if (nargin == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 retval = vinfo;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 else if (nargin == 4)
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 if (vinfo.nfields () == 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 vinfo.assign ("Name", args(0));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 vinfo.assign ("Version", args(1));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 vinfo.assign ("Release", args(2));
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 vinfo.assign ("Date", args(3));
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 else
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 octave_idx_type n = vinfo.numel () + 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 vinfo.resize (dim_vector (n, 1));
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 octave_value idx (n);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 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
124 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
125 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
126 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
127 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27214
diff changeset
133 DEFMETHOD (quit, interp, args, ,
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27214
diff changeset
134 doc: /* -*- texinfo -*-
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 @deftypefn {} {} exit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 @deftypefnx {} {} exit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 @deftypefnx {} {} quit
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 @deftypefnx {} {} quit (@var{status})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 Exit the current Octave session.
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 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
142 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
143
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 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
145 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
146 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
147 to run using @code{atexit}.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 @seealso{atexit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 // 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
152 // 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
153 // yet call this base "quit" could be nice. No link would be needed here.
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27214
diff changeset
154
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27262
diff changeset
155 octave::event_manager& evmgr = interp.get_event_manager ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27214
diff changeset
156
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27262
diff changeset
157 if (! evmgr.confirm_shutdown ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 if (! quit_allowed)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 error ("quit: not supported in embedded mode");
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 int exit_status = 0;
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 if (args.length () > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 exit_status = args(0).nint_value ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 // 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
169 // 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
170 // 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
171 // etc. before exiting.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
173 throw octave::exit_exception (exit_status);
22094
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 return ovl ();
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 DEFALIAS (exit, quit);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
180 DEFMETHOD (atexit, interp, args, nargout,
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
181 doc: /* -*- texinfo -*-
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 @deftypefn {} {} atexit (@var{fcn})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 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
185
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 For example,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 @group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 function last_words ()
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 disp ("Bye bye");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 endfunction
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 atexit ("last_words");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 @end group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 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
199
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 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
201 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
202 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
203 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
204 above,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 atexit ("last_words", false);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 @end example
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 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 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
212 @code{last_words} when it exits.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 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
215 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
216 @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
217 @seealso{quit}
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 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 if (nargin < 1 || nargin > 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 print_usage ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 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
226
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 bool add_mode = (nargin == 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 ? 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
229 : true;
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 octave_value_list retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 if (add_mode)
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
234 octave::interpreter::add_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
237 bool found = interp.remove_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 if (nargout > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 retval = ovl (found);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 }
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 return retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 }
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 namespace octave
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 {
27408
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
248 // The time we last time we changed directories.
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
249 sys::time Vlast_chdir_time = 0.0;
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
250
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
251 // Execute commands from a file and catch potential exceptions in a consistent
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
252 // way. This function should be called anywhere we might parse and execute
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
253 // commands from a file before we have entered the main loop in
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
254 // toplev.cc.
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
255
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
256 static int safe_source_file (const std::string& file_name,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
257 const std::string& context = "",
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
258 bool verbose = false,
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27506
diff changeset
259 bool require_file = true)
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
260 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
261 interpreter& interp = __get_interpreter__ ("safe_source_file");
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
262
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
263 try
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
264 {
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27506
diff changeset
265 source_file (file_name, context, verbose, require_file);
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
266 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
267 catch (const interrupt_exception&)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
268 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
269 interp.recover_from_exception ();
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
270
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
271 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
272 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
273 catch (const execution_exception& e)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
274 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
275 interp.handle_exception (e);
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
276
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
277 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
278 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
279
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
280 return 0;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
281 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
282
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
283 static void initialize_version_info (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
284 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
285 octave_value_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
286
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
287 args(3) = OCTAVE_RELEASE_DATE;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
288 args(2) = config::release ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
289 args(1) = OCTAVE_VERSION;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
290 args(0) = "GNU Octave";
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
291
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
292 F__version_info__ (args, 0);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
293 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
294
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
295 static void xerbla_abort (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
296 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
297 error ("Fortran procedure terminated by call to XERBLA");
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
298 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
299
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
300 static void initialize_xerbla_error_handler (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
301 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
302 // The idea here is to force xerbla to be referenced so that we will
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
303 // link to our own version instead of the one provided by the BLAS
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
304 // library. But numeric_limits<double>::NaN () should never be -1, so
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
305 // we should never actually call xerbla. FIXME (again!): If this
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
306 // becomes a constant expression the test might be optimized away and
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
307 // then the reference to the function might also disappear.
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
308
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
309 if (numeric_limits<double>::NaN () == -1)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
310 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
311
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
312 typedef void (*xerbla_handler_ptr) (void);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
313
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
314 typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
315
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
316 dynamic_library libs ("");
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
317
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
318 if (libs)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
319 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
320 octave_set_xerbla_handler_ptr octave_set_xerbla_handler
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
321 = reinterpret_cast<octave_set_xerbla_handler_ptr>
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
322 (libs.search ("octave_set_xerbla_handler"));
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
323
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
324 if (octave_set_xerbla_handler)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
325 octave_set_xerbla_handler (xerbla_abort);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
326 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
327 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
328
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
329 OCTAVE_NORETURN static void
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
330 lo_error_handler (const char *fmt, ...)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
331 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
332 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
333 va_start (args, fmt);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
334 verror_with_cfn (fmt, args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
335 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
336
27480
63b417917f5e remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents: 27474
diff changeset
337 throw execution_exception ();
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
338 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
339
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
340 OCTAVE_NORETURN static void
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
341 lo_error_with_id_handler (const char *id, const char *fmt, ...)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
342 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
343 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
344 va_start (args, fmt);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
345 verror_with_id_cfn (id, fmt, args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
346 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
347
27480
63b417917f5e remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents: 27474
diff changeset
348 throw execution_exception ();
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
349 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
350
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
351 static void initialize_error_handlers (void)
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
352 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
353 set_liboctave_error_handler (lo_error_handler);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
354 set_liboctave_error_with_id_handler (lo_error_with_id_handler);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
355 set_liboctave_warning_handler (warning);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
356 set_liboctave_warning_with_id_handler (warning_with_id);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
357 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
358
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
359 // 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
360 // 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
361 // path.
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
362
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
363 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
364 : m_app_context (app_context),
27266
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
365 m_display_info (),
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
366 m_environment (),
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
367 m_settings (),
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
368 m_error_system (*this),
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
369 m_help_system (*this),
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
370 m_input_system (*this),
25435
a52e6fb674b1 eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents: 25407
diff changeset
371 m_output_system (*this),
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
372 m_history_system (*this),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
373 m_dynamic_loader (*this),
27394
489c74ac36da store reference to interpreter in load_path object
John W. Eaton <jwe@octave.org>
parents: 27335
diff changeset
374 m_load_path (*this),
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
375 m_load_save_system (*this),
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24538
diff changeset
376 m_type_info (),
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
377 m_symbol_table (*this),
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
378 m_evaluator (*this),
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
379 m_stream_list (*this),
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24727
diff changeset
380 m_child_list (),
23742
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
381 m_url_handle_manager (),
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23630
diff changeset
382 m_cdef_manager (*this),
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
383 m_gtk_manager (),
27302
5f170ea12fa1 use Qt signals to pass interpreter callbacks to octave-qobject
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
384 m_event_manager (*this),
27321
eddce82a57cc don't use singleton pattern for gh_manager object
John W. Eaton <jwe@octave.org>
parents: 27309
diff changeset
385 m_gh_manager (nullptr),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
386 m_interactive (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
387 m_read_site_files (true),
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
388 m_read_init_files (m_app_context != nullptr),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
389 m_verbose (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
390 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
391 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
392 m_history_initialized (false),
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
393 m_in_top_level_repl (false),
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
394 m_initialized (false)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 {
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
396 // FIXME: When thread_local storage is used by default, this message
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
397 // should change to say something like
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
398 //
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
399 // only one Octave interpreter may be active in any given thread
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
400
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
401 if (instance)
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
402 throw std::runtime_error
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
403 ("only one Octave interpreter may be active");
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
404
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
405 instance = this;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
27309
463fc0cfed90 initialize locale from values in the environment on interpreter start
Mike Miller <mtmiller@octave.org>
parents: 27302
diff changeset
408 setlocale (LC_ALL, "");
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 setlocale (LC_NUMERIC, "C");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410 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
411 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
412 sys::env::putenv ("LC_TIME", "C");
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414 // Initialize the default floating point unit control state.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 octave_set_default_fpucw ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
417 thread::init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
419 octave_ieee_init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
421 initialize_xerbla_error_handler ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 initialize_error_handlers ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
425 if (m_app_context)
26826
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
426 {
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
427 install_signal_handlers ();
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
428 octave_unblock_signal_by_name ("SIGTSTP");
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
429 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 quit_allowed = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
27266
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
433 if (! m_app_context)
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
434 m_display_info.initialize ();
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
435
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
436 bool line_editing = false;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
437 bool traditional = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
439 if (m_app_context)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
440 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
441 // 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
442 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
443
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
444 // 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
445 // including PKG_ADD files.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
447 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
448
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
449 m_app_context->intern_argv (args);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
450 intern_nargin (args.numel () - 1);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
451
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
452 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
453
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
454 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
455
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
456 for (const auto& pth : command_line_path)
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
457 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
458
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
459 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
460 if (! exec_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
461 m_environment.exec_path (exec_path);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
463 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
464 if (! image_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
465 m_environment.image_path (image_path);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
466
27266
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
467 if (! options.no_window_system ())
596312d4f25d don't use singleton pattern for display_info class
John W. Eaton <jwe@octave.org>
parents: 27263
diff changeset
468 m_display_info.initialize ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
470 // 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
471 // interactive.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
472
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
473 // 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
474 // pipe or a redirected file.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
475 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
476
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
477 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
478 && octave_isatty_wrapper (fileno (stdout)));
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
479
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
480 // 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
481 if (options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
482 m_interactive = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
483
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
484 line_editing = options.line_editing ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
485 if ((! m_interactive || options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
486 && ! options.forced_line_editing ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
487 line_editing = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
489 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
490
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
491 // 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
492 // 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
493
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
494 if (options.echo_commands ())
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
495 m_evaluator.echo
25063
a211e39e59d9 restore '--echo-commands' option to same behavior as 'echo on all' (bug #53453)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
496 (tree_evaluator::ECHO_SCRIPTS | tree_evaluator::ECHO_FUNCTIONS
a211e39e59d9 restore '--echo-commands' option to same behavior as 'echo on all' (bug #53453)
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
497 | tree_evaluator::ECHO_ALL);
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
498
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
499 std::string 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
500 if (! docstrings_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
501 Fbuilt_in_docstrings_file (*this, octave_value (docstrings_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
502
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
503 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
504 if (! doc_cache_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
505 Fdoc_cache_file (*this, octave_value (doc_cache_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
506
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
507 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
508 if (! info_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
509 Finfo_file (*this, octave_value (info_file));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
510
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
511 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
512 if (! info_program.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
513 Finfo_program (*this, octave_value (info_program));
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
514
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
515 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
516 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
517
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
518 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
519 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
520
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
521 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
522 if (! texi_macros_file.empty ())
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
523 Ftexi_macros_file (*this, octave_value (texi_macros_file));
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
524 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525
27322
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
526 // FIXME: we defer creation of the gh_manager object because it
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
527 // creates a root_figure object that requires the display_info
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
528 // object, but that is currently only accessible through the global
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
529 // interpreter object and that is not available until after the
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
530 // interpreter::instance pointer is set (above). It would be better
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
531 // if m_gh_manager could be an object value instead of a pointer and
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
532 // created as part of the interpreter initialization. To do that,
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
533 // we should either make the display_info object independent of the
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
534 // interpreter object (does it really need to cache any
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
535 // information?) or defer creation of the root_figure object until
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
536 // it is actually needed.
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
537 m_gh_manager = new gh_manager (*this);
cb92168e48f6 defer gh_manager creation until after display_info initialization
John W. Eaton <jwe@octave.org>
parents: 27321
diff changeset
538
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
539 m_input_system.initialize (line_editing);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 // 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
542 // 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
543
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 initialize_version_info ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
546 // 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
547 // 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
548
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
549 if (traditional)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
550 maximum_braindamage ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
552 octave_interpreter_ready = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
555 OCTAVE_THREAD_LOCAL interpreter *interpreter::instance = nullptr;
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
556
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
557 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
558 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
559 cleanup ();
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27322
diff changeset
560
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27322
diff changeset
561 delete m_gh_manager;
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 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
566 m_evaluator.set_auto_fcn_var (stack_frame::NARGIN, nargs);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
567 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
568
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
569 // 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
570
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
571 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
572 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
573 if (! m_history_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
574 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
575 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
576
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
577 if (m_app_context)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
578 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
579 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
580
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
581 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
582
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
583 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
584 command_history::ignore_entries ();
23117
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
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
587 m_history_system.initialize (read_history_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
588
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
589 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
590 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
591
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
592 m_history_initialized = true;
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
593 }
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
594 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
595
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
596 // 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
597 // option says to leave it empty.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
598
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
599 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
600 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
601 if (! m_load_path_initialized)
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 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
604
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
605 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
607 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
608
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
609 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
610 }
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 // 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
613 // 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
614 // 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
615 // 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
616 // 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
617 // 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
618 // 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
619 // are already handled.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
620
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
621 unwind_protect frame;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
622
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
623 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
624 m_load_path.get_add_hook ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
625
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
626 m_load_path.set_add_hook ([this] (const std::string& dir)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
627 { this->execute_pkg_add (dir); });
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
628
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
629 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
630
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
631 m_load_path_initialized = true;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
632 }
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
633 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
634
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
635 // 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
636
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
637 void interpreter::initialize (void)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
638 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
639 if (m_initialized)
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
640 return;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
641
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
642 display_startup_message ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
643
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
644 // 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
645 // files and begins evaluating commands.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
646
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
647 initialize_history ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
648
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
649 // 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
650 // 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
651
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
652 // 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
653 // 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
654 // 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
655
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
656 initialize_load_path ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
657
27531
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
658 octave_save_signal_mask ();
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
659
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
660 can_interrupt = true;
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
661
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
662 octave_signal_hook = respond_to_pending_signals;
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
663 octave_interrupt_hook = nullptr;
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
664
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
665 catch_interrupts ();
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
666
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
667 // FIXME: could we eliminate this variable or make it not be global?
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
668 // Global used to communicate with signal handler.
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
669 octave_initialized = true;
478150691336 consolidate initialization code
John W. Eaton <jwe@octave.org>
parents: 27530
diff changeset
670
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
671 m_initialized = true;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
672 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
673
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
674 // FIXME: this function is intended to be executed only once. Should
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
675 // we enforce that restriction?
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
676
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
677 int interpreter::execute (void)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
678 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
679 int exit_status = 0;
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
680
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
681 try
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
682 {
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
683 initialize ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
684
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
685 execute_startup_files ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
686
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
687 if (m_app_context)
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
688 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
689 const cmdline_options& options = m_app_context->options ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
690
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
691 if (m_app_context->have_eval_option_code ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
692 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
693 int status = execute_eval_option_code ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
694
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
695 if (status )
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
696 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
697
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
698 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
699 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
700 }
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
701
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
702 // If there is an extra argument, see if it names a file to
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
703 // read. Additional arguments are taken as command line options
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
704 // for the script.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
705
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
706 if (m_app_context->have_script_file ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
707 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
708 int status = execute_command_line_file ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
709
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
710 if (status)
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
711 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
712
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
713 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
714 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
715 }
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
716
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
717 if (options.forced_interactive ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
718 command_editor::blink_matching_paren (false);
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
719 }
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
720
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
721 return main_loop ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
722 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
723 catch (const exit_exception& ex)
23117
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 return ex.exit_status ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
726 }
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
727
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
728 return exit_status;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
729 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
730
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
731 void interpreter::display_startup_message (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
732 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
733 bool inhibit_startup_message = false;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
734
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
735 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
736 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
737 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
738
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
739 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
740 }
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23220
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_interactive && ! inhibit_startup_message)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
743 std::cout << octave_startup_message () << "\n" << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
744 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
745
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
746 // 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
747 // 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
748 // exception.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
749
26722
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
750 int interpreter::execute_startup_files (void)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
751 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
752 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
753 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
754 bool verbose = m_verbose;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
755 bool inhibit_startup_message = m_inhibit_startup_message;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
756
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
757 if (m_app_context)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
758 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
759 const cmdline_options& options = m_app_context->options ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
760
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
761 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
762 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
763 verbose = options.verbose_flag ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
764 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
765 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
767 verbose = (verbose && ! inhibit_startup_message);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
768
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
769 bool require_file = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
770
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
771 std::string context;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
772
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
773 int exit_status = 0;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
774
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
775 if (read_site_files)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
776 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
777 // Execute commands from the site-wide configuration file.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
778 // First from the file $(prefix)/lib/octave/site/m/octaverc
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
779 // (if it exists), then from the file
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
780 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
781
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
782 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
783 context, verbose, require_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
784
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
785 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
786 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
787
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
788 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
789 context, verbose, require_file);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
790
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
791 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
792 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
793 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
794
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
795 if (read_init_files)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
796 {
26722
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
797 // Try to execute commands from the Matlab compatible startup.m file
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
798 // if it exists anywhere in the load path when starting Octave.
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
799 std::string ff_startup_m = file_in_path ("startup.m", "");
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
800
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
801 if (! ff_startup_m.empty ())
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
802 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
803 int parse_status = 0;
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
804
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
805 try
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
806 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
807 eval_string (std::string ("startup"), false, parse_status, 0);
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
808 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
809 catch (const interrupt_exception&)
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
810 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
811 recover_from_exception ();
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
812 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
813 catch (const execution_exception& e)
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
814 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
815 handle_exception (e);
26722
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
816 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
817 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
818
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
819 // Schedule the Matlab compatible finish.m file to run if it exists
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
820 // anywhere in the load path when exiting Octave.
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
821 add_atexit_function ("__finish__");
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
822
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
823 // Try to execute commands from $HOME/$OCTAVE_INITFILE and
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
824 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
825 // .octaverc is assumed.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
826
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
827 bool home_rc_already_executed = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
828
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
829 std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
830
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
831 if (initfile.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
832 initfile = ".octaverc";
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
833
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
834 std::string home_dir = sys::env::get_home_directory ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
835
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
836 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
837
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
838 std::string local_rc;
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 if (! home_rc.empty ())
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 int status = safe_source_file (home_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
843 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
844
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
845 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
846 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
847
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
848 // Names alone are not enough.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
849
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
850 sys::file_stat fs_home_rc (home_rc);
23102
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 (fs_home_rc)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
853 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
854 // 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
855 // because doing that may change the working directory.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
856
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
857 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
858
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
859 home_rc_already_executed = same_file (home_rc, local_rc);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
860 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
861 }
22094
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 if (! home_rc_already_executed)
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 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
866 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
867
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
868 int status = safe_source_file (local_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
869 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
870
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
871 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
872 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
873 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
874 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
875
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
876 if (m_interactive && verbose)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
877 std::cout << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
878
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
879 return exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
882 // Execute any code specified with --eval 'CODE'
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
883
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
884 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
885 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
886 if (! m_app_context)
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
887 return 0;
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
888
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
889 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
890
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
891 std::string code_to_eval = options.code_to_eval ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
892
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
893 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
894
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895 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
896
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
899 int parse_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
900
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
901 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
903 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
904 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
905 catch (const interrupt_exception&)
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 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
908
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
909 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
911 catch (const execution_exception& e)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
912 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
913 handle_exception (e);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
914
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
915 return 1;
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918 return parse_status;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
919 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
920
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
921 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
922 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
923 if (! m_app_context)
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
924 return 0;
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
925
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
926 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
927
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
928 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
929
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
930 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
931
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
932 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
933
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
934 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
935
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
936 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
937
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
938 frame.add_method (m_app_context,
22094
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 application::program_invocation_name ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
941
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942 frame.add_method (m_app_context,
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 application::program_name ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
945
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
946 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
948 // If we are running an executable script (#! /bin/octave) then
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
949 // we should only see the args passed to the script.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
950
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
951 string_vector script_args = options.remaining_args ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
952
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
953 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
954 intern_nargin (script_args.numel () - 1);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
955
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
956 std::string fname = script_args[0];
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
957
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958 m_app_context->set_program_names (fname);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
959
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
960 std::string context;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961 bool verbose = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
962 bool require_file = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
963
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27506
diff changeset
964 return safe_source_file (fname, context, verbose, require_file);
22094
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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
967 int interpreter::main_loop (void)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
968 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
969 int exit_status = 0;
23104
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 // The big loop.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
972
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
973 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
974
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
975 input_reader reader (*this);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
976
27526
cb964b74d8a0 Backed out changeset 28ed77ca1e4a
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
977 push_parser repl_parser (*this);
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
978
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
979 #else
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
980
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
981 // The pull parser takes ownership of the lexer and will delete it
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
982 // when the parser goes out of scope.
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
983
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
984 parser repl_parser (m_interactive
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
985 ? new lexer (*this) : new lexer (stdin, *this));
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
986
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
987 #endif
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
988
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
989 do
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
990 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
991 try
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
992 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
993 unwind_protect_var<bool> upv (m_in_top_level_repl, true);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
994
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
995 repl_parser.reset ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
996
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
997 if (m_evaluator.at_top_level ())
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
998 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
999 m_evaluator.dbstep_flag (0);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1000 m_evaluator.reset_debug_state ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1001 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1002
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1003 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1004
27528
e51284fc0a51 eliminate promptflag from the lexer and input reader classes
John W. Eaton <jwe@octave.org>
parents: 27527
diff changeset
1005 std::string prompt
e51284fc0a51 eliminate promptflag from the lexer and input reader classes
John W. Eaton <jwe@octave.org>
parents: 27527
diff changeset
1006 = command_editor::decode_prompt_string (m_input_system.PS1 ());
e51284fc0a51 eliminate promptflag from the lexer and input reader classes
John W. Eaton <jwe@octave.org>
parents: 27527
diff changeset
1007
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1008 do
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1009 {
27527
73be3c628eac refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents: 27526
diff changeset
1010 bool eof = false;
73be3c628eac refactor input_reader class and its use in lexer
John W. Eaton <jwe@octave.org>
parents: 27526
diff changeset
1011 std::string input_line = reader.get_input (prompt, eof);
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1012
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1013 if (eof)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1014 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1015 exit_status = EOF;
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1016 break;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1017 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1018
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1019 exit_status = repl_parser.run (input_line, false);
27528
e51284fc0a51 eliminate promptflag from the lexer and input reader classes
John W. Eaton <jwe@octave.org>
parents: 27527
diff changeset
1020
e51284fc0a51 eliminate promptflag from the lexer and input reader classes
John W. Eaton <jwe@octave.org>
parents: 27527
diff changeset
1021 prompt = command_editor::decode_prompt_string (m_input_system.PS2 ());
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1022 }
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1023 while (exit_status < 0);
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1024
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1025 #else
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1026
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1027 exit_status = repl_parser.run ();
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1028
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1029 #endif
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1030 if (exit_status == 0)
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1031 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1032 std::shared_ptr<tree_statement_list>
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1033 stmt_list = repl_parser.statement_list ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1034
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1035 if (stmt_list)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1036 {
27529
886df2049d81 only increment command number when complete block of code is parsed
John W. Eaton <jwe@octave.org>
parents: 27528
diff changeset
1037 command_editor::increment_current_command_number ();
886df2049d81 only increment command number when complete block of code is parsed
John W. Eaton <jwe@octave.org>
parents: 27528
diff changeset
1038
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1039 m_evaluator.eval (stmt_list, m_interactive);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1040 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1041 else if (repl_parser.at_end_of_input ())
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1042 {
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1043 exit_status = EOF;
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1044 break;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1045 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1046 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1047 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1048 catch (const interrupt_exception&)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1049 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1050 recover_from_exception ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1051
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1052 // Required newline when the user does Ctrl+C at the prompt.
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1053 if (m_interactive)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1054 octave_stdout << "\n";
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1055 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1056 catch (const index_exception& e)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1057 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1058 recover_from_exception ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1059
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1060 std::cerr << "error: unhandled index exception: "
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1061 << e.message () << " -- trying to return to prompt"
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1062 << std::endl;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1063 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1064 catch (const execution_exception& ee)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1065 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1066 m_error_system.save_exception (ee);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1067 m_error_system.display_exception (ee, std::cerr);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1068
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1069 if (m_interactive)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1070 recover_from_exception ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1071 else
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1072 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1073 // We should exit with a nonzero status.
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1074 exit_status = 1;
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1075 break;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1076 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1077 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1078 catch (const std::bad_alloc&)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1079 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1080 recover_from_exception ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1081
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1082 std::cerr << "error: out of memory -- trying to return to prompt"
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1083 << std::endl;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1084 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1085 }
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1086 while (exit_status == 0);
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1087
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1088 if (exit_status == EOF)
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1089 {
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1090 if (m_interactive)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1091 octave_stdout << "\n";
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1092
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1093 exit_status = 0;
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1094 }
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27517
diff changeset
1095
27530
7a9d2b0e6da8 be more defensive about using m_app_context in interpreter code
John W. Eaton <jwe@octave.org>
parents: 27529
diff changeset
1096 return exit_status;
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
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1099 // 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
1100 // errors while shutting down.
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1101
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1102 #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
1103 catch (E) \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1104 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1105 recover_from_exception (); \
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 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
1108 << std::endl; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1109 }
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1110
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1111 #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
1112 do \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1113 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1114 try \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1115 { \
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1116 unwind_protect frame; \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1117 \
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1118 frame.add_method (m_error_system, \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1119 &error_system::set_debug_on_error, \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1120 m_error_system.debug_on_error ()); \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1121 frame.add_method (m_error_system, \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1122 &error_system::set_debug_on_warning, \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1123 m_error_system.debug_on_warning ()); \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1124 \
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1125 m_error_system.debug_on_error (false); \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1126 m_error_system.debug_on_warning (false); \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1127 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1128 F ARGS; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1129 } \
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1130 OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1131 OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1132 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
1133 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
1134 } \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1135 while (0)
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1136
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
1137 void interpreter::cleanup (void)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1138 {
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1139 // If we are attached to a GUI, process pending events and
27262
d67f369b3074 use shared_ptr to manage octave_link_events object
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
1140 // disable the link.
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1141
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27262
diff changeset
1142 m_event_manager.process_events (true);
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27262
diff changeset
1143 m_event_manager.disable ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1144
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1145 OCTAVE_SAFE_CALL (m_input_system.clear_input_event_hooks, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1146
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1147 while (! atexit_functions.empty ())
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 std::string fcn = atexit_functions.front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1150
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1151 atexit_functions.pop_front ();
22094
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
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1165 OCTAVE_SAFE_CALL (m_history_system.write_timestamp, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
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
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27322
diff changeset
1170 OCTAVE_SAFE_CALL (m_gh_manager->close_all_figures, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1171
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
1172 m_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 (cleanup_tmp_files, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1176 // 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
1177 // 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
1178 // 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
1179 m_symbol_table.cleanup ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1180
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1181 OCTAVE_SAFE_CALL (sysdep_cleanup, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1183 OCTAVE_SAFE_CALL (flush_stdout, ());
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 // 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
1186 // 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
1187 // 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
1188 // 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
1189 // 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
1190 // 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
1191 // 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
1192 // .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
1193 // is unloaded.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1194 //
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1195 // 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
1196 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1197
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1198 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
1199 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1200 return m_evaluator;
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1201 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1202
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1203 stream_list& interpreter::get_stream_list (void)
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1204 {
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1205 return m_stream_list;
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1206 }
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1207
23742
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1208 url_handle_manager& interpreter::get_url_handle_manager (void)
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1209 {
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1210 return m_url_handle_manager;
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1211 }
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1212
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1213 symbol_scope
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1214 interpreter::get_top_scope (void) const
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1215 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1216 return m_evaluator.get_top_scope ();
23609
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
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1219 symbol_scope
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1220 interpreter::get_current_scope (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1221 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1222 return m_evaluator.get_current_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1223 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1224
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1225 symbol_scope
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1226 interpreter::require_current_scope (const std::string& who) const
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1227 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1228 symbol_scope scope = get_current_scope ();
23609
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1229
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1230 if (! scope)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1231 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
1232
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1233 return scope;
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1234 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1235
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1236 profiler& interpreter::get_profiler (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1237 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1238 return m_evaluator.get_profiler ();
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1239 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1240
27408
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1241 int interpreter::chdir (const std::string& dir)
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1242 {
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1243 std::string xdir = sys::file_ops::tilde_expand (dir);
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1244
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1245 int cd_ok = sys::env::chdir (xdir);
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1246
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1247 if (! cd_ok)
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1248 error ("%s: %s", dir.c_str (), std::strerror (errno));
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1249
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1250 Vlast_chdir_time.stamp ();
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1251
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1252 // FIXME: should these actions be handled as a list of functions
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1253 // to call so users can add their own chdir handlers?
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1254
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1255 m_load_path.update ();
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1256
27409
a0d49e55acae rename change_directory to directory_changed in event manager
John W. Eaton <jwe@octave.org>
parents: 27408
diff changeset
1257 m_event_manager.directory_changed (sys::env::get_current_directory ());
27408
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1258
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1259 return cd_ok;
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1260 }
9b19eec60931 move change directory function to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27394
diff changeset
1261
23703
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1262 void interpreter::mlock (void)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1263 {
27212
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27161
diff changeset
1264 m_evaluator.mlock ();
23703
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
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1267 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
1268 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1269 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
1270
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1271 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1272 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1273 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
1274
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1275 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1276 fcn->unlock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1277 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1278 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1279
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1280 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
1281 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1282 bool retval = false;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1283
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1284 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
1285
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1286 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1287 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1288 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
1289
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1290 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1291 retval = fcn->islocked ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1292 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1293
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1294 return retval;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1295 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1296
27015
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1297 std::string interpreter::mfilename (const std::string& opt) const
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1298 {
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1299 return m_evaluator.mfilename (opt);
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1300 }
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1301
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1302 octave_value_list interpreter::eval_string (const std::string& eval_str,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1303 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1304 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1305 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1306 return m_evaluator.eval_string (eval_str, silent, parse_status, nargout);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1307 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1308
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1309 octave_value interpreter::eval_string (const std::string& eval_str,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1310 bool silent, int& parse_status)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1311 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1312 return m_evaluator.eval_string (eval_str, silent, parse_status);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1313 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1314
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1315 octave_value_list interpreter::eval_string (const octave_value& arg,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1316 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1317 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1318 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1319 return m_evaluator.eval_string (arg, silent, parse_status, nargout);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1320 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1321
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1322 octave_value_list interpreter::eval (const std::string& try_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1323 int nargout)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1324 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1325 return m_evaluator.eval (try_code, nargout);
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1326 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1327
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1328 octave_value_list interpreter::eval (const std::string& try_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1329 const std::string& catch_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1330 int nargout)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1331 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1332 return m_evaluator.eval (try_code, catch_code, nargout);
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1333 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
1334
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1335 octave_value_list interpreter::evalin (const std::string& context,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1336 const std::string& try_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1337 int nargout)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1338 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1339 return m_evaluator.evalin (context, try_code, nargout);
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1340 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1341
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1342 octave_value_list interpreter::evalin (const std::string& context,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1343 const std::string& try_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1344 const std::string& catch_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1345 int nargout)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1346 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1347 return m_evaluator.evalin (context, try_code, catch_code, nargout);
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1348 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
1349
27020
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1350 //! Evaluate an Octave function (built-in or interpreted) and return
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1351 //! the list of result values.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1352 //!
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1353 //! @param name The name of the function to call.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1354 //! @param args The arguments to the function.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1355 //! @param nargout The number of output arguments expected.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1356 //! @return A list of output values. The length of the list is not
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1357 //! necessarily the same as @c nargout.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1358
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1359 octave_value_list interpreter::feval (const char *name,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1360 const octave_value_list& args,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1361 int nargout)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1362 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1363 return feval (std::string (name), args, nargout);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1364 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1365
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1366 octave_value_list interpreter::feval (const std::string& name,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1367 const octave_value_list& args,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1368 int nargout)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1369 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1370 octave_value fcn = m_symbol_table.find_function (name, args);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1371
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1372 if (fcn.is_undefined ())
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1373 error ("feval: function '%s' not found", name.c_str ());
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1374
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1375 octave_function *of = fcn.function_value ();
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1376
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1377 return of->call (m_evaluator, nargout, args);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1378 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1379
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1380 octave_value_list interpreter::feval (octave_function *fcn,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1381 const octave_value_list& args,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1382 int nargout)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1383 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1384 if (fcn)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1385 return fcn->call (m_evaluator, nargout, args);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1386
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1387 return octave_value_list ();
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1388 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1389
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1390 octave_value_list interpreter::feval (const octave_value& val,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1391 const octave_value_list& args,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1392 int nargout)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1393 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1394 // FIXME: do we really want to silently return an empty ovl if
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1395 // the function object is undefined? It's essentially what the
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1396 // version above that accepts a pointer to an octave_function
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1397 // object does and some code was apparently written to rely on it
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1398 // (for example, __ode15__).
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1399
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1400 if (val.is_undefined ())
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1401 return ovl ();
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1402
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1403 if (val.is_function ())
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1404 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1405 return feval (val.function_value (), args, nargout);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1406 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1407 else if (val.is_function_handle ())
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1408 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1409 // This covers function handles, inline functions, and anonymous
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1410 // functions.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1411
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1412 std::list<octave_value_list> arg_list;
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1413 arg_list.push_back (args);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1414
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1415 // FIXME: could we make octave_value::subsref a const method?
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1416 // It would be difficult because there are instances of
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1417 // incrementing the reference count inside subsref methods,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1418 // which means they can't be const with the current way of
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1419 // handling reference counting.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1420
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1421 octave_value xval = val;
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1422 return xval.subsref ("(", arg_list, nargout);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1423 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1424 else if (val.is_string ())
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1425 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1426 return feval (val.string_value (), args, nargout);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1427 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1428 else
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1429 error ("feval: first argument must be a string, inline function, or a function handle");
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1430
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1431 return ovl ();
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1432 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1433
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1434 //! Evaluate an Octave function (built-in or interpreted) and return
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1435 //! the list of result values.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1436 //!
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1437 //! @param args The first element of @c args is the function to call.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1438 //! It may be the name of the function as a string, a function
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1439 //! handle, or an inline function. The remaining arguments are
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1440 //! passed to the function.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1441 //! @param nargout The number of output arguments expected.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1442 //! @return A list of output values. The length of the list is not
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1443 //! necessarily the same as @c nargout.
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1444
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1445 octave_value_list interpreter::feval (const octave_value_list& args,
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1446 int nargout)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1447 {
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1448 if (args.length () == 0)
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1449 error ("feval: first argument must be a string, inline function, or a function handle");
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1450
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1451 octave_value f_arg = args(0);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1452
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1453 octave_value_list tmp_args = args.slice (1, args.length () - 1, true);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1454
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1455 return feval (f_arg, tmp_args, nargout);
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1456 }
30e9204de313 move feval functions to interpreter class
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
1457
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1458 void interpreter::install_variable (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1459 const octave_value& value, bool global)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1460 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1461 m_evaluator.install_variable (name, value, global);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1462 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1463
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1464 octave_value interpreter::global_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1465 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1466 return m_evaluator.global_varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1467 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1468
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1469 void interpreter::global_assign (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1470 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1471 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1472 m_evaluator.global_assign (name, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1473 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1474
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1475 octave_value interpreter::top_level_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1476 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1477 return m_evaluator.top_level_varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1478 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1479
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1480 void interpreter::top_level_assign (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1481 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1482 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1483 m_evaluator.top_level_assign (name, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1484 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1485
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1486 bool interpreter::is_variable (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1487 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1488 return m_evaluator.is_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1489 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1490
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1491 bool interpreter::is_local_variable (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1492 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1493 return m_evaluator.is_local_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1494 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1495
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1496 octave_value interpreter::varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1497 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1498 return m_evaluator.varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1499 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1500
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1501 void interpreter::assign (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1502 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1503 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1504 m_evaluator.assign (name, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1505 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1506
27014
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1507 void interpreter::assignin (const std::string& context,
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1508 const std::string& name,
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1509 const octave_value& val)
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1510 {
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1511 m_evaluator.assignin (context, name, val);
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1512 }
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1513
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1514 void interpreter::source_file (const std::string& file_name,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1515 const std::string& context, bool verbose,
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27506
diff changeset
1516 bool require_file)
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1517 {
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27506
diff changeset
1518 m_evaluator.source_file (file_name, context, verbose, require_file);
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1519 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1520
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1521 bool interpreter::at_top_level (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1522 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1523 return m_evaluator.at_top_level ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1524 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1525
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1526 bool interpreter::isglobal (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1527 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1528 return m_evaluator.is_global (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1529 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1530
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1531 octave_value interpreter::find (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1532 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1533 return m_evaluator.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1534 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1535
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1536 void interpreter::clear_all (bool force)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1537 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1538 m_evaluator.clear_all (force);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1539 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1540
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1541 void interpreter::clear_objects (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1542 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1543 m_evaluator.clear_objects ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1544 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1545
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1546 void interpreter::clear_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1547 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1548 m_evaluator.clear_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1549 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1550
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1551 void interpreter::clear_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1552 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1553 m_evaluator.clear_variable_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1554 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1555
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1556 void interpreter::clear_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1557 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1558 m_evaluator.clear_variable_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1559 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1560
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1561 void interpreter::clear_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1562 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1563 m_evaluator.clear_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1564 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1565
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1566 void interpreter::clear_global_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1567 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1568 m_evaluator.clear_global_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1569 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1570
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1571 void interpreter::clear_global_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1572 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1573 m_evaluator.clear_global_variable_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1574 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1575
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1576 void interpreter::clear_global_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1577 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1578 m_evaluator.clear_global_variable_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1579 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1580
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1581 void interpreter::clear_global_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1582 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1583 m_evaluator.clear_global_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1584 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1585
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1586 void interpreter::clear_functions (bool force)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1587 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1588 m_symbol_table.clear_functions (force);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1589 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1590
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1591 void interpreter::clear_function (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1592 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1593 m_symbol_table.clear_function (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1594 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1595
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1596 void interpreter::clear_symbol (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1597 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1598 m_evaluator.clear_symbol (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1599 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1600
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1601 void interpreter::clear_function_pattern (const std::string& pat)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1602 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1603 m_symbol_table.clear_function_pattern (pat);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1604 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1605
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1606 void interpreter::clear_function_regexp (const std::string& pat)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1607 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1608 m_symbol_table.clear_function_regexp (pat);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1609 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1610
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1611 void interpreter::clear_symbol_pattern (const std::string& pat)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1612 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1613 return m_evaluator.clear_symbol_pattern (pat);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1614 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1615
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1616 void interpreter::clear_symbol_regexp (const std::string& pat)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1617 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1618 return m_evaluator.clear_symbol_regexp (pat);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1619 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1620
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1621 std::list<std::string> interpreter::global_variable_names (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1622 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1623 return m_evaluator.global_variable_names ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1624 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1625
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1626 std::list<std::string> interpreter::variable_names (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1627 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1628 return m_evaluator.variable_names ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1629 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1630
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1631 std::list<std::string> interpreter::user_function_names (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1632 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1633 return m_symbol_table.user_function_names ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1634 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1635
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1636 std::list<std::string> interpreter::autoloaded_functions (void) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1637 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1638 return m_evaluator.autoloaded_functions ();
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1639 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1640
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1641 void interpreter::handle_exception (const execution_exception& e)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1642 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1643 m_error_system.save_exception (e);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1644
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1645 // FIXME: use a separate stream instad of std::cerr directly so that
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1646 // error messages can be redirected more easily? Pass the message
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1647 // to an event manager function?
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1648 m_error_system.display_exception (e, std::cerr);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1649
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1650 recover_from_exception ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1651 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1652
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1653 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
1654 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1655 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
1656 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
1657 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
1658 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
1659 catch_interrupts ();
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1660 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1661
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1662 // 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
1663
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1664 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
1665
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1666 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
1667 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1668 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
1669 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1670
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1671 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
1672 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1673 bool found = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1674
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1675 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
1676 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
1677 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1678 if (*it == fname)
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1679 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1680 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
1681 found = true;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1682 break;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1683 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1684 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1685
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1686 return found;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1687 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1688
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1689 // What internal options get configured by --traditional.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1690
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1691 void interpreter::maximum_braindamage (void)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1692 {
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1693 m_input_system.PS1 (">> ");
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1694 m_input_system.PS2 ("");
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1695
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1696 m_evaluator.PS4 ("");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1697
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1698 m_load_save_system.crash_dumps_octave_core (false);
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1699 m_load_save_system.save_default_options ("-mat-binary");
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1700
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1701 m_history_system.timestamp_format_string ("%%-- %D %I:%M %p --%%");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1702
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1703 m_error_system.beep_on_error (true);
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1704 Fconfirm_recursive_rmdir (octave_value (false));
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
1705
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1706 Fdisable_diagonal_matrix (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1707 Fdisable_permutation_matrix (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1708 Fdisable_range (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1709 Ffixed_point_format (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1710 Fprint_empty_dimensions (octave_value (false));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1711 Fstruct_levels_to_print (octave_value (0));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1712
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1713 disable_warning ("Octave:abbreviated-property-match");
27517
85ad4689aa05 Add warning when non-scalar argument presented to ':' range operator.
Rik <rik@octave.org>
parents: 27509
diff changeset
1714 disable_warning ("Octave:colon-nonscalar-argument");
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1715 disable_warning ("Octave:data-file-in-path");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1716 disable_warning ("Octave:function-name-clash");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1717 disable_warning ("Octave:possible-matlab-short-circuit-operator");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1718 }
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1719
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1720 void interpreter::execute_pkg_add (const std::string& dir)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1721 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1722 try
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1723 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1724 m_load_path.execute_pkg_add (dir);
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1725 }
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27020
diff changeset
1726 catch (const interrupt_exception&)
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1727 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
1728 recover_from_exception ();
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1729 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1730 catch (const execution_exception& e)
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1731 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27409
diff changeset
1732 handle_exception (e);
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1733 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1734 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1735 }