GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
interpreter-private.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2017-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <iostream>
31 #include <list>
32 #include <string>
33 
34 #include "bp-table.h"
35 #include "cdef-manager.h"
36 #include "child-list.h"
37 #include "display.h"
38 #include "error.h"
39 #include "event-manager.h"
40 #include "gtk-manager.h"
41 #include "help.h"
42 #include "input.h"
43 #include "interpreter-private.h"
44 #include "interpreter.h"
45 #include "load-path.h"
46 #include "load-save.h"
47 #include "ov.h"
48 #include "ovl.h"
49 #include "pager.h"
50 #include "symtab.h"
51 
53 
55 {
57 
58  if (! interp)
59  {
60  std::cerr << "fatal error: octave interpreter context missing" << std::endl;
61  abort ();
62  }
63 
64  return *interp;
65 }
66 
68 {
69  interpreter& interp = __get_interpreter__ ();
70 
71  return interp.get_dynamic_loader ();
72 }
73 
75 {
76  interpreter& interp = __get_interpreter__ ();
77 
78  return interp.get_error_system ();
79 }
80 
81 gh_manager& __get_gh_manager__ (void)
82 {
83  interpreter& interp = __get_interpreter__ ();
84 
85  return interp.get_gh_manager ();
86 }
87 
89 {
90  interpreter& interp = __get_interpreter__ ();
91 
92  return interp.get_help_system ();
93 }
94 
96 {
97  interpreter& interp = __get_interpreter__ ();
98 
99  return interp.get_input_system ();
100 }
101 
103 {
104  interpreter& interp = __get_interpreter__ ();
105 
106  return interp.get_output_system ();
107 }
108 
110 {
111  interpreter& interp = __get_interpreter__ ();
112 
113  return interp.get_load_path ();
114 }
115 
117 {
118  interpreter& interp = __get_interpreter__ ();
119 
120  return interp.get_load_save_system ();
121 }
122 
124 {
125  interpreter& interp = __get_interpreter__ ();
126 
127  return interp.get_event_manager ();
128 }
129 
131 {
132  interpreter& interp = __get_interpreter__ ();
133 
134  return interp.get_type_info ();
135 }
136 
138 {
139  interpreter& interp = __get_interpreter__ ();
140 
141  return interp.get_symbol_table ();
142 }
143 
145 {
146  interpreter& interp = __get_interpreter__ ();
147 
148  return interp.get_current_scope ();
149 }
150 
152 {
154 
155  if (! scope)
156  error ("__require_current_scope__: symbol table scope missing");
157 
158  return scope;
159 }
160 
162 {
163  interpreter& interp = __get_interpreter__ ();
164 
165  return interp.get_evaluator ();
166 }
167 
169 {
171 
172  return tw.get_bp_table ();
173 }
174 
176 {
177  interpreter& interp = __get_interpreter__ ();
178 
179  return interp.get_child_list ();
180 }
181 
183 {
184  interpreter& interp = __get_interpreter__ ();
185 
186  return interp.get_cdef_manager ();
187 }
188 
190 {
191  interpreter& interp = __get_interpreter__ ();
192 
193  return interp.get_display_info ();
194 }
195 
197 {
198  interpreter& interp = __get_interpreter__ ();
199 
200  return interp.get_gtk_manager ();
201 }
202 
205  const std::string& parameter_name)
206 {
207  std::list<std::string> parameter_names;
208  parameter_names.push_back (parameter_name);
209  return get_function_handle (interp, arg, parameter_names);
210 }
211 
212 // May return a function handle object, inline function object, or
213 // function object.
214 
217  const std::list<std::string>& parameter_names)
218 {
219  if (arg.is_function_handle () || arg.is_inline_function ())
220  return arg;
221  else if (arg.is_string ())
222  {
223  std::string fstr = arg.string_value ();
224 
225  if (fstr.empty ())
226  return octave_value ();
227 
228  symbol_table& symtab = interp.get_symbol_table ();
229 
230  octave_value fcn = symtab.find_function (fstr);
231 
232  if (fcn.is_defined ())
233  return fcn;
234 
235  // Possibly warn here that passing the function body in a
236  // character string is discouraged.
237 
238  octave_value_list args (parameter_names.size () + 1);
239  octave_idx_type i = 0;
240  args(i++) = fstr;
241  for (const auto& pname : parameter_names)
242  args(i++) = pname;
243 
244  octave_value_list tmp = interp.feval ("inline", args, 1);
245 
246  if (tmp.length () > 0)
247  return tmp(0);
248  }
249 
250  return octave_value ();
251 }
252 
OCTAVE_END_NAMESPACE(octave)
Provides threadsafe access to octave.
output_system & get_output_system(void)
Definition: interpreter.h:268
event_manager & get_event_manager(void)
Definition: interpreter.h:328
type_info & get_type_info(void)
Definition: interpreter.h:293
gh_manager & get_gh_manager(void)
Definition: interpreter.h:333
help_system & get_help_system(void)
Definition: interpreter.h:258
error_system & get_error_system(void)
Definition: interpreter.h:251
tree_evaluator & get_evaluator(void)
child_list & get_child_list(void)
Definition: interpreter.h:311
symbol_scope get_current_scope(void) const
dynamic_loader & get_dynamic_loader(void)
Definition: interpreter.h:278
static interpreter * the_interpreter(void)
Definition: interpreter.h:539
symbol_table & get_symbol_table(void)
Definition: interpreter.h:298
display_info & get_display_info(void)
Definition: interpreter.h:236
load_save_system & get_load_save_system(void)
Definition: interpreter.h:288
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
cdef_manager & get_cdef_manager(void)
Definition: interpreter.h:318
gtk_manager & get_gtk_manager(void)
Definition: interpreter.h:323
input_system & get_input_system(void)
Definition: interpreter.h:263
load_path & get_load_path(void)
Definition: interpreter.h:283
octave_idx_type length(void) const
Definition: ovl.h:113
bool is_string(void) const
Definition: ov.h:682
bool is_defined(void) const
Definition: ov.h:637
bool is_function_handle(void) const
Definition: ov.h:813
std::string string_value(bool force=false) const
Definition: ov.h:1019
bool is_inline_function(void) const
Definition: ov.h:819
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
Definition: symtab.cc:249
bp_table & get_bp_table(void)
Definition: pt-eval.h:429
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
gtk_manager & __get_gtk_manager__(void)
child_list & __get_child_list__(void)
bp_table & __get_bp_table__(void)
dynamic_loader & __get_dynamic_loader__(void)
error_system & __get_error_system__(void)
input_system & __get_input_system__(void)
load_save_system & __get_load_save_system__(void)
interpreter & __get_interpreter__(void)
load_path & __get_load_path__(void)
type_info & __get_type_info__(void)
symbol_scope __require_current_scope__(void)
output_system & __get_output_system__(void)
display_info & __get_display_info__(void)
event_manager & __get_event_manager__(void)
cdef_manager & __get_cdef_manager__(void)
gh_manager & __get_gh_manager__(void)
symbol_table & __get_symbol_table__(void)
symbol_scope __get_current_scope__(void)
tree_evaluator & __get_evaluator__(void)
help_system & __get_help_system__(void)
octave_value get_function_handle(interpreter &interp, const octave_value &arg, const std::string &parameter_name)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))