Mercurial > hg > octave-nkf
annotate src/defun-int.h @ 10637:9cd5aa83fa62
implement 'local' parameter to pseudo-variables
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 17 May 2010 13:46:57 +0200 |
parents | f3b65e1ae355 |
children | ed6969880316 |
rev | line source |
---|---|
525 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
8920 | 4 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
525 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
525 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_defun_int_h) | |
25 #define octave_defun_int_h 1 | |
26 | |
2968 | 27 #include <string> |
28 | |
3145 | 29 #include "ov-builtin.h" |
3325 | 30 #include "ov-dld-fcn.h" |
3145 | 31 #include "symtab.h" |
3015 | 32 #include "version.h" |
33 | |
2968 | 34 class octave_value; |
35 | |
6109 | 36 extern OCTINTERP_API void print_usage (void); |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
7996
diff
changeset
|
37 extern OCTINTERP_API void print_usage (const std::string&); |
3014 | 38 |
6109 | 39 extern OCTINTERP_API void check_version (const std::string& version, const std::string& fcn); |
3015 | 40 |
6109 | 41 extern OCTINTERP_API void |
3523 | 42 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
10313 | 43 const std::string& doc, |
44 bool can_hide_function = true); | |
2968 | 45 |
6109 | 46 extern OCTINTERP_API void |
3523 | 47 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
10313 | 48 const octave_shlib& shl, const std::string& doc, |
49 bool relative = false); | |
703 | 50 |
6109 | 51 extern OCTINTERP_API void |
5864 | 52 install_mex_function (void *fptr, bool fmex, const std::string& name, |
10313 | 53 const octave_shlib& shl, bool relative = false); |
5864 | 54 |
6109 | 55 extern OCTINTERP_API void |
3523 | 56 alias_builtin (const std::string& alias, const std::string& name); |
703 | 57 |
9960
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
58 // Gets the shlib of the currently executing DLD function, if any. |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
59 extern OCTINTERP_API octave_shlib |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
60 get_current_shlib (void); |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
61 |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
62 // This is a convenience class that calls the above function automatically at |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
63 // construction time. When deriving new classes, you can either use it as a field |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
64 // or as a parent (with multiple inheritance). |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
65 |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 class octave_auto_shlib : public octave_shlib |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
67 { |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
68 octave_auto_shlib (void) |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
69 : octave_shlib (get_current_shlib ()) { } |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
70 octave_auto_shlib (const octave_shlib& shl) |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
71 : octave_shlib (shl) { } |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
72 }; |
5f3c10ecb150
implement get_current_shlib and octave_auto_shlib
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
73 |
3743 | 74 #define DECLARE_FUNX(name, args_name, nargout_name) \ |
6109 | 75 OCTAVE_EXPORT octave_value_list \ |
3743 | 76 name (const octave_value_list& args_name, int nargout_name) |
77 | |
78 #define DECLARE_FUN(name, args_name, nargout_name) \ | |
79 DECLARE_FUNX (F ## name, args_name, nargout_name) | |
2968 | 80 |
3325 | 81 // Define the code that will be used to insert the new function into |
82 // the symbol table. We look for this name instead of the actual | |
3523 | 83 // function so that we can easily install the doc std::string too. |
3325 | 84 |
6323 | 85 typedef bool (*octave_dld_fcn_installer) (const octave_shlib&, bool relative); |
3325 | 86 |
7336 | 87 typedef octave_function * (*octave_dld_fcn_getter) (const octave_shlib&, bool relative); |
88 | |
3325 | 89 #define DEFINE_FUN_INSTALLER_FUN(name, doc) \ |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
90 DEFINE_FUNX_INSTALLER_FUN(#name, F ## name, G ## name, doc) |
5796 | 91 |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
92 #define DEFINE_FUNX_INSTALLER_FUN(name, fname, gname, doc) \ |
7336 | 93 extern "C" \ |
94 OCTAVE_EXPORT \ | |
95 octave_function * \ | |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
96 gname (const octave_shlib& shl, bool relative) \ |
7336 | 97 { \ |
98 octave_function *retval = 0; \ | |
99 \ | |
100 check_version (OCTAVE_API_VERSION, name); \ | |
101 \ | |
102 if (! error_state) \ | |
103 { \ | |
10313 | 104 octave_dld_function *fcn = octave_dld_function::create (fname, shl, name, doc); \ |
7336 | 105 \ |
106 if (relative) \ | |
107 fcn->mark_relative (); \ | |
108 \ | |
109 retval = fcn; \ | |
110 } \ | |
111 \ | |
112 return retval; \ | |
3325 | 113 } |
114 | |
3295 | 115 // MAKE_BUILTINS is defined to extract function names and related |
116 // information and create the *.df files that are eventually used to | |
117 // create the builtins.cc file. | |
118 | |
119 #if defined (MAKE_BUILTINS) | |
120 | |
121 // Generate code to install name in the symbol table. The script | |
122 // mkdefs will create a .def file for every .cc file that uses DEFUN, | |
4208 | 123 // or DEFCMD. |
3295 | 124 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
125 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
3295 | 126 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
127 XDEFUN_INTERNAL (name, args_name, nargout_name, doc) \ |
3295 | 128 END_INSTALL_BUILTIN |
129 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
130 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
4234 | 131 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
132 XDEFCONSTFUN_INTERNAL (name, args_name, nargout_name, doc) \ |
4234 | 133 END_INSTALL_BUILTIN |
134 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
135 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
3743 | 136 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
137 XDEFUNX_INTERNAL (name, fname, args_name, nargout_name, doc) \ |
3743 | 138 END_INSTALL_BUILTIN |
139 | |
3364 | 140 // Generate code to install name in the symbol table. The script |
141 // mkdefs will create a .def file for every .cc file that uses | |
142 // DEFUN_DLD. | |
143 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
144 #define DEFUN_DLD_INTERNAL(name, args_name, nargout_name, doc) \ |
3364 | 145 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
146 XDEFUN_DLD_INTERNAL (name, args_name, nargout_name, doc) \ |
3364 | 147 END_INSTALL_BUILTIN |
148 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
149 #define DEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
5796 | 150 BEGIN_INSTALL_BUILTIN \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
151 XDEFUNX_DLD_INTERNAL (name, fname, args_name, nargout_name, doc) \ |
5796 | 152 END_INSTALL_BUILTIN |
153 | |
3295 | 154 // Generate code for making another name for an existing function. |
155 | |
156 #define DEFALIAS_INTERNAL(alias, name) \ | |
157 BEGIN_INSTALL_BUILTIN \ | |
158 XDEFALIAS_INTERNAL(alias, name) \ | |
159 END_INSTALL_BUILTIN | |
160 | |
161 #else /* ! MAKE_BUILTINS */ | |
162 | |
163 // Generate the first line of the function definition. This ensures | |
164 // that the internal functions all have the same signature. | |
165 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
166 #define DEFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
3295 | 167 DECLARE_FUN (name, args_name, nargout_name) |
168 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
169 #define DEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ |
4234 | 170 DECLARE_FUN (name, args_name, nargout_name) |
171 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8575
diff
changeset
|
172 #define DEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ |
3743 | 173 DECLARE_FUNX (fname, args_name, nargout_name) |
174 | |
3295 | 175 // No definition is required for an alias. |
176 | |
4699 | 177 #define DEFALIAS_INTERNAL(alias, name) |
3295 | 178 |
179 #endif /* ! MAKE_BUILTINS */ | |
180 | |
525 | 181 #endif |