GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
interpreter.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2002-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_interpreter_h)
24 #define octave_interpreter_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include "child-list.h"
31 #include "quit.h"
32 #include "str-vec.h"
33 
34 #include "bp-table.h"
35 #include "dynamic-ld.h"
36 #include "environment.h"
37 #include "gtk-manager.h"
38 #include "help.h"
39 #include "load-path.h"
40 #include "oct-stream.h"
41 #include "ov-classdef.h"
42 #include "ov-typeinfo.h"
43 #include "pt-eval.h"
44 #include "symtab.h"
45 #include "url-handle-manager.h"
46 
47 extern OCTINTERP_API bool quit_allowed;
48 
49 // TRUE means we are ready to interpret commands, but not everything
50 // is ready for interactive use.
51 extern OCTINTERP_API bool octave_interpreter_ready;
52 
53 // TRUE means we've processed all the init code and we are good to go.
54 extern OCTINTERP_API bool octave_initialized;
55 
56 namespace octave
57 {
58  class profiler;
59  class call_stack;
60  class child_list;
61  class tree_evaluator;
62 
63  // The application object contains a pointer to the current
64  // interpreter and the interpreter contains a pointer back to the
65  // application context so we need a forward declaration for one (or
66  // both) of them...
67 
68  class application;
69 
70  class OCTINTERP_API interpreter
71  {
72  public:
73 
74  // Create an interpreter object and perform basic initialization.
75 
76  interpreter (application *app_context = nullptr);
77 
78  // No copying, at least not yet...
79 
80  interpreter (const interpreter&) = delete;
81 
82  interpreter& operator = (const interpreter&) = delete;
83 
84  // Clean up the interpreter object.
85 
86  ~interpreter (void);
87 
88  void intern_nargin (octave_idx_type nargs);
89 
90  // If creating an embedded interpreter, you may inhibit reading
91  // the command history file by calling initialize_history with
92  // read_history_file = false prior to calling initialize.
93 
94  void initialize_history (bool read_history_file = false);
95 
96  // If creating an embedded interpreter, you may inhibit setting
97  // the default compiled-in path by calling intialize_load_path
98  // with set_initial_path = false prior calling initialize. After
99  // that, you can add directories to the load path to set up a
100  // custom path.
101 
102  void initialize_load_path (bool set_initial_path = true);
103 
104  // Load command line history, set the load path.
105 
106  void initialize (void);
107 
108  // Initialize the interpreter (if not already done by an explicit
109  // call to intialize), execute startup files, --eval option code,
110  // script files, and/or interactive commands.
111 
112  int execute (void);
113 
114  bool interactive (void) const
115  {
116  return m_interactive;
117  }
118 
119  void interactive (bool arg)
120  {
121  m_interactive = arg;
122  }
123 
124  void read_site_files (bool flag)
125  {
126  m_read_site_files = flag;
127  }
128 
129  void read_init_files (bool flag)
130  {
131  m_read_init_files = flag;
132  }
133 
134  void verbose (bool flag)
135  {
136  m_verbose = flag;
137  }
138 
139  void inhibit_startup_message (bool flag)
140  {
141  m_inhibit_startup_message = flag;
142  }
143 
144  bool initialized (void) const
145  {
146  return m_initialized;
147  }
148 
150  {
151  return m_environment;
152  }
153 
155  {
156  return m_help_system;
157  }
158 
160  {
161  return m_dynamic_loader;
162  }
163 
165  {
166  return m_load_path;
167  }
168 
170  {
171  return m_symbol_table;
172  }
173 
175  {
176  return m_type_info;
177  }
178 
179  symbol_scope get_current_scope (void);
180  symbol_scope require_current_scope (const std::string& who);
181 
183  {
184  return m_bp_table;
185  }
186 
187  call_stack& get_call_stack (void);
188 
189  profiler& get_profiler (void);
190 
191  tree_evaluator& get_evaluator (void);
192 
193  stream_list& get_stream_list (void);
194 
196  {
197  return m_child_list;
198  }
199 
200  url_handle_manager& get_url_handle_manager (void);
201 
203  {
204  return m_cdef_manager;
205  }
206 
208  {
209  return m_gtk_manager;
210  }
211 
212  void mlock (void);
213 
214  void munlock (const std::string& nm);
215 
216  bool mislocked (const std::string& nm);
217 
218  static void recover_from_exception (void);
219 
220  static void add_atexit_function (const std::string& fname);
221 
222  static bool remove_atexit_function (const std::string& fname);
223 
224  static interpreter * the_interpreter (void) { return instance; }
225 
226  private:
227 
228  // The interpreter instance; Currently it is only possible to
229  // have one, so OCTAVE_THREAD_LOCAL will normally be defined to be
230  // empty. Eventually we would like to allow multiple interpreters
231  // to be active at once, but they will still be limited to one per
232  // thread. When that is possible, OCTAVE_THREAD_LOCAL can be
233  // replaced by the C++ thread_local keyword. For now, use a macro
234  // to allow experimenting with thread_local storage.
235 
236  OCTAVE_THREAD_LOCAL static interpreter *instance;
237 
238  static std::list<std::string> atexit_functions;
239 
240  void display_startup_message (void) const;
241 
242  int execute_startup_files (void) const;
243 
244  int execute_eval_option_code (void);
245 
246  int execute_command_line_file (void);
247 
248  int main_loop (void);
249 
250  void cleanup (void);
251 
253 
255 
257 
259 
261 
263 
265 
267 
269 
271 
273 
275 
277 
279 
280  // TRUE means this is an interactive interpreter (forced or not).
282 
284 
286 
287  bool m_verbose;
288 
290 
292 
294 
296 
297  void maximum_braindamage (void);
298  };
299 }
300 
301 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
302 
303 OCTAVE_DEPRECATED (4.4, "use 'octave::interpreter::recover_from_exception' instead")
304 static inline void
305 recover_from_exception (void)
306 {
308 }
309 
310 OCTAVE_DEPRECATED (4.4, "use 'octave::interpreter::add_atexit_function' instead")
311 static inline void
312 add_atexit_function (const std::string& fname)
313 {
315 }
316 
317 OCTAVE_DEPRECATED (4.4, "use 'octave::interpreter::remove_atexit_function' instead")
318 static inline bool
319 remove_atexit_function (const std::string& fname)
320 {
322 }
323 
324 #endif
325 
326 #endif
help_system & get_help_system(void)
Definition: interpreter.h:154
load_path m_load_path
Definition: interpreter.h:260
stream_list m_stream_list
Definition: interpreter.h:270
OCTINTERP_API bool octave_interpreter_ready
Definition: interpreter.cc:81
fname
Definition: load-save.cc:767
static std::list< std::string > atexit_functions
Definition: interpreter.h:238
static void recover_from_exception(void)
bp_table & get_bp_table(void)
Definition: interpreter.h:182
child_list & get_child_list(void)
Definition: interpreter.h:195
help_system m_help_system
Definition: interpreter.h:256
STL namespace.
symbol_table m_symbol_table
Definition: interpreter.h:264
environment & get_environment(void)
Definition: interpreter.h:149
type_info m_type_info
Definition: interpreter.h:262
type_info & get_type_info(void)
Definition: interpreter.h:174
OCTINTERP_API bool octave_initialized
Definition: interpreter.cc:84
octave_value arg
Definition: pr-output.cc:3244
static interpreter * the_interpreter(void)
Definition: interpreter.h:224
void initialize_history(bool read_history_file)
Definition: oct-hist.cc:532
static void initialize(void)
void read_init_files(bool flag)
Definition: interpreter.h:129
void inhibit_startup_message(bool flag)
Definition: interpreter.h:139
gtk_manager & get_gtk_manager(void)
Definition: interpreter.h:207
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
bool interactive(void) const
Definition: interpreter.h:114
load_path & get_load_path(void)
Definition: interpreter.h:164
OCTINTERP_API bool mislocked(const std::string &)
static OCTAVE_THREAD_LOCAL interpreter * instance
Definition: interpreter.h:236
gtk_manager m_gtk_manager
Definition: interpreter.h:278
void read_site_files(bool flag)
Definition: interpreter.h:124
OCTINTERP_API bool quit_allowed
Definition: interpreter.cc:77
cdef_manager m_cdef_manager
Definition: interpreter.h:276
OCTINTERP_API void munlock(const std::string &)
bool m_inhibit_startup_message
Definition: interpreter.h:289
void verbose(bool flag)
Definition: interpreter.h:134
symbol_table & get_symbol_table(void)
Definition: interpreter.h:169
dynamic_loader m_dynamic_loader
Definition: interpreter.h:258
cdef_manager & get_cdef_manager(void)
Definition: interpreter.h:202
static void add_atexit_function(const std::string &fname)
application * m_app_context
Definition: interpreter.h:252
static bool remove_atexit_function(const std::string &fname)
url_handle_manager m_url_handle_manager
Definition: interpreter.h:274
child_list m_child_list
Definition: interpreter.h:272
bool initialized(void) const
Definition: interpreter.h:144
dynamic_loader & get_dynamic_loader(void)
Definition: interpreter.h:159
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
environment m_environment
Definition: interpreter.h:254
void interactive(bool arg)
Definition: interpreter.h:119
tree_evaluator m_evaluator
Definition: interpreter.h:266
OCTINTERP_API void mlock(void)