GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
interpreter-private.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2017-2025 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
69{
71
72 return interp.get_dynamic_loader ();
73}
74
77{
79
80 return interp.get_error_system ();
81}
82
85{
87
88 return interp.get_gh_manager ();
89}
90
93{
95
96 return interp.get_help_system ();
97}
98
101{
102 interpreter& interp = __get_interpreter__ ();
103
104 return interp.get_input_system ();
105}
106
109{
110 interpreter& interp = __get_interpreter__ ();
111
112 return interp.get_output_system ();
113}
114
117{
118 interpreter& interp = __get_interpreter__ ();
119
120 return interp.get_load_path ();
121}
122
125{
126 interpreter& interp = __get_interpreter__ ();
127
128 return interp.get_load_save_system ();
129}
130
133{
134 interpreter& interp = __get_interpreter__ ();
135
136 return interp.get_event_manager ();
137}
138
141{
142 interpreter& interp = __get_interpreter__ ();
143
144 return interp.get_type_info ();
145}
146
149{
150 interpreter& interp = __get_interpreter__ ();
151
152 return interp.get_symbol_table ();
153}
154
157{
158 interpreter& interp = __get_interpreter__ ();
159
160 return interp.get_current_scope ();
161}
162
165{
167
168 if (! scope)
169 error ("__require_current_scope__: symbol table scope missing");
170
171 return scope;
172}
173
176{
177 interpreter& interp = __get_interpreter__ ();
178
179 return interp.get_evaluator ();
180}
181
184{
186
187 return tw.get_bp_table ();
188}
189
192{
193 interpreter& interp = __get_interpreter__ ();
194
195 return interp.get_child_list ();
196}
197
200{
201 interpreter& interp = __get_interpreter__ ();
202
203 return interp.get_cdef_manager ();
204}
205
208{
209 interpreter& interp = __get_interpreter__ ();
210
211 return interp.get_display_info ();
212}
213
216{
217 interpreter& interp = __get_interpreter__ ();
218
219 return interp.get_gtk_manager ();
220}
221
224 const std::string& parameter_name)
225{
226 std::list<std::string> parameter_names;
227 parameter_names.push_back (parameter_name);
228 return get_function_handle (interp, arg, parameter_names);
229}
230
231// May return a function handle object, inline function object, or
232// function object.
233
236 const std::list<std::string>& parameter_names)
237{
238 if (arg.is_function_handle () || arg.is_inline_function ())
239 return arg;
240 else if (arg.is_string ())
241 {
242 std::string fstr = arg.string_value ();
243
244 if (fstr.empty ())
245 return octave_value ();
246
247 symbol_table& symtab = interp.get_symbol_table ();
248
249 octave_value fcn = symtab.find_function (fstr);
250
251 if (fcn.is_defined ())
252 return fcn;
253
254 // Possibly warn here that passing the function body in a
255 // character string is discouraged.
256
257 octave_value_list args (parameter_names.size () + 1);
258 octave_idx_type i = 0;
259 args(i++) = fstr;
260 for (const auto& pname : parameter_names)
261 args(i++) = pname;
262
263 octave_value_list tmp = interp.feval ("inline", args, 1);
264
265 if (tmp.length () > 0)
266 return tmp(0);
267 }
268
269 return octave_value ();
270}
271
272OCTAVE_END_NAMESPACE(octave)
Provides threadsafe access to octave.
cdef_manager & get_cdef_manager()
error_system & get_error_system()
display_info & get_display_info()
output_system & get_output_system()
load_path & get_load_path()
gtk_manager & get_gtk_manager()
symbol_scope get_current_scope() const
help_system & get_help_system()
dynamic_loader & get_dynamic_loader()
tree_evaluator & get_evaluator()
type_info & get_type_info()
child_list & get_child_list()
load_save_system & get_load_save_system()
static interpreter * the_interpreter()
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.
gh_manager & get_gh_manager()
input_system & get_input_system()
event_manager & get_event_manager()
symbol_table & get_symbol_table()
octave_idx_type length() const
Definition ovl.h:111
bool is_function_handle() const
Definition ov.h:768
bool is_inline_function() const
Definition ov.h:774
bool is_string() const
Definition ov.h:637
bool is_defined() const
Definition ov.h:592
std::string string_value(bool force=false) const
Definition ov.h:983
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope::invalid())
Definition symtab.cc:254
bp_table & get_bp_table()
Definition pt-eval.h:424
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
tree_evaluator & __get_evaluator__()
event_manager & __get_event_manager__()
child_list & __get_child_list__()
dynamic_loader & __get_dynamic_loader__()
cdef_manager & __get_cdef_manager__()
output_system & __get_output_system__()
error_system & __get_error_system__()
gh_manager & __get_gh_manager__()
display_info & __get_display_info__()
symbol_table & __get_symbol_table__()
symbol_scope __require_current_scope__()
symbol_scope __get_current_scope__()
help_system & __get_help_system__()
bp_table & __get_bp_table__()
type_info & __get_type_info__()
load_path & __get_load_path__()
input_system & __get_input_system__()
gtk_manager & __get_gtk_manager__()
interpreter & __get_interpreter__()
load_save_system & __get_load_save_system__()
octave_value get_function_handle(interpreter &interp, const octave_value &arg, const std::string &parameter_name)