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