525
|
1 // defun.h -*- C++ -*- |
|
2 /* |
|
3 |
1884
|
4 Copyright (C) 1996 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 // |
1957
|
35 // name is the name of the variable, unquoted. |
1340
|
36 // |
|
37 // defn is the initial value for the variable. |
550
|
38 // |
|
39 // ins_as_fcn is a flag that says whether to install the variable as |
|
40 // if it were a function (allowing the name to also be used as a |
|
41 // variable by users, but recover its original definition if cleared). |
|
42 // |
1340
|
43 // protect is a flag that says whether it should be possible to give |
|
44 // the variable a new value. |
|
45 // |
550
|
46 // eternal is a flag that says whether it should be possible to |
|
47 // clear the variable. Most builtin variables are eternal, and |
|
48 // cannot be cleared. |
|
49 // |
|
50 // sv_fcn is a pointer to a function that should be called whenever |
|
51 // this variable is given a new value. It can be 0 if there is no |
|
52 // function to call. See also the code in user-prefs.cc. |
|
53 // |
|
54 // doc is the simple help text for this variable. |
|
55 |
1957
|
56 #define DEFVAR(name, defn, inst_as_fcn, sv_fcn, doc) \ |
|
57 DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc) |
|
58 |
|
59 // Define a builtin-constant, and a corresponding variable that can be |
|
60 // redefined. This is just the same as DEFVAR, except that it defines |
|
61 // `name' as a variable, and `__name__' as a constant that cannot be |
|
62 // redefined. |
|
63 |
|
64 #define DEFCONST(name, defn, inst_as_fcn, sv_fcn, doc) \ |
|
65 DEFVAR_INT (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc); \ |
|
66 DEFVAR_INT ("__" ## #name ## "__", XSBV_ ## name, defn, 0, 1, sv_fcn, doc) |
|
67 |
|
68 // This one can be used when `name' cannot be used directly (if it is |
|
69 // already defined as a macro). In that case, name is already a |
|
70 // quoted string, and the name of the structure has to be passed too. |
|
71 |
|
72 #define DEFCONSTX(name, sname, defn, inst_as_fcn, sv_fcn, doc) \ |
|
73 DEFVAR_INT (#name, sname, defn, inst_as_fcn, 0, sv_fcn, doc); \ |
|
74 DEFVAR_INT ("__" ## name ## "__", X ## sname, defn, 0, 1, sv_fcn, doc) |
|
75 |
|
76 // How builtin variables are actually installed. |
|
77 |
|
78 #define DEFVAR_INT(name, sname, defn, inst_as_fcn, protect, sv_fcn, doc) \ |
525
|
79 do \ |
|
80 { \ |
1755
|
81 builtin_variable sname (name, new tree_constant (defn), \ |
|
82 inst_as_fcn, protect, (sv_fcn ? 1 : 0), \ |
|
83 sv_fcn, doc); \ |
|
84 install_builtin_variable (sname); \ |
525
|
85 } \ |
|
86 while (0) |
|
87 |
550
|
88 // Define a builtin function. |
|
89 // |
1957
|
90 // name is the name of the function, unqouted. |
550
|
91 // |
1957
|
92 // args_name is the name of the Octave_object variable used to pass |
|
93 // the argument list to this function. |
550
|
94 // |
1957
|
95 // nargout_name is the name of the int variable used to pass the |
|
96 // number of output arguments this function is expected to produce. |
550
|
97 // |
|
98 // doc is the simple help text for the function. |
|
99 |
1957
|
100 #define DEFUN(name, args_name, nargout_name, doc) \ |
|
101 DEFUN_INTERNAL (name, args_name, nargout_name, 0, doc) |
525
|
102 |
550
|
103 // Define a builtin text-style function. |
|
104 // |
|
105 // This is like DEFUN, except that it defines a function that can be |
|
106 // called from the Octave language without using parenthesis to |
|
107 // surround the arguments). |
|
108 |
1957
|
109 #define DEFUN_TEXT(name, args_name, nargout_name, doc) \ |
|
110 DEFUN_INTERNAL (name, args_name, nargout_name, 1, doc) |
525
|
111 |
550
|
112 // Define a mapper function. |
|
113 // |
1957
|
114 // name is the name of the function, unquoqted. |
550
|
115 // |
|
116 // can_ret_cmplx_for_real is a flag that says whether this function |
|
117 // can create a complex number given a real-valued argument |
|
118 // (e.g., sqrt (-1)). |
|
119 // |
|
120 // lo is the lower bound of the range for which real arguments can |
|
121 // become complex. (e.g., lo == -Inf for sqrt). |
|
122 // |
|
123 // hi is the upper bound of the range for which real arguments can |
|
124 // become complex. (e.g., hi == 0 for sqrt). |
|
125 // |
|
126 // d_d_map is a pointer to a function that should be called for real |
|
127 // arguments that are expected to create real results. |
|
128 // |
|
129 // d_c_map is a pointer to a function that should be called for real |
|
130 // arguments that are expected to create complex results. |
|
131 // |
|
132 // c_c_map is a pointer to a function that should be called for |
|
133 // complex arguments that are expected to create complex results. |
|
134 // |
|
135 // doc is the simple help text for the function. |
|
136 |
1957
|
137 #define DEFUN_MAPPER(name, can_ret_cmplx_for_real, lo, hi, \ |
525
|
138 d_d_map, d_c_map, c_c_map, doc) \ |
|
139 do \ |
|
140 { \ |
1957
|
141 builtin_mapper_function S ## name (#name, can_ret_cmplx_for_real, \ |
1755
|
142 lo, hi, d_d_map, d_c_map, \ |
|
143 c_c_map, doc); \ |
1957
|
144 install_builtin_mapper (S ## name); \ |
525
|
145 } \ |
|
146 while (0) |
|
147 |
550
|
148 // Make alias another name for the existing function name. This macro |
|
149 // must be used in the same file where name is defined, after the |
|
150 // definition for name. |
525
|
151 |
550
|
152 #define DEFALIAS(name, alias) DEFALIAS_INTERNAL (name, alias) |
525
|
153 |
|
154 #endif |
|
155 |
|
156 /* |
|
157 ;;; Local Variables: *** |
|
158 ;;; mode: C++ *** |
|
159 ;;; page-delimiter: "^/\\*" *** |
|
160 ;;; End: *** |
|
161 */ |