525
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
525
|
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 the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
525
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_defun_int_h) |
|
25 #define octave_defun_int_h 1 |
|
26 |
2968
|
27 #include <string> |
|
28 |
3145
|
29 #include "ov-builtin.h" |
3325
|
30 #include "ov-dld-fcn.h" |
3145
|
31 #include "ov-mapper.h" |
|
32 #include "symtab.h" |
3015
|
33 #include "version.h" |
|
34 |
2968
|
35 class octave_value; |
|
36 |
3523
|
37 extern void print_usage (const std::string& nm, bool just_usage = false); |
3014
|
38 |
3523
|
39 extern void check_version (const std::string& version, const std::string& fcn); |
3015
|
40 |
3145
|
41 extern void |
|
42 install_builtin_mapper (octave_mapper *mf); |
2968
|
43 |
|
44 extern void |
3523
|
45 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
46 const std::string& doc, bool is_text_fcn = false, |
|
47 bool can_hide_function = true); |
2968
|
48 |
|
49 extern void |
3523
|
50 install_builtin_variable (const std::string& n, const octave_value& v, |
3258
|
51 bool p, bool e, |
3145
|
52 symbol_record::change_function chg_fcn, |
3523
|
53 const std::string& h); |
2968
|
54 |
|
55 extern void |
3523
|
56 install_builtin_constant (const std::string& n, const octave_value& v, |
|
57 bool p, const std::string& h); |
3258
|
58 |
|
59 extern void |
3523
|
60 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
61 const octave_shlib& shl, |
3523
|
62 const std::string& doc, bool is_text_fcn = false); |
703
|
63 |
3325
|
64 extern void |
3523
|
65 alias_builtin (const std::string& alias, const std::string& name); |
703
|
66 |
3743
|
67 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
2968
|
68 octave_value_list \ |
3743
|
69 name (const octave_value_list& args_name, int nargout_name) |
|
70 |
|
71 #define DECLARE_FUN(name, args_name, nargout_name) \ |
|
72 DECLARE_FUNX (F ## name, args_name, nargout_name) |
2968
|
73 |
3325
|
74 // Define the code that will be used to insert the new function into |
|
75 // the symbol table. We look for this name instead of the actual |
3523
|
76 // function so that we can easily install the doc std::string too. |
3325
|
77 |
|
78 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&); |
|
79 |
|
80 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
3842
|
81 DEFINE_FUN_INSTALLER_FUN2(name, doc, CXX_ABI) |
|
82 |
|
83 #define DEFINE_FUN_INSTALLER_FUN2(name, doc, cxx_abi) \ |
|
84 DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) |
|
85 |
|
86 #define DEFINE_FUN_INSTALLER_FUN3(name, doc, cxx_abi) \ |
|
87 extern "C" \ |
3325
|
88 bool \ |
3842
|
89 FS ## name ## _ ## cxx_abi (const octave_shlib& shl) \ |
3325
|
90 { \ |
4448
|
91 check_version (OCTAVE_API_VERSION, #name); \ |
3325
|
92 install_dld_function (F ## name, #name, shl, doc); \ |
|
93 return error_state ? false : true; \ |
|
94 } |
|
95 |
5102
|
96 // Define a builtin variable. |
|
97 // |
|
98 // name is the name of the variable, unquoted. |
|
99 // |
|
100 // defn is the initial value for the variable. |
|
101 // |
|
102 // protect is a flag that says whether it should be possible to give |
|
103 // the variable a new value. |
|
104 // |
|
105 // eternal is a flag that says whether it should be possible to |
|
106 // clear the variable. Most builtin variables are eternal, and |
|
107 // cannot be cleared. |
|
108 // |
|
109 // chg_fcn is a pointer to a function that should be called whenever |
|
110 // this variable is given a new value. It can be 0 if there is no |
|
111 // function to call. See also the code in user-prefs.cc. |
|
112 // |
|
113 // doc is the simple help text for this variable. |
|
114 |
|
115 #define DEFVAR(name, defn, chg_fcn, doc) \ |
|
116 DEFVAR_INTERNAL (#name, SBV_ ## name, defn, false, chg_fcn, doc) |
|
117 |
|
118 // Define a builtin constant `name' (which may be redefined, but will |
|
119 // retain its original value when cleared) and also an alias to it |
|
120 // called `__name__' (which may not be redefined). |
|
121 |
|
122 #define DEFCONST(name, defn, doc) \ |
|
123 DEFCONST_INTERNAL (name, defn, doc) |
|
124 |
|
125 // This one can be used when `name' cannot be used directly (if it is |
|
126 // already defined as a macro). In that case, name is already a |
|
127 // quoted string, and the name of the structure must to be passed too. |
|
128 |
|
129 #define DEFCONSTX(name, sname, defn, doc) \ |
|
130 DEFCONSTX_INTERNAL (name, sname, defn, doc) |
3842
|
131 |
3295
|
132 // MAKE_BUILTINS is defined to extract function names and related |
|
133 // information and create the *.df files that are eventually used to |
|
134 // create the builtins.cc file. |
|
135 |
|
136 #if defined (MAKE_BUILTINS) |
|
137 |
|
138 // Generate code to install name in the symbol table. The script |
|
139 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
4208
|
140 // or DEFCMD. |
3295
|
141 |
|
142 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
143 BEGIN_INSTALL_BUILTIN \ |
|
144 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
145 END_INSTALL_BUILTIN |
|
146 |
4234
|
147 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
148 BEGIN_INSTALL_BUILTIN \ |
|
149 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
150 END_INSTALL_BUILTIN |
|
151 |
3743
|
152 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
153 is_text_fcn, doc) \ |
|
154 BEGIN_INSTALL_BUILTIN \ |
3744
|
155 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, is_text_fcn, doc) \ |
3743
|
156 END_INSTALL_BUILTIN |
|
157 |
3364
|
158 // Generate code to install name in the symbol table. The script |
|
159 // mkdefs will create a .def file for every .cc file that uses |
|
160 // DEFUN_DLD. |
|
161 |
|
162 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
163 BEGIN_INSTALL_BUILTIN \ |
|
164 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
165 END_INSTALL_BUILTIN |
|
166 |
3295
|
167 // Generate code for making another name for an existing function. |
|
168 |
|
169 #define DEFALIAS_INTERNAL(alias, name) \ |
|
170 BEGIN_INSTALL_BUILTIN \ |
|
171 XDEFALIAS_INTERNAL(alias, name) \ |
|
172 END_INSTALL_BUILTIN |
|
173 |
|
174 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
175 BEGIN_INSTALL_BUILTIN \ |
|
176 XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
177 END_INSTALL_BUILTIN |
|
178 |
3321
|
179 #define DEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
180 BEGIN_INSTALL_BUILTIN \ |
3321
|
181 XDEFCONST_INTERNAL(name, defn, doc) \ |
|
182 END_INSTALL_BUILTIN |
|
183 |
|
184 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
185 BEGIN_INSTALL_BUILTIN \ |
|
186 XDEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
187 END_INSTALL_BUILTIN |
|
188 |
|
189 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
190 d_c_map, c_c_map, lo, hi, \ |
4100
|
191 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
192 BEGIN_INSTALL_BUILTIN \ |
|
193 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
194 d_c_map, c_c_map, lo, hi, \ |
4100
|
195 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
3295
|
196 END_INSTALL_BUILTIN |
|
197 |
|
198 #else /* ! MAKE_BUILTINS */ |
|
199 |
|
200 // Generate the first line of the function definition. This ensures |
|
201 // that the internal functions all have the same signature. |
|
202 |
|
203 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
204 DECLARE_FUN (name, args_name, nargout_name) |
|
205 |
4234
|
206 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
207 DECLARE_FUN (name, args_name, nargout_name) |
|
208 |
3743
|
209 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, \ |
|
210 is_text_fcn, doc) \ |
|
211 DECLARE_FUNX (fname, args_name, nargout_name) |
|
212 |
3295
|
213 // No definition is required for an alias. |
|
214 |
4699
|
215 #define DEFALIAS_INTERNAL(alias, name) |
3295
|
216 |
2968
|
217 // How builtin variables are actually installed. |
|
218 |
3258
|
219 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
220 install_builtin_variable (name, octave_value (defn), protect, \ |
|
221 (chg_fcn != 0), chg_fcn, doc) |
|
222 |
|
223 // How builtin variables are actually installed. |
|
224 |
3321
|
225 #define INSTALL_CONST(name, sname, defn, protect, doc) \ |
3258
|
226 install_builtin_constant (name, octave_value (defn), protect, doc) |
2968
|
227 |
3321
|
228 #define DEFCONST_INTERNAL(name, defn, doc) \ |
4011
|
229 INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); |
3321
|
230 |
|
231 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
4011
|
232 INSTALL_CONST (name, sname, defn, false, doc); |
3321
|
233 |
2968
|
234 // How mapper functions are actually installed. |
|
235 |
3564
|
236 // XXX FIXME XXX -- Really want to avoid the following casts, since |
|
237 // (as always with casts) it may mask some real errors... |
|
238 |
3249
|
239 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
240 d_c_map, c_c_map, lo, hi, \ |
4100
|
241 ch_map_flag, can_ret_cmplx_for_real, doc) \ |
2968
|
242 install_builtin_mapper \ |
3564
|
243 (new octave_mapper \ |
5261
|
244 (ch_map, d_b_map, c_b_map, d_d_map, d_c_map, c_c_map, \ |
4165
|
245 lo, hi, ch_map_flag, can_ret_cmplx_for_real, #name, doc)) |
525
|
246 |
3295
|
247 #endif /* ! MAKE_BUILTINS */ |
|
248 |
525
|
249 #endif |
|
250 |
|
251 /* |
|
252 ;;; Local Variables: *** |
|
253 ;;; mode: C++ *** |
|
254 ;;; End: *** |
|
255 */ |