annotate libinterp/corefcn/interpreter.cc @ 27017:24b7e6326e26

move parse_fcn_file to interpreter; source_file to evaluator * interpreter.h, interpreter.cc (interpreter::parse_fcn_file): Move function here from file-scope static function in oct-parse.yy. * pt-eval.h, pt-eval.cc (tree_evaluator::source_file): Move function here from oct-parse.yy. Change all uses.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Apr 2019 12:11:33 +0000
parents 9b261300a001
children a20ead51515d
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"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "file-stat.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #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
36 #include "lo-blas-proto.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "lo-error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "oct-env.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "str-vec.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "signal-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "unistd-wrappers.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
23711
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
43 #include "builtin-defun-decls.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "defaults.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "Cell.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
46 #include "call-stack.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "defun.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "display.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "error.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "file-io.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "graphics.h"
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
52 #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
53 #include "input.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
54 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 #include "interpreter.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 #include "load-path.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 #include "load-save.h"
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 #include "octave-link.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
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 DEFUN (quit, args, ,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 doc: /* -*- texinfo -*-
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.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 if (! octave_link::confirm_shutdown ())
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 if (! quit_allowed)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 error ("quit: not supported in embedded mode");
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 int exit_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 if (args.length () > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 exit_status = args(0).nint_value ();
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 // 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
166 // 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
167 // 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
168 // etc. before exiting.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
170 throw octave::exit_exception (exit_status);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 return ovl ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 DEFALIAS (exit, quit);
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 DEFUN (atexit, args, nargout,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 doc: /* -*- texinfo -*-
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 @deftypefn {} {} atexit (@var{fcn})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 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
182
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 For example,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 @group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 function last_words ()
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 disp ("Bye bye");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 endfunction
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 atexit ("last_words");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 @end group
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 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
196
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 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
198 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
199 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
200 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
201 above,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 @example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 atexit ("last_words", false);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 @end example
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 @noindent
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 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
209 @code{last_words} when it exits.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 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
212 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
213 @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
214 @seealso{quit}
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 @end deftypefn */)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 int nargin = args.length ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 if (nargin < 1 || nargin > 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 print_usage ();
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 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
223
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 bool add_mode = (nargin == 2)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 ? 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
226 : true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 octave_value_list retval;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 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
231 octave::interpreter::add_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
234 bool found = octave::interpreter::remove_atexit_function (arg);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 if (nargout > 0)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 retval = ovl (found);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 return retval;
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 namespace octave
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 {
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
245 // 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
246 // 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
247 // 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
248 // toplev.cc.
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
249
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
250 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
251 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
252 bool verbose = false,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
253 bool require_file = true,
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
254 const std::string& warn_for = "")
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
255 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
256 try
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
257 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
258 source_file (file_name, context, verbose, require_file, warn_for);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
259 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
260 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
261 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
262 interpreter::recover_from_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
263
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
264 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
265 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
266 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
267 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
268 std::string stack_trace = e.info ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
269
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
270 if (! stack_trace.empty ())
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
271 std::cerr << stack_trace;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
272
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
273 interpreter::recover_from_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
274
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
275 return 1;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
276 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
277
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
278 return 0;
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
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
281 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
282 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
283 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
284
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
285 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
286 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
287 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
288 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
289
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
290 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
291 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
292
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
293 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
294 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
295 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
296 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
297
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
298 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
299 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
300 // 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
301 // 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
302 // 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
303 // 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
304 // 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
305 // 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
306
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
307 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
308 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
309
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
310 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
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 (*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
313
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
314 dynamic_library libs ("");
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 if (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 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
319 = 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
320 (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
321
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
322 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
323 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
324 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
325 }
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 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
328 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
329 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
330 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
331 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
332 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
333 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
334
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
335 octave_throw_execution_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
336 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
337
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
338 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
339 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
340 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
341 va_list args;
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
342 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
343 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
344 va_end (args);
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
345
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
346 octave_throw_execution_exception ();
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
347 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
348
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
349 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
350 {
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
351 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
352 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
353 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
354 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
355 }
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
356
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
357 // 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
358 // 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
359 // path.
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
360
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
361 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
362 : m_app_context (app_context),
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
363 m_environment (),
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
364 m_settings (),
23721
b2d55b52ee51 new class to manage help system and associated variables
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
365 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
366 m_input_system (*this),
25435
a52e6fb674b1 eliminate some singletons and static & global variables
John W. Eaton <jwe@octave.org>
parents: 25407
diff changeset
367 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
368 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
369 m_dynamic_loader (*this),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
370 m_load_path (),
25993
f75bb9d659e0 eliminate global and file-scope static variables from load-save.cc (bug #54571)
John W. Eaton <jwe@octave.org>
parents: 25488
diff changeset
371 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
372 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
373 m_symbol_table (*this),
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
374 m_evaluator (*this),
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
375 m_stream_list (*this),
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24727
diff changeset
376 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
377 m_url_handle_manager (),
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23630
diff changeset
378 m_cdef_manager (*this),
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
379 m_gtk_manager (),
23627
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
380 m_interactive (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
381 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
382 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
383 m_verbose (false),
0a6e87804cab don't use singleton pattern for dynamic_loader class
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
384 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
385 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
386 m_history_initialized (false),
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
387 m_initialized (false)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 {
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
389 // 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
390 // should change to say something like
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
391 //
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
392 // 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
393
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
394 if (instance)
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
395 throw std::runtime_error
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
396 ("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
397
23511
232c8d69d934 manage interpreter instance in interpreter object
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
398 instance = this;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 setlocale (LC_NUMERIC, "C");
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402 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
403 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
404 sys::env::putenv ("LC_TIME", "C");
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406 // 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
407 octave_set_default_fpucw ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
409 thread::init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
410
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 // Initialize default warning state before --traditional option
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412 // that may reset them.
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_default_warning_state ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
416 octave_ieee_init ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417
25487
fbc270aeb55d * interpreter.cc (intialize_xerbla_error_handler, xerbla_abort): New functions.
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
418 initialize_xerbla_error_handler ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 initialize_error_handlers ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
422 if (m_app_context)
26826
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
423 {
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
424 install_signal_handlers ();
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
425 octave_unblock_signal_by_name ("SIGTSTP");
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26722
diff changeset
426 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 else
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 quit_allowed = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
430 bool line_editing = false;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
431 bool traditional = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
433 if (m_app_context)
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
434 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
435 // 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
436 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
437
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
438 // 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
439 // including PKG_ADD files.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
441 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
442
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
443 m_app_context->intern_argv (args);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
444 intern_nargin (args.numel () - 1);
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
445
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
446 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
447
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
448 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
449
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
450 for (const auto& pth : command_line_path)
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
451 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
452
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
453 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
454 if (! exec_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
455 m_environment.exec_path (exec_path);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
457 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
458 if (! image_path.empty ())
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
459 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
460
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
461 if (options.no_window_system ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
462 display_info::no_window_system ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
463
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
464 // 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
465 // interactive.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
466
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
467 // 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
468 // pipe or a redirected file.
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
469 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
470
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
471 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
472 && octave_isatty_wrapper (fileno (stdout)));
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
473
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
474 // 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
475 if (options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
476 m_interactive = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
478 line_editing = options.line_editing ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
479 if ((! m_interactive || options.forced_interactive ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
480 && ! options.forced_line_editing ())
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
481 line_editing = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
482
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
483 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
484
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
485 // 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
486 // 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
487
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
488 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
489 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
490 (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
491 | 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
492
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
493 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
494 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
495 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
496
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
497 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
498 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
499 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
500
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
501 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
502 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
503 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
504
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
505 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
506 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
507 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
508
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
509 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
510 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
511
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
512 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
513 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
514
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
515 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
516 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
517 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
518 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
520 m_input_system.initialize (line_editing);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522 // 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
523 // 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
524
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525 initialize_version_info ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
527 // 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
528 // 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
529
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
530 if (traditional)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
531 maximum_braindamage ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
533 octave_interpreter_ready = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535
24538
2b273df71aa0 allow experimenting with thread_local storage
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
536 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
537
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
538 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
539 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
540 cleanup ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
541 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
542
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
543 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
544 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
545 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
546 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22186
diff changeset
547
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
548 // 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
549
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
550 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
551 {
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
552 if (! m_history_initialized)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
553 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
554 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
556 if (m_app_context)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
557 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
558 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
559
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
560 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
561
5a97aafb12a9 don't call built-in interpreter functions from the application context
John W. Eaton <jwe@octave.org>
parents: 23703
diff changeset
562 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
563 command_history::ignore_entries ();
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
564 }
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
565
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
566 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
567
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
568 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
569 command_history::ignore_entries ();
23117
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 m_history_initialized = true;
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
572 }
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
573 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
575 // 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
576 // option says to leave it empty.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
577
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
578 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
579 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
580 if (! m_load_path_initialized)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
581 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
582 // Allow command-line option to override.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
584 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
585 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
586 const cmdline_options& options = m_app_context->options ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
587
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
588 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
589 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
590
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
591 // 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
592 // 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
593 // 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
594 // 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
595 // 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
596 // 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
597 // 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
598 // are already handled.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
599
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
600 unwind_protect frame;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
601
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
602 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
603 m_load_path.get_add_hook ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
604
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
605 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
606 { this->execute_pkg_add (dir); });
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
607
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
608 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
609
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
610 m_load_path_initialized = true;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
611 }
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
612 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
614 // 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
615
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
616 void interpreter::initialize (void)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
617 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
618 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
619 return;
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
620
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
621 display_startup_message ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
622
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
623 // 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
624 // files and begins evaluating commands.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
625
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
626 initialize_history ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
627
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
628 // 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
629 // 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
630
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
631 // 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
632 // 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
633 // 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
634
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
635 initialize_load_path ();
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 m_initialized = true;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
638 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
639
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
640 // 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
641 // we enforce that restriction?
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
642
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
643 int interpreter::execute (void)
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
644 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
645 try
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
646 {
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
647 initialize ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
648
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
649 // We ignore errors in startup files.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
650
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
651 execute_startup_files ();
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
652
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
653 int exit_status = 0;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
654
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
655 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
656 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
657 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
658
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
659 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
660 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
661 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
662
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
663 if (status )
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
664 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
665
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
666 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
667 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
668 }
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
669
23819
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
670 // 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
671 // 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
672 // for the script.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
673
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
674 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
675 {
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
676 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
677
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
678 if (status)
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
679 exit_status = status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
680
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
681 if (! options.persist ())
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
682 return exit_status;
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
683 }
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 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
686 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
687 }
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 // Avoid counting commands executed from startup or script files.
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
690
5d8ef9b859f8 defer execution of user code to interpreter::execute (bug #51631)
John W. Eaton <jwe@octave.org>
parents: 23795
diff changeset
691 command_editor::reset_current_command_number (1);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
692
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
693 return main_loop ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
694 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
695 catch (const exit_exception& ex)
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
696 {
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
697 return ex.exit_status ();
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
698 }
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
699 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
700
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
701 void interpreter::display_startup_message (void) const
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
702 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
703 bool inhibit_startup_message = false;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
704
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
705 if (m_app_context)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
706 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
707 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
708
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
709 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
710 }
23396
945b53af4655 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
711
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
712 if (m_interactive && ! inhibit_startup_message)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
713 std::cout << octave_startup_message () << "\n" << std::endl;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
714 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
715
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
716 // 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
717 // 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
718 // exception.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
719
26722
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
720 int interpreter::execute_startup_files (void)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
721 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
722 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
723 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
724 bool verbose = m_verbose;
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
725 bool inhibit_startup_message = m_inhibit_startup_message;
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
726
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
727 if (m_app_context)
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
728 {
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
729 const cmdline_options& options = m_app_context->options ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
730
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
731 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
732 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
733 verbose = options.verbose_flag ();
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
734 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
735 }
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 verbose = (verbose && ! inhibit_startup_message);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
738
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
739 bool require_file = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
740
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
741 std::string context;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
742
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
743 int exit_status = 0;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
744
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
745 if (read_site_files)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
746 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
747 // Execute commands from the site-wide configuration file.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
748 // First from the file $(prefix)/lib/octave/site/m/octaverc
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
749 // (if it exists), then from the file
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
750 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
751
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
752 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
753 context, verbose, require_file);
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
755 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
756 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
757
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23712
diff changeset
758 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
759 context, verbose, require_file);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
760
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
761 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
762 exit_status = status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
763 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
765 if (read_init_files)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
766 {
26722
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
767 // 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
768 // 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
769 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
770
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
771 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
772 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
773 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
774
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
775 try
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
776 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
777 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
778 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
779 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
780 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
781 recover_from_exception ();
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
782 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
783 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
784 {
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
785 std::string stack_trace = e.info ();
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
786
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
787 if (! stack_trace.empty ())
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
788 std::cerr << stack_trace;
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
789
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
790 recover_from_exception ();
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
791 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
792 }
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
793
f51e8a7c33f4 run Matlab user files from interpreter, not startup scripts (bug #55681)
Mike Miller <mtmiller@octave.org>
parents: 26661
diff changeset
794 // 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
795 // 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
796 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
797
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
798 // Try to execute commands from $HOME/$OCTAVE_INITFILE and
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
799 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
800 // .octaverc is assumed.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
801
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
802 bool home_rc_already_executed = false;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
803
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
804 std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
805
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
806 if (initfile.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
807 initfile = ".octaverc";
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
808
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
809 std::string home_dir = sys::env::get_home_directory ();
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
810
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
811 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
812
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
813 std::string local_rc;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
814
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
815 if (! home_rc.empty ())
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
816 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
817 int status = safe_source_file (home_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
818 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
819
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
820 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
821 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
822
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
823 // Names alone are not enough.
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
824
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
825 sys::file_stat fs_home_rc (home_rc);
23102
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 if (fs_home_rc)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
828 {
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
829 // 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
830 // because doing that may change the working directory.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
831
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
832 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
833
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
834 home_rc_already_executed = same_file (home_rc, local_rc);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
835 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
836 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
837
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
838 if (! home_rc_already_executed)
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 (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
841 local_rc = sys::env::make_absolute (initfile);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
842
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
843 int status = safe_source_file (local_rc, context, verbose,
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
844 require_file);
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
845
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
846 if (status)
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
847 exit_status = status;
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
848 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
849 }
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
850
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
851 if (m_interactive && verbose)
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
852 std::cout << std::endl;
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 return exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
855 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
856
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
857 // Execute any code specified with --eval 'CODE'
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 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
860 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
861 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
862
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
863 std::string code_to_eval = options.code_to_eval ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
864
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
865 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
866
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
867 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
868
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
869 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
870
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
871 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
872 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
873 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
875 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
876
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
877 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
878
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879 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
880
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
883 int parse_status = 0;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
884
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
885 try
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
886 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
887 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
888 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
889 catch (const interrupt_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
890 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
891 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
893 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
894 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
895 catch (const execution_exception&)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
896 {
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 recover_from_exception ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
899 return 1;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
900 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
901
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
902 return parse_status;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
904
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
905 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
906 {
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
907 const cmdline_options& options = m_app_context->options ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
908
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
909 unwind_protect frame;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
911 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
912
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
913 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
914
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
915 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
916 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
917 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
919 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
920
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
921 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
922
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
923 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
924
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
925 string_vector args = options.all_args ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
926
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
927 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
928
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
929 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
930
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
931 frame.add_method (m_app_context,
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
932 &application::program_invocation_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
933 application::program_invocation_name ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
934
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
935 frame.add_method (m_app_context,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
936 &application::program_name,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
937 application::program_name ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
938
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939 m_interactive = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
941 // If we are running an executable script (#! /bin/octave) then
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
942 // we should only see the args passed to the script.
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
943
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
944 string_vector script_args = options.remaining_args ();
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
945
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
946 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
947 intern_nargin (script_args.numel () - 1);
23102
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
948
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
949 std::string fname = script_args[0];
373771419d51 refactor interpreter::execute
John W. Eaton <jwe@octave.org>
parents: 23100
diff changeset
950
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
951 m_app_context->set_program_names (fname);
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
952
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
953 std::string context;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
954 bool verbose = false;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
955 bool require_file = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
957 return safe_source_file (fname, context, verbose, require_file, "octave");
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958 }
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 int interpreter::main_loop (void)
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961 {
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
962 if (! m_app_context)
23104
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
963 return 0;
2805cc365a86 fix thinko in previous change
John W. Eaton <jwe@octave.org>
parents: 23102
diff changeset
964
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
965 octave_save_signal_mask ();
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
966
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
967 can_interrupt = true;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
968
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24361
diff changeset
969 octave_signal_hook = respond_to_pending_signals;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
970 octave_interrupt_hook = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23775
diff changeset
971 octave_bad_alloc_hook = nullptr;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
972
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
973 catch_interrupts ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
974
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
975 octave_initialized = true;
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
976
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
977 // The big loop.
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
978
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
979 return m_evaluator.repl (application::interactive ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
980 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
981
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
982 // 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
983 // errors while shutting down.
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
984
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
985 #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
986 catch (E) \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
987 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
988 recover_from_exception (); \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
989 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
990 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
991 << std::endl; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
992 }
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
993
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
994 #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
995 do \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
996 { \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
997 try \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
998 { \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
999 unwind_protect frame; \
23106
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1000 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1001 frame.protect_var (Vdebug_on_error); \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1002 frame.protect_var (Vdebug_on_warning); \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1003 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1004 Vdebug_on_error = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1005 Vdebug_on_warning = false; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1006 \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1007 F ARGS; \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1008 } \
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1009 OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1010 OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1011 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
1012 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
1013 } \
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1014 while (0)
1a53f9d42ec1 move OCTAVE_SAFE_CALL macro out of header file
John W. Eaton <jwe@octave.org>
parents: 23105
diff changeset
1015
23087
9f406f0b36da rework clean_up_and_exit (bug #50068)
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
1016 void interpreter::cleanup (void)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017 {
23092
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1018 // If we are attached to a GUI, process pending events and
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1019 // disconnect the link.
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1020
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1021 octave_link::process_events (true);
0fed4c678795 additional restructuring of startup and shutdown
John W. Eaton <jwe@octave.org>
parents: 23087
diff changeset
1022 octave_link::disconnect_link ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1023
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1024 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
1025
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1026 while (! atexit_functions.empty ())
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1027 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1028 std::string fcn = atexit_functions.front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1029
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1030 atexit_functions.pop_front ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1031
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032 OCTAVE_SAFE_CALL (reset_error_handler, ());
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1033
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1034 OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0));
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1036 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1037 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1038
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1039 // 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
1040 // 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
1041 // called.
23699
b29904962d2d deprecate some global functions that access the symbol table
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
1042 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
1043
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1044 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
1045
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1046 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
1047
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1048 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
1049 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
1050
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1051 OCTAVE_SAFE_CALL (gh_manager::close_all_figures, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1052
23774
41795b504a8b don't use singleton for gtk_manager
John W. Eaton <jwe@octave.org>
parents: 23753
diff changeset
1053 m_gtk_manager.unload_all_toolkits ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1054
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1055 OCTAVE_SAFE_CALL (cleanup_tmp_files, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1056
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
1057 // 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
1058 // 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
1059 // 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
1060 m_symbol_table.cleanup ();
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1061
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1062 OCTAVE_SAFE_CALL (sysdep_cleanup, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1063
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1064 OCTAVE_SAFE_CALL (flush_stdout, ());
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1065
23117
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1066 // 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
1067 // 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
1068 // 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
1069 // 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
1070 // 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
1071 // 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
1072 // 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
1073 // .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
1074 // is unloaded.
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1075 //
17a3567a7b01 separate final interpreter initialization from execution
John W. Eaton <jwe@octave.org>
parents: 23111
diff changeset
1076 // 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
1077 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1078
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1079 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
1080 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1081 return m_evaluator;
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23511
diff changeset
1082 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1084 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
1085 {
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1086 return m_stream_list;
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1087 }
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
1088
23742
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1089 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
1090 {
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1091 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
1092 }
1f0daaf81955 don't use singleton for ch_manager, rename to url_handle_manager
John W. Eaton <jwe@octave.org>
parents: 23738
diff changeset
1093
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1094 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
1095 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
1096 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1097 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
1098 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1099
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1100 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
1101 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
1102 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1103 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
1104 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1105
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1106 symbol_scope
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1107 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
1108 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1109 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
1110
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1111 if (! scope)
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1112 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
1113
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1114 return scope;
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1115 }
99989ab8f142 new convenience functions for accessing current scope
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1116
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1117 call_stack& interpreter::get_call_stack (void)
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1118 {
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23627
diff changeset
1119 return m_evaluator.get_call_stack ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1120 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23552
diff changeset
1121
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1122 profiler& interpreter::get_profiler (void)
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1123 {
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1124 return m_evaluator.get_profiler ();
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1125 }
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23742
diff changeset
1126
23703
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1127 void interpreter::mlock (void)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1128 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1129 call_stack& cs = get_call_stack ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1130
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1131 octave_function *fcn = cs.current ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1132
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1133 if (! fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1134 error ("mlock: invalid use outside a function");
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1135
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1136 fcn->lock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1137 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1138
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1139 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
1140 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1141 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
1142
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1143 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1144 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1145 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
1146
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1147 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1148 fcn->unlock ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1149 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1150 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1151
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1152 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
1153 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1154 bool retval = false;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1155
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1156 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
1157
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1158 if (val.is_defined ())
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1159 {
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1160 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
1161
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1162 if (fcn)
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1163 retval = fcn->islocked ();
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1164 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1165
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1166 return retval;
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1167 }
6eb5f6199a5a move mlock, munlock, and mislocked to interpreter class
John W. Eaton <jwe@octave.org>
parents: 23699
diff changeset
1168
27015
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1169 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
1170 {
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1171 return m_evaluator.mfilename (opt);
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1172 }
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
1173
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1174 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
1175 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1176 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1177 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1178 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
1179 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1180
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1181 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
1182 bool silent, int& parse_status)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1183 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1184 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
1185 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1186
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1187 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
1188 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1189 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1190 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1191 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
1192 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
1193
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1194 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
1195 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
1196 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1197 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
1198 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1199
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1200 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
1201 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1202 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
1203 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1204
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1205 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
1206 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
1207 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1208 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
1209 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1210
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1211 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
1212 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1213 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
1214 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1215
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1216 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
1217 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
1218 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1219 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
1220 }
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 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
1223 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1224 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
1225 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1226
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1227 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
1228 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1229 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
1230 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1231
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1232 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
1233 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1234 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
1235 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1236
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1237 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
1238 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
1239 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1240 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
1241 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1242
27014
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1243 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
1244 const std::string& name,
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1245 const octave_value& val)
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1246 {
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1247 m_evaluator.assignin (context, name, val);
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1248 }
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26826
diff changeset
1249
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1250 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
1251 const std::string& context, bool verbose,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1252 bool require_file,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1253 const std::string& warn_for)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1254 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1255 m_evaluator.source_file (file_name, context, verbose, require_file,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1256 warn_for);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1257 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1258
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1259 static void
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1260 safe_fclose (FILE *f)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1261 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1262 if (f)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1263 fclose (static_cast<FILE *> (f));
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1264 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1265
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1266 octave_value
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1267 interpreter::parse_fcn_file (const std::string& full_file,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1268 const std::string& file,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1269 const std::string& dir_name,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1270 const std::string& dispatch_type,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1271 const std::string& package_name,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1272 bool require_file,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1273 bool force_script, bool autoload,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1274 bool relative_lookup,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1275 const std::string& warn_for)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1276 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1277 octave_value retval;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1278
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1279 unwind_protect frame;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1280
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1281 octave_function *fcn_ptr = nullptr;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1282
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1283 // Open function file and parse.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1284
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1285 FILE *in_stream = command_editor::get_input_stream ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1286
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1287 frame.add_fcn (command_editor::set_input_stream, in_stream);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1288
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1289 frame.add_fcn (command_history::ignore_entries,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1290 command_history::ignoring_entries ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1291
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1292 command_history::ignore_entries ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1293
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1294 FILE *ffile = nullptr;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1295
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1296 if (! full_file.empty ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1297 ffile = sys::fopen (full_file, "rb");
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1298
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1299 if (ffile)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1300 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1301 frame.add_fcn (safe_fclose, ffile);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1302
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1303 parser parser (ffile, *this);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1304
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1305 parser.m_curr_class_name = dispatch_type;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1306 parser.m_curr_package_name = package_name;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1307 parser.m_autoloading = autoload;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1308 parser.m_fcn_file_from_relative_lookup = relative_lookup;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1309
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1310 parser.m_lexer.m_force_script = force_script;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1311 parser.m_lexer.prep_for_file ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1312 parser.m_lexer.m_parsing_class_method = ! dispatch_type.empty ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1313
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1314 parser.m_lexer.m_fcn_file_name = file;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1315 parser.m_lexer.m_fcn_file_full_name = full_file;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1316 parser.m_lexer.m_dir_name = dir_name;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1317 parser.m_lexer.m_package_name = package_name;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1318
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1319 int status = parser.run ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1320
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1321 fcn_ptr = parser.m_primary_fcn_ptr;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1322
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1323 if (status == 0)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1324 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1325 if (parser.m_lexer.m_reading_classdef_file
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1326 && parser.m_classdef_object)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1327 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1328 // Convert parse tree for classdef object to
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1329 // meta.class info (and stash it in the symbol
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1330 // table?). Return pointer to constructor?
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1331
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1332 if (fcn_ptr)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1333 panic_impossible ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1334
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1335 bool is_at_folder = ! dispatch_type.empty ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1336
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1337 try
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1338 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1339 fcn_ptr = parser.m_classdef_object->make_meta_class (*this, is_at_folder);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1340 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1341 catch (const execution_exception&)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1342 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1343 delete parser.m_classdef_object;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1344 throw;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1345 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1346
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1347 if (fcn_ptr)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1348 retval = octave_value (fcn_ptr);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1349
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1350 delete parser.m_classdef_object;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1351
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1352 parser.m_classdef_object = nullptr;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1353 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1354 else if (fcn_ptr)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1355 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1356 retval = octave_value (fcn_ptr);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1357
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1358 fcn_ptr->maybe_relocate_end ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1359
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1360 if (parser.m_parsing_subfunctions)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1361 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1362 if (! parser.m_endfunction_found)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1363 parser.m_subfunction_names.reverse ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1364
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1365 fcn_ptr->stash_subfunction_names (parser.m_subfunction_names);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1366 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1367 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1368 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1369 else
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1370 error ("parse error while reading file %s", full_file.c_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1371 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1372 else if (require_file)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1373 error ("no such file, '%s'", full_file.c_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1374 else if (! warn_for.empty ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1375 error ("%s: unable to open file '%s'", warn_for.c_str (),
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1376 full_file.c_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1377
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1378 return retval;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1379 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1380
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1381 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
1382 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1383 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
1384 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1385
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1386 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
1387 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1388 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
1389 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1390
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1391 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
1392 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1393 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
1394 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1395
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1396 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
1397 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1398 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
1399 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1400
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1401 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
1402 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1403 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
1404 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1405
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1406 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
1407 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1408 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
1409 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1410
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1411 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
1412 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1413 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
1414 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1415
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1416 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
1417 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1418 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
1419 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1420
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1421 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
1422 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1423 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
1424 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1425
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1426 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
1427 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1428 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
1429 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1430
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1431 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
1432 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1433 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
1434 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1435
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1436 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
1437 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1438 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
1439 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1440
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1441 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
1442 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1443 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
1444 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1445
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1446 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
1447 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1448 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
1449 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1450
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1451 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
1452 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1453 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
1454 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1455
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1456 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
1457 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1458 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
1459 }
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 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
1462 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1463 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
1464 }
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 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
1467 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1468 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
1469 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1470
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1471 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
1472 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1473 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
1474 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1475
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1476 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
1477 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1478 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
1479 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1480
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1481 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
1482 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1483 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
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 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
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.variable_names ();
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 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
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_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
1494 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1495
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1496 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
1497 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1498 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
1499 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
1500
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1501 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
1502 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23694
diff changeset
1503 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
1504 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
1505 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
1506 octave_exception_state = octave_no_exception;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1507 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
1508 catch_interrupts ();
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1509 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1510
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1511 // 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
1512
23111
252975fdc444 more refactoring of interpreter and application classes
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
1513 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
1514
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1515 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
1516 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1517 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
1518 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1519
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1520 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
1521 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1522 bool found = false;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1523
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1524 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
1525 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
1526 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1527 if (*it == fname)
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1528 {
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1529 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
1530 found = true;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1531 break;
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1532 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1533 }
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1534
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23109
diff changeset
1535 return found;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1536 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1537
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1538 // 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
1539
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1540 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
1541 {
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
1542 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
1543 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
1544
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1545 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
1546
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
1547 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
1548 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
1549
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25993
diff changeset
1550 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
1551
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1552 Fbeep_on_error (octave_value (true));
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1553 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
1554
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1555 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
1556 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
1557 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
1558 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
1559 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
1560 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
1561
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1562 disable_warning ("Octave:abbreviated-property-match");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23721
diff changeset
1563 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
1564 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
1565 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
1566 }
25345
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1567
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1568 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
1569 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1570 try
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1571 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1572 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
1573 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1574 catch (const octave::interrupt_exception&)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1575 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1576 octave::interpreter::recover_from_exception ();
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1577 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1578 catch (const octave::execution_exception&)
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1579 {
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1580 octave::interpreter::recover_from_exception ();
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1581 }
ce6f7a5cd68e avoid global access of load path in interpreter class
John W. Eaton <jwe@octave.org>
parents: 25184
diff changeset
1582 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1583 }