525
|
1 // defun.h -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
525
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
525
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_defun_h) |
|
25 #define octave_defun_h 1 |
|
26 |
|
27 #if defined (octave_defun_dld_h) |
|
28 #error defun.h and defun-dld.h both included in same file! |
|
29 #endif |
|
30 |
|
31 #include "defun-int.h" |
|
32 |
550
|
33 // Define a builtin variable. |
|
34 // |
|
35 // name is the name of the variable, as a string. |
|
36 // |
|
37 // sname is the name of the structure that is used to hold |
|
38 // information about the variable, and that is passed to |
|
39 // install_builtin_variable to register it in the symbol table. |
|
40 // By convention, it is constructed by prefixing name with the |
|
41 // character S. |
|
42 // |
|
43 // ins_as_fcn is a flag that says whether to install the variable as |
|
44 // if it were a function (allowing the name to also be used as a |
|
45 // variable by users, but recover its original definition if cleared). |
|
46 // |
|
47 // eternal is a flag that says whether it should be possible to |
|
48 // clear the variable. Most builtin variables are eternal, and |
|
49 // cannot be cleared. |
|
50 // |
|
51 // sv_fcn is a pointer to a function that should be called whenever |
|
52 // this variable is given a new value. It can be 0 if there is no |
|
53 // function to call. See also the code in user-prefs.cc. |
|
54 // |
|
55 // doc is the simple help text for this variable. |
|
56 |
525
|
57 #define DEFVAR(name, sname, defn, inst_as_fcn, protect, \ |
|
58 eternal, sv_fcn, doc) \ |
|
59 do \ |
|
60 { \ |
|
61 builtin_variable sname = \ |
|
62 { \ |
|
63 name, \ |
|
64 new tree_constant (defn), \ |
|
65 inst_as_fcn, \ |
|
66 protect, \ |
|
67 eternal, \ |
|
68 sv_fcn, \ |
|
69 doc, \ |
|
70 }; \ |
|
71 install_builtin_variable (&sname); \ |
|
72 } \ |
|
73 while (0) |
|
74 |
550
|
75 // Define a builtin function. |
|
76 // |
|
77 // name is the name of the function, as a string. |
|
78 // |
|
79 // fname is the name of the C++ function. By convention, it is |
|
80 // constructed by prefixing name with the character F. |
|
81 // |
|
82 // sname is the name of the structure that is used to hold |
|
83 // information about the function, and that is passed to |
|
84 // install_builtin_function to register the function in the symbol |
|
85 // table. By convention, it is constructed by prefixing name with |
|
86 // the character S. |
|
87 // |
|
88 // nargin_max is the maximum number of arguments this function can |
|
89 // accept. XXX FIXME XXX -- is this really used now? |
|
90 // |
|
91 // nargout_max is the maximum number of outputs this function can |
|
92 // produce. XXX FIXME XXX -- is this really used now? |
|
93 // |
|
94 // doc is the simple help text for the function. |
|
95 |
525
|
96 #define DEFUN(name, fname, sname, nargin_max, nargout_max, doc) \ |
|
97 DEFUN_INTERNAL (name, fname, sname, nargin_max, nargout_max, 0, doc) |
|
98 |
550
|
99 // Define a builtin text-style function. |
|
100 // |
|
101 // This is like DEFUN, except that it defines a function that can be |
|
102 // called from the Octave language without using parenthesis to |
|
103 // surround the arguments). |
|
104 |
525
|
105 #define DEFUN_TEXT(name, fname, sname, nargin_max, nargout_max, doc) \ |
|
106 DEFUN_INTERNAL (name, fname, sname, nargin_max, nargout_max, 1, doc) |
|
107 |
550
|
108 // Define a mapper function. |
|
109 // |
|
110 // name is the name of the function as a string |
|
111 // |
|
112 // sname is the name of the structure that is used to hold |
|
113 // information about the function, and that is passed to |
|
114 // install_builtin_mapper to register the function in the symbol |
|
115 // table. By convention, it is constructed by prefixing name with |
|
116 // the character S. |
|
117 // |
|
118 // can_ret_cmplx_for_real is a flag that says whether this function |
|
119 // can create a complex number given a real-valued argument |
|
120 // (e.g., sqrt (-1)). |
|
121 // |
|
122 // lo is the lower bound of the range for which real arguments can |
|
123 // become complex. (e.g., lo == -Inf for sqrt). |
|
124 // |
|
125 // hi is the upper bound of the range for which real arguments can |
|
126 // become complex. (e.g., hi == 0 for sqrt). |
|
127 // |
|
128 // d_d_map is a pointer to a function that should be called for real |
|
129 // arguments that are expected to create real results. |
|
130 // |
|
131 // d_c_map is a pointer to a function that should be called for real |
|
132 // arguments that are expected to create complex results. |
|
133 // |
|
134 // c_c_map is a pointer to a function that should be called for |
|
135 // complex arguments that are expected to create complex results. |
|
136 // |
|
137 // doc is the simple help text for the function. |
|
138 |
525
|
139 #define DEFUN_MAPPER(name, sname, can_ret_cmplx_for_real, lo, hi, \ |
|
140 d_d_map, d_c_map, c_c_map, doc) \ |
|
141 do \ |
|
142 { \ |
|
143 builtin_mapper_function sname = \ |
|
144 { \ |
|
145 name, \ |
|
146 can_ret_cmplx_for_real, \ |
|
147 lo, \ |
|
148 hi, \ |
|
149 d_d_map, \ |
|
150 d_c_map, \ |
|
151 c_c_map, \ |
|
152 doc, \ |
|
153 }; \ |
|
154 install_builtin_mapper (&sname); \ |
|
155 } \ |
|
156 while (0) |
|
157 |
550
|
158 // Make alias another name for the existing function name. This macro |
|
159 // must be used in the same file where name is defined, after the |
|
160 // definition for name. |
525
|
161 |
550
|
162 #define DEFALIAS(name, alias) DEFALIAS_INTERNAL (name, alias) |
525
|
163 |
|
164 #endif |
|
165 |
|
166 /* |
|
167 ;;; Local Variables: *** |
|
168 ;;; mode: C++ *** |
|
169 ;;; page-delimiter: "^/\\*" *** |
|
170 ;;; End: *** |
|
171 */ |