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 |
1340
|
41 // character SBV. |
|
42 // |
|
43 // defn is the initial value for the variable. |
550
|
44 // |
|
45 // ins_as_fcn is a flag that says whether to install the variable as |
|
46 // if it were a function (allowing the name to also be used as a |
|
47 // variable by users, but recover its original definition if cleared). |
|
48 // |
1340
|
49 // protect is a flag that says whether it should be possible to give |
|
50 // the variable a new value. |
|
51 // |
550
|
52 // eternal is a flag that says whether it should be possible to |
|
53 // clear the variable. Most builtin variables are eternal, and |
|
54 // cannot be cleared. |
|
55 // |
|
56 // sv_fcn is a pointer to a function that should be called whenever |
|
57 // this variable is given a new value. It can be 0 if there is no |
|
58 // function to call. See also the code in user-prefs.cc. |
|
59 // |
|
60 // doc is the simple help text for this variable. |
|
61 |
1431
|
62 #define DEFVAR_INT(name, sname, defn, inst_as_fcn, protect, \ |
|
63 sv_fcn, doc) \ |
525
|
64 do \ |
|
65 { \ |
1755
|
66 builtin_variable sname (name, new tree_constant (defn), \ |
|
67 inst_as_fcn, protect, (sv_fcn ? 1 : 0), \ |
|
68 sv_fcn, doc); \ |
|
69 install_builtin_variable (sname); \ |
525
|
70 } \ |
|
71 while (0) |
|
72 |
1431
|
73 #define DEFVAR(name, sname, defn, inst_as_fcn, sv_fcn, doc) \ |
|
74 DEFVAR_INT (name, sname, defn, inst_as_fcn, 0, sv_fcn, doc) |
|
75 |
|
76 // Define a builtin-constant, and a corresponding variable that can be |
|
77 // redefined. This is just the same as DEFVAR, except that it defines |
|
78 // `name' as a variable, and `__name__' as a constant that cannot be |
|
79 // redefined. |
|
80 |
|
81 #define DEFCONST(name, sname, defn, inst_as_fcn, sv_fcn, doc) \ |
|
82 DEFVAR_INT (name, sname, defn, inst_as_fcn, 0, sv_fcn, doc); \ |
|
83 DEFVAR_INT ("__" ## name ## "__", sname, defn, 0, 1, sv_fcn, doc) |
|
84 |
550
|
85 // Define a builtin function. |
|
86 // |
|
87 // name is the name of the function, as a string. |
|
88 // |
|
89 // fname is the name of the C++ function. By convention, it is |
|
90 // constructed by prefixing name with the character F. |
|
91 // |
|
92 // sname is the name of the structure that is used to hold |
|
93 // information about the function, and that is passed to |
|
94 // install_builtin_function to register the function in the symbol |
|
95 // table. By convention, it is constructed by prefixing name with |
|
96 // the character S. |
|
97 // |
1488
|
98 // unused_arg_flags is used to decide how to declare the function so |
|
99 // that g++ doesn't complain about unused arguments. It can be |
|
100 // one of: |
550
|
101 // |
1488
|
102 // 00: Both of the arguments args and nargout are unused. |
|
103 // 10: The argument args is unused. |
|
104 // 01: The argument nargout is unused. |
|
105 // 11 or missing: Both of the arguments args and nargout are used. |
550
|
106 // |
|
107 // doc is the simple help text for the function. |
|
108 |
1488
|
109 #define DEFUN(name, fname, sname, unused_arg_flags, doc) \ |
|
110 DEFUN_INTERNAL (name, fname, sname, unused_arg_flags, 0, doc) |
525
|
111 |
550
|
112 // Define a builtin text-style function. |
|
113 // |
|
114 // This is like DEFUN, except that it defines a function that can be |
|
115 // called from the Octave language without using parenthesis to |
|
116 // surround the arguments). |
|
117 |
1488
|
118 #define DEFUN_TEXT(name, fname, sname, unused_arg_flags, doc) \ |
|
119 DEFUN_INTERNAL (name, fname, sname, unused_arg_flags, 1, doc) |
525
|
120 |
550
|
121 // Define a mapper function. |
|
122 // |
|
123 // name is the name of the function as a string |
|
124 // |
|
125 // sname is the name of the structure that is used to hold |
|
126 // information about the function, and that is passed to |
|
127 // install_builtin_mapper to register the function in the symbol |
|
128 // table. By convention, it is constructed by prefixing name with |
|
129 // the character S. |
|
130 // |
|
131 // can_ret_cmplx_for_real is a flag that says whether this function |
|
132 // can create a complex number given a real-valued argument |
|
133 // (e.g., sqrt (-1)). |
|
134 // |
|
135 // lo is the lower bound of the range for which real arguments can |
|
136 // become complex. (e.g., lo == -Inf for sqrt). |
|
137 // |
|
138 // hi is the upper bound of the range for which real arguments can |
|
139 // become complex. (e.g., hi == 0 for sqrt). |
|
140 // |
|
141 // d_d_map is a pointer to a function that should be called for real |
|
142 // arguments that are expected to create real results. |
|
143 // |
|
144 // d_c_map is a pointer to a function that should be called for real |
|
145 // arguments that are expected to create complex results. |
|
146 // |
|
147 // c_c_map is a pointer to a function that should be called for |
|
148 // complex arguments that are expected to create complex results. |
|
149 // |
|
150 // doc is the simple help text for the function. |
|
151 |
525
|
152 #define DEFUN_MAPPER(name, sname, can_ret_cmplx_for_real, lo, hi, \ |
|
153 d_d_map, d_c_map, c_c_map, doc) \ |
|
154 do \ |
|
155 { \ |
1755
|
156 builtin_mapper_function sname (name, can_ret_cmplx_for_real, \ |
|
157 lo, hi, d_d_map, d_c_map, \ |
|
158 c_c_map, doc); \ |
|
159 install_builtin_mapper (sname); \ |
525
|
160 } \ |
|
161 while (0) |
|
162 |
550
|
163 // Make alias another name for the existing function name. This macro |
|
164 // must be used in the same file where name is defined, after the |
|
165 // definition for name. |
525
|
166 |
550
|
167 #define DEFALIAS(name, alias) DEFALIAS_INTERNAL (name, alias) |
525
|
168 |
|
169 #endif |
|
170 |
|
171 /* |
|
172 ;;; Local Variables: *** |
|
173 ;;; mode: C++ *** |
|
174 ;;; page-delimiter: "^/\\*" *** |
|
175 ;;; End: *** |
|
176 */ |