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 |
3014
|
36 extern void print_usage (const string& nm, bool just_usage = false); |
|
37 |
3015
|
38 extern void check_version (const string& version, const string& fcn); |
|
39 |
3145
|
40 extern void |
|
41 install_builtin_mapper (octave_mapper *mf); |
2968
|
42 |
|
43 extern void |
3145
|
44 install_builtin_function (octave_builtin::fcn f, const string& name, |
|
45 const string& doc, bool is_text_fcn = false); |
2968
|
46 |
|
47 extern void |
|
48 install_builtin_variable (const string& n, const octave_value& v, |
3258
|
49 bool p, bool e, |
3145
|
50 symbol_record::change_function chg_fcn, |
2968
|
51 const string& h); |
|
52 |
|
53 extern void |
3258
|
54 install_builtin_constant (const string& n, const octave_value& v, |
|
55 bool p, const string& h); |
|
56 |
|
57 extern void |
3325
|
58 install_dld_function (octave_dld_function::fcn f, const string& name, |
|
59 const octave_shlib& shl, |
|
60 const string& doc, bool is_text_fcn = false); |
703
|
61 |
3325
|
62 extern void |
|
63 alias_builtin (const string& alias, const string& name); |
703
|
64 |
1957
|
65 #define DECLARE_FUN(name, args_name, nargout_name) \ |
2968
|
66 octave_value_list \ |
|
67 F ## name (const octave_value_list& args_name, int nargout_name) |
|
68 |
3325
|
69 // Define the code that will be used to insert the new function into |
|
70 // the symbol table. We look for this name instead of the actual |
|
71 // function so that we can easily install the doc string too. |
|
72 |
|
73 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&); |
|
74 |
|
75 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
|
76 bool \ |
|
77 FS ## name (const octave_shlib& shl) \ |
|
78 { \ |
|
79 check_version (OCTAVE_VERSION, #name); \ |
|
80 install_dld_function (F ## name, #name, shl, doc); \ |
|
81 return error_state ? false : true; \ |
|
82 } |
|
83 |
3295
|
84 // MAKE_BUILTINS is defined to extract function names and related |
|
85 // information and create the *.df files that are eventually used to |
|
86 // create the builtins.cc file. |
|
87 |
|
88 #if defined (MAKE_BUILTINS) |
|
89 |
|
90 // Generate code to install name in the symbol table. The script |
|
91 // mkdefs will create a .def file for every .cc file that uses DEFUN, |
|
92 // DEFUN_TEXT, or DEFUN_DLD. |
|
93 |
|
94 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
95 BEGIN_INSTALL_BUILTIN \ |
|
96 XDEFUN_INTERNAL (name, args_name, nargout_name, is_text_fcn, doc) \ |
|
97 END_INSTALL_BUILTIN |
|
98 |
|
99 // Generate code for making another name for an existing function. |
|
100 |
|
101 #define DEFALIAS_INTERNAL(alias, name) \ |
|
102 BEGIN_INSTALL_BUILTIN \ |
|
103 XDEFALIAS_INTERNAL(alias, name) \ |
|
104 END_INSTALL_BUILTIN |
|
105 |
|
106 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
107 BEGIN_INSTALL_BUILTIN \ |
|
108 XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
109 END_INSTALL_BUILTIN |
|
110 |
3321
|
111 #define DEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
112 BEGIN_INSTALL_BUILTIN \ |
3321
|
113 XDEFCONST_INTERNAL(name, defn, doc) \ |
|
114 END_INSTALL_BUILTIN |
|
115 |
|
116 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
117 BEGIN_INSTALL_BUILTIN \ |
|
118 XDEFCONST_INTERNAL(name, defn, doc) \ |
3295
|
119 END_INSTALL_BUILTIN |
|
120 |
|
121 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
122 d_c_map, c_c_map, lo, hi, \ |
|
123 can_ret_cmplx_for_real, doc) \ |
|
124 BEGIN_INSTALL_BUILTIN \ |
|
125 XDEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
126 d_c_map, c_c_map, lo, hi, \ |
|
127 can_ret_cmplx_for_real, doc) \ |
|
128 END_INSTALL_BUILTIN |
|
129 |
|
130 #else /* ! MAKE_BUILTINS */ |
|
131 |
|
132 // Generate the first line of the function definition. This ensures |
|
133 // that the internal functions all have the same signature. |
|
134 |
|
135 #define DEFUN_INTERNAL(name, args_name, nargout_name, is_text_fcn, doc) \ |
|
136 DECLARE_FUN (name, args_name, nargout_name) |
|
137 |
|
138 // No definition is required for an alias. |
|
139 |
|
140 #define DEFALIAS_INTERNAL(name, alias) |
|
141 |
2968
|
142 // How builtin variables are actually installed. |
|
143 |
3258
|
144 #define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ |
|
145 install_builtin_variable (name, octave_value (defn), protect, \ |
|
146 (chg_fcn != 0), chg_fcn, doc) |
|
147 |
|
148 // How builtin variables are actually installed. |
|
149 |
3321
|
150 #define INSTALL_CONST(name, sname, defn, protect, doc) \ |
3258
|
151 install_builtin_constant (name, octave_value (defn), protect, doc) |
2968
|
152 |
3321
|
153 #define DEFCONST_INTERNAL(name, defn, doc) \ |
|
154 INSTALL_CONST (#name, SBV_ ## name, defn, false, doc); \ |
|
155 INSTALL_CONST ("__" ## #name ## "__", XSBV_ ## name, defn, true, doc) |
|
156 |
|
157 #define DEFCONSTX_INTERNAL(name, sname, defn, doc) \ |
|
158 INSTALL_CONST (name, sname, defn, false, doc); \ |
|
159 INSTALL_CONST ("__" ## name ## "__", X ## sname, defn, true, doc) |
|
160 |
2968
|
161 // How mapper functions are actually installed. |
|
162 |
3249
|
163 #define DEFUN_MAPPER_INTERNAL(name, ch_map, d_b_map, c_b_map, d_d_map, \ |
|
164 d_c_map, c_c_map, lo, hi, \ |
|
165 can_ret_cmplx_for_real, doc) \ |
2968
|
166 install_builtin_mapper \ |
3249
|
167 (new octave_mapper (ch_map, d_b_map, c_b_map, d_d_map, d_c_map, \ |
|
168 c_c_map, lo, hi, \ |
2968
|
169 can_ret_cmplx_for_real, #name)) |
525
|
170 |
3295
|
171 #endif /* ! MAKE_BUILTINS */ |
|
172 |
525
|
173 #endif |
|
174 |
|
175 /* |
|
176 ;;; Local Variables: *** |
|
177 ;;; mode: C++ *** |
|
178 ;;; End: *** |
|
179 */ |