Mercurial > hg > octave-nkf
annotate src/ov-fcn-handle.cc @ 9450:cf714e75c656
implement overloaded function handles
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 23 Jul 2009 14:44:30 +0200 |
parents | 0dd3c7a2ba19 |
children | 0c7d84a65386 |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 John W. Eaton |
4343 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4343 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4343 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <iostream> | |
5765 | 28 #include <sstream> |
5164 | 29 #include <vector> |
4343 | 30 |
7336 | 31 #include "file-ops.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
32 #include "oct-locbuf.h" |
7336 | 33 |
4343 | 34 #include "defun.h" |
4654 | 35 #include "error.h" |
36 #include "gripes.h" | |
5663 | 37 #include "input.h" |
4343 | 38 #include "oct-map.h" |
39 #include "ov-base.h" | |
40 #include "ov-fcn-handle.h" | |
4980 | 41 #include "ov-usr-fcn.h" |
4343 | 42 #include "pr-output.h" |
4980 | 43 #include "pt-pr-code.h" |
44 #include "pt-misc.h" | |
45 #include "pt-stmt.h" | |
46 #include "pt-cmd.h" | |
47 #include "pt-exp.h" | |
48 #include "pt-assign.h" | |
4343 | 49 #include "variables.h" |
4988 | 50 #include "parse.h" |
6625 | 51 #include "unwind-prot.h" |
52 #include "defaults.h" | |
53 #include "file-stat.h" | |
54 #include "load-path.h" | |
55 #include "oct-env.h" | |
4988 | 56 |
57 #include "byte-swap.h" | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
58 #include "ls-ascii-helper.h" |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
59 #include "ls-hdf5.h" |
4988 | 60 #include "ls-oct-ascii.h" |
6625 | 61 #include "ls-oct-binary.h" |
4988 | 62 #include "ls-utils.h" |
4343 | 63 |
64 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); | |
65 | |
4612 | 66 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, |
67 "function handle", | |
5946 | 68 "function_handle"); |
4343 | 69 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
70 octave_fcn_handle::octave_fcn_handle (const octave_value& f, |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
71 const std::string& n) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
72 : fcn (f), nm (n) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
73 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
74 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
75 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
76 if (uf) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
77 symbol_table::cache_name (uf->scope (), nm); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
78 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
79 |
4924 | 80 octave_value_list |
81 octave_fcn_handle::subsref (const std::string& type, | |
82 const std::list<octave_value_list>& idx, | |
83 int nargout) | |
84 { | |
85 octave_value_list retval; | |
86 | |
87 switch (type[0]) | |
88 { | |
89 case '(': | |
90 { | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
91 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5663 | 92 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
93 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
4924 | 94 } |
95 break; | |
96 | |
97 case '{': | |
98 case '.': | |
99 { | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
100 std::string tnm = type_name (); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
101 error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); |
4924 | 102 } |
103 break; | |
104 | |
105 default: | |
106 panic_impossible (); | |
107 } | |
108 | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
109 // FIXME -- perhaps there should be an |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
110 // octave_value_list::next_subsref member function? See also |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
111 // octave_builtin::subsref. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
112 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
113 if (idx.size () > 1) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
114 retval = retval(0).next_subsref (nargout, type, idx); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
115 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
116 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
117 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
118 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
119 octave_value_list |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
120 octave_fcn_handle::do_multi_index_op (int nargout, |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
121 const octave_value_list& args) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
122 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
123 octave_value_list retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
124 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
125 out_of_date_check (fcn); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
126 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
127 if (disp.get () && ! args.empty ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
128 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
129 // Possibly overloaded function. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
130 octave_value ovfcn = fcn; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
131 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
132 // Get dynamic (class) dispatch type. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
133 std::string ddt = get_dispatch_type (args); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
134 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
135 if (ddt.empty ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
136 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
137 // Static dispatch (class of 1st arg)? |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
138 if (! disp->empty ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
139 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
140 std::string sdt = args(0).class_name (); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
141 str_ov_map::iterator pos = disp->find (sdt); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
142 if (pos != disp->end ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
143 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
144 out_of_date_check (pos->second, sdt); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
145 ovfcn = pos->second; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
146 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
147 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
148 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
149 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
150 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
151 octave_value method = symbol_table::find_method (nm, ddt); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
152 if (method.is_defined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
153 ovfcn = method; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
154 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
155 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
156 if (ovfcn.is_defined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
157 retval = ovfcn.do_multi_index_op (nargout, args); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
158 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
159 error ("invalid function handle"); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
160 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
161 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
162 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
163 // Non-overloaded function (anonymous, subfunction, private function). |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
164 if (fcn.is_defined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
165 retval = fcn.do_multi_index_op (nargout, args); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
166 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
167 error ("invalid function handle"); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
168 } |
4924 | 169 |
170 return retval; | |
171 } | |
172 | |
4988 | 173 bool |
6625 | 174 octave_fcn_handle::set_fcn (const std::string &octaveroot, |
175 const std::string& fpath) | |
4988 | 176 { |
6625 | 177 bool success = true; |
178 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
179 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
180 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
181 && fpath.substr (0, octaveroot.length ()) == octaveroot |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
182 && OCTAVE_EXEC_PREFIX != octaveroot) |
6625 | 183 { |
184 // First check if just replacing matlabroot is enough | |
185 std::string str = OCTAVE_EXEC_PREFIX + | |
186 fpath.substr (octaveroot.length ()); | |
187 file_stat fs (str); | |
188 | |
189 if (fs.exists ()) | |
190 { | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
191 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 192 |
7336 | 193 std::string dir_name = str.substr (0, xpos); |
6625 | 194 |
7336 | 195 octave_function *xfcn |
196 = load_fcn_from_file (str, dir_name, "", nm); | |
6625 | 197 |
7336 | 198 if (xfcn) |
199 { | |
200 octave_value tmp (xfcn); | |
6625 | 201 |
7336 | 202 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
6625 | 203 } |
204 else | |
205 { | |
206 error ("function handle points to non-existent function"); | |
207 success = false; | |
208 } | |
209 } | |
210 else | |
211 { | |
212 // Next just search for it anywhere in the system path | |
213 string_vector names(3); | |
214 names(0) = nm + ".oct"; | |
215 names(1) = nm + ".mex"; | |
216 names(2) = nm + ".m"; | |
217 | |
6626 | 218 dir_path p (load_path::system_path ()); |
6625 | 219 |
220 str = octave_env::make_absolute | |
221 (p.find_first_of (names), octave_env::getcwd ()); | |
222 | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
223 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 224 |
7336 | 225 std::string dir_name = str.substr (0, xpos); |
226 | |
227 octave_function *xfcn = load_fcn_from_file (str, dir_name, "", nm); | |
4989 | 228 |
7336 | 229 if (xfcn) |
230 { | |
231 octave_value tmp (xfcn); | |
6625 | 232 |
7336 | 233 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
6625 | 234 } |
235 else | |
236 { | |
237 error ("function handle points to non-existent function"); | |
238 success = false; | |
239 } | |
240 } | |
241 } | |
242 else | |
243 { | |
244 if (fpath.length () > 0) | |
245 { | |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7901
diff
changeset
|
246 size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 247 |
7336 | 248 std::string dir_name = fpath.substr (0, xpos); |
249 | |
250 octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", nm); | |
6625 | 251 |
7336 | 252 if (xfcn) |
253 { | |
254 octave_value tmp (xfcn); | |
6625 | 255 |
7336 | 256 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
6625 | 257 } |
258 else | |
259 { | |
260 error ("function handle points to non-existent function"); | |
261 success = false; | |
262 } | |
263 } | |
264 else | |
265 { | |
7336 | 266 fcn = symbol_table::find_function (nm); |
267 | |
6625 | 268 if (! fcn.is_function ()) |
269 { | |
270 error ("function handle points to non-existent function"); | |
271 success = false; | |
272 } | |
273 } | |
274 } | |
275 | |
276 return success; | |
277 } | |
278 | |
279 bool | |
6974 | 280 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 281 { |
4988 | 282 if (nm == "@<anonymous>") |
283 { | |
6625 | 284 os << nm << "\n"; |
285 | |
4989 | 286 print_raw (os, true); |
287 os << "\n"; | |
6625 | 288 |
7336 | 289 if (fcn.is_undefined ()) |
6625 | 290 return false; |
291 | |
292 octave_user_function *f = fcn.user_function_value (); | |
293 | |
7336 | 294 std::list<symbol_table::symbol_record> vars |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
295 = symbol_table::all_variables (f->scope (), 0); |
6625 | 296 |
7336 | 297 size_t varlen = vars.size (); |
6625 | 298 |
299 if (varlen > 0) | |
300 { | |
301 os << "# length: " << varlen << "\n"; | |
302 | |
7336 | 303 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
304 p != vars.end (); p++) | |
6625 | 305 { |
7336 | 306 if (! save_ascii_data (os, p->varval (), p->name (), false, 0)) |
6625 | 307 return os; |
308 } | |
309 } | |
310 } | |
311 else | |
312 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
313 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
314 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
315 |
6625 | 316 os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
317 if (! fnm.empty ()) |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
318 os << "# path: " << fnm << "\n"; |
6625 | 319 os << nm << "\n"; |
4988 | 320 } |
321 | |
322 return true; | |
323 } | |
324 | |
325 bool | |
326 octave_fcn_handle::load_ascii (std::istream& is) | |
327 { | |
6625 | 328 bool success = true; |
329 | |
330 std::streampos pos = is.tellg (); | |
331 std::string octaveroot = extract_keyword (is, "octaveroot", true); | |
332 if (octaveroot.length() == 0) | |
333 { | |
334 is.seekg (pos); | |
335 is.clear (); | |
336 } | |
337 pos = is.tellg (); | |
338 std::string fpath = extract_keyword (is, "path", true); | |
339 if (fpath.length() == 0) | |
340 { | |
341 is.seekg (pos); | |
342 is.clear (); | |
343 } | |
344 | |
4988 | 345 is >> nm; |
4989 | 346 |
4988 | 347 if (nm == "@<anonymous>") |
348 { | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
349 skip_preceeding_newline (is); |
4988 | 350 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
351 std::string buf; |
4988 | 352 |
353 if (is) | |
354 { | |
355 | |
356 // Get a line of text whitespace characters included, leaving | |
4989 | 357 // newline in the stream. |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
358 buf = read_until_newline (is, true); |
4989 | 359 |
4988 | 360 } |
361 | |
6625 | 362 pos = is.tellg (); |
7336 | 363 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
364 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
365 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
366 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
367 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
368 |
7336 | 369 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
370 unwind_protect::add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
371 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
372 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
373 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
374 octave_call_stack::push (local_scope, 0); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
375 unwind_protect::add_fcn (octave_call_stack::pop); |
4988 | 376 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
377 octave_idx_type len = 0; |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
378 |
6625 | 379 if (extract_keyword (is, "length", len, true) && len >= 0) |
4989 | 380 { |
6625 | 381 if (len > 0) |
382 { | |
383 for (octave_idx_type i = 0; i < len; i++) | |
384 { | |
385 octave_value t2; | |
386 bool dummy; | |
387 | |
388 std::string name | |
389 = read_ascii_data (is, std::string (), dummy, t2, i); | |
390 | |
391 if (!is) | |
392 { | |
393 error ("load: failed to load anonymous function handle"); | |
394 break; | |
395 } | |
396 | |
7901 | 397 symbol_table::varref (name, local_scope, 0) = t2; |
6625 | 398 } |
399 } | |
4989 | 400 } |
401 else | |
6625 | 402 { |
403 is.seekg (pos); | |
404 is.clear (); | |
405 } | |
406 | |
407 if (is && success) | |
408 { | |
409 int parse_status; | |
410 octave_value anon_fcn_handle = | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
411 eval_string (buf, true, parse_status); |
6625 | 412 |
413 if (parse_status == 0) | |
414 { | |
415 octave_fcn_handle *fh = | |
416 anon_fcn_handle.fcn_handle_value (); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
417 |
6625 | 418 if (fh) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
419 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
420 fcn = fh->fcn; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
421 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
422 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
423 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
424 if (uf) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
425 symbol_table::cache_name (uf->scope (), nm); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
426 } |
6625 | 427 else |
428 success = false; | |
429 } | |
430 else | |
431 success = false; | |
432 } | |
433 else | |
434 success = false; | |
435 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
436 unwind_protect::run_frame (uwp_frame); |
4988 | 437 } |
438 else | |
6625 | 439 success = set_fcn (octaveroot, fpath); |
4988 | 440 |
6625 | 441 return success; |
4988 | 442 } |
443 | |
444 bool | |
6625 | 445 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) |
4988 | 446 { |
447 if (nm == "@<anonymous>") | |
448 { | |
6625 | 449 std::ostringstream nmbuf; |
450 | |
7336 | 451 if (fcn.is_undefined ()) |
6625 | 452 return false; |
453 | |
454 octave_user_function *f = fcn.user_function_value (); | |
455 | |
7336 | 456 std::list<symbol_table::symbol_record> vars |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
457 = symbol_table::all_variables (f->scope (), 0); |
6625 | 458 |
7336 | 459 size_t varlen = vars.size (); |
6625 | 460 |
461 if (varlen > 0) | |
462 nmbuf << nm << " " << varlen; | |
463 else | |
464 nmbuf << nm; | |
465 | |
466 std::string buf_str = nmbuf.str(); | |
467 int32_t tmp = buf_str.length (); | |
468 os.write (reinterpret_cast<char *> (&tmp), 4); | |
469 os.write (buf_str.c_str (), buf_str.length ()); | |
470 | |
5765 | 471 std::ostringstream buf; |
4988 | 472 print_raw (buf, true); |
5765 | 473 std::string stmp = buf.str (); |
4988 | 474 tmp = stmp.length (); |
5760 | 475 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 476 os.write (stmp.c_str (), stmp.length ()); |
6625 | 477 |
478 if (varlen > 0) | |
479 { | |
7336 | 480 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
481 p != vars.end (); p++) | |
6625 | 482 { |
7336 | 483 if (! save_binary_data (os, p->varval (), p->name (), |
6625 | 484 "", 0, save_as_floats)) |
485 return os; | |
486 } | |
487 } | |
488 } | |
489 else | |
490 { | |
491 std::ostringstream nmbuf; | |
492 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
493 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
494 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
495 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
496 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm; |
6625 | 497 |
498 std::string buf_str = nmbuf.str (); | |
499 int32_t tmp = buf_str.length (); | |
500 os.write (reinterpret_cast<char *> (&tmp), 4); | |
501 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 502 } |
7336 | 503 |
4988 | 504 return true; |
505 } | |
506 | |
507 bool | |
508 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
6625 | 509 oct_mach_info::float_format fmt) |
4988 | 510 { |
6625 | 511 bool success = true; |
7336 | 512 |
5828 | 513 int32_t tmp; |
5760 | 514 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 515 return false; |
516 if (swap) | |
517 swap_bytes<4> (&tmp); | |
518 | |
519 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
8378
7d0492aa522d
fix use of uninitialized buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
520 is.get (ctmp1, tmp+1, 0); |
4988 | 521 nm = std::string (ctmp1); |
522 | |
523 if (! is) | |
524 return false; | |
525 | |
6625 | 526 if (nm.length() >= 12 && nm.substr (0, 12) == "@<anonymous>") |
4988 | 527 { |
6625 | 528 octave_idx_type len = 0; |
529 | |
530 if (nm.length() > 12) | |
531 { | |
532 std::istringstream nm_is (nm.substr(12)); | |
533 nm_is >> len; | |
534 nm = nm.substr(0,12); | |
535 } | |
536 | |
5760 | 537 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 538 return false; |
539 if (swap) | |
540 swap_bytes<4> (&tmp); | |
541 | |
542 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
8378
7d0492aa522d
fix use of uninitialized buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
543 is.get (ctmp2, tmp+1, 0); |
4988 | 544 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
545 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
546 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
547 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
548 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
549 |
7336 | 550 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
551 unwind_protect::add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
552 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
553 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
554 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
555 octave_call_stack::push (local_scope, 0); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
556 unwind_protect::add_fcn (octave_call_stack::pop); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
557 |
6625 | 558 if (len > 0) |
4989 | 559 { |
6625 | 560 for (octave_idx_type i = 0; i < len; i++) |
561 { | |
562 octave_value t2; | |
563 bool dummy; | |
564 std::string doc; | |
565 | |
566 std::string name = | |
567 read_binary_data (is, swap, fmt, std::string (), | |
568 dummy, t2, doc); | |
569 | |
570 if (!is) | |
571 { | |
572 error ("load: failed to load anonymous function handle"); | |
573 break; | |
574 } | |
575 | |
7336 | 576 symbol_table::varref (name, local_scope) = t2; |
6625 | 577 } |
578 } | |
579 | |
580 if (is && success) | |
581 { | |
582 int parse_status; | |
583 octave_value anon_fcn_handle = | |
584 eval_string (ctmp2, true, parse_status); | |
585 | |
586 if (parse_status == 0) | |
587 { | |
588 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
589 |
6625 | 590 if (fh) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
591 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
592 fcn = fh->fcn; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
593 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
594 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
595 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
596 if (uf) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
597 symbol_table::cache_name (uf->scope (), nm); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
598 } |
6625 | 599 else |
600 success = false; | |
601 } | |
4989 | 602 else |
6625 | 603 success = false; |
4989 | 604 } |
6625 | 605 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
606 unwind_protect::run_frame (uwp_frame); |
4988 | 607 } |
608 else | |
609 { | |
6625 | 610 std::string octaveroot; |
611 std::string fpath; | |
612 | |
8021 | 613 if (nm.find_first_of ("\n") != std::string::npos) |
6225 | 614 { |
6625 | 615 size_t pos1 = nm.find_first_of ("\n"); |
616 size_t pos2 = nm.find_first_of ("\n", pos1 + 1); | |
617 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); | |
618 fpath = nm.substr (pos2 + 1); | |
619 nm = nm.substr (0, pos1); | |
6225 | 620 } |
6625 | 621 |
622 success = set_fcn (octaveroot, fpath); | |
623 } | |
624 | |
625 return success; | |
4988 | 626 } |
627 | |
628 #if defined (HAVE_HDF5) | |
629 bool | |
630 octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, | |
6625 | 631 bool save_as_floats) |
4988 | 632 { |
7336 | 633 bool retval = true; |
634 | |
4988 | 635 hid_t group_hid = -1; |
636 group_hid = H5Gcreate (loc_id, name, 0); | |
7336 | 637 if (group_hid < 0) |
638 return false; | |
4988 | 639 |
640 hid_t space_hid = -1, data_hid = -1, type_hid = -1;; | |
641 | |
642 // attach the type of the variable | |
643 type_hid = H5Tcopy (H5T_C_S1); | |
644 H5Tset_size (type_hid, nm.length () + 1); | |
645 if (type_hid < 0) | |
646 { | |
647 H5Gclose (group_hid); | |
648 return false; | |
649 } | |
650 | |
651 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
652 hdims[0] = 0; | |
653 hdims[1] = 0; | |
5760 | 654 space_hid = H5Screate_simple (0 , hdims, 0); |
4988 | 655 if (space_hid < 0) |
656 { | |
657 H5Tclose (type_hid); | |
658 H5Gclose (group_hid); | |
659 return false; | |
660 } | |
661 | |
662 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); | |
663 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, | |
5760 | 664 H5P_DEFAULT, nm.c_str ()) < 0) |
4988 | 665 { |
666 H5Sclose (space_hid); | |
667 H5Tclose (type_hid); | |
668 H5Gclose (group_hid); | |
669 return false; | |
670 } | |
671 H5Dclose (data_hid); | |
672 | |
673 if (nm == "@<anonymous>") | |
674 { | |
5765 | 675 std::ostringstream buf; |
4988 | 676 print_raw (buf, true); |
5765 | 677 std::string stmp = buf.str (); |
4988 | 678 |
679 // attach the type of the variable | |
680 H5Tset_size (type_hid, stmp.length () + 1); | |
681 if (type_hid < 0) | |
682 { | |
6695 | 683 H5Sclose (space_hid); |
4988 | 684 H5Gclose (group_hid); |
685 return false; | |
686 } | |
687 | |
688 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, | |
689 H5P_DEFAULT); | |
690 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, | |
5760 | 691 H5P_DEFAULT, stmp.c_str ()) < 0) |
4988 | 692 { |
693 H5Sclose (space_hid); | |
694 H5Tclose (type_hid); | |
695 H5Gclose (group_hid); | |
696 return false; | |
697 } | |
698 | |
699 H5Dclose (data_hid); | |
6625 | 700 |
701 octave_user_function *f = fcn.user_function_value (); | |
702 | |
7336 | 703 std::list<symbol_table::symbol_record> vars |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
704 = symbol_table::all_variables (f->scope (), 0); |
7336 | 705 |
706 size_t varlen = vars.size (); | |
6625 | 707 |
708 if (varlen > 0) | |
709 { | |
710 hid_t as_id = H5Screate (H5S_SCALAR); | |
711 | |
712 if (as_id >= 0) | |
713 { | |
714 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", | |
715 H5T_NATIVE_IDX, as_id, H5P_DEFAULT); | |
716 | |
717 if (a_id >= 0) | |
718 { | |
719 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); | |
720 | |
721 H5Aclose (a_id); | |
722 } | |
723 else | |
724 retval = false; | |
725 | |
726 H5Sclose (as_id); | |
727 } | |
728 else | |
729 retval = false; | |
730 | |
731 data_hid = H5Gcreate (group_hid, "symbol table", 0); | |
732 if (data_hid < 0) | |
733 { | |
734 H5Sclose (space_hid); | |
735 H5Tclose (type_hid); | |
736 H5Gclose (group_hid); | |
737 return false; | |
738 } | |
739 | |
7336 | 740 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
741 p != vars.end (); p++) | |
6625 | 742 { |
7336 | 743 if (! add_hdf5_data (data_hid, p->varval (), p->name (), |
6625 | 744 "", false, save_as_floats)) |
745 break; | |
746 } | |
747 H5Gclose (data_hid); | |
748 } | |
749 } | |
750 else | |
751 { | |
752 std::string octaveroot = OCTAVE_EXEC_PREFIX; | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
753 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
754 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
755 std::string fpath = f ? f->fcn_file_name () : std::string (); |
6625 | 756 |
757 H5Sclose (space_hid); | |
758 hdims[0] = 1; | |
759 hdims[1] = octaveroot.length (); | |
760 space_hid = H5Screate_simple (0 , hdims, 0); | |
761 if (space_hid < 0) | |
762 { | |
763 H5Tclose (type_hid); | |
764 H5Gclose (group_hid); | |
765 return false; | |
766 } | |
767 | |
768 H5Tclose (type_hid); | |
769 type_hid = H5Tcopy (H5T_C_S1); | |
770 H5Tset_size (type_hid, octaveroot.length () + 1); | |
771 | |
772 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", | |
773 type_hid, space_hid, H5P_DEFAULT); | |
774 | |
775 if (a_id >= 0) | |
776 { | |
777 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); | |
778 | |
779 H5Aclose (a_id); | |
780 } | |
781 else | |
6695 | 782 { |
783 H5Sclose (space_hid); | |
784 H5Tclose (type_hid); | |
785 H5Gclose (group_hid); | |
786 return false; | |
787 } | |
6625 | 788 |
789 H5Sclose (space_hid); | |
790 hdims[0] = 1; | |
791 hdims[1] = fpath.length (); | |
792 space_hid = H5Screate_simple (0 , hdims, 0); | |
793 if (space_hid < 0) | |
794 { | |
795 H5Tclose (type_hid); | |
796 H5Gclose (group_hid); | |
797 return false; | |
798 } | |
799 | |
800 H5Tclose (type_hid); | |
801 type_hid = H5Tcopy (H5T_C_S1); | |
802 H5Tset_size (type_hid, fpath.length () + 1); | |
803 | |
804 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, H5P_DEFAULT); | |
805 | |
806 if (a_id >= 0) | |
807 { | |
808 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); | |
809 | |
810 H5Aclose (a_id); | |
811 } | |
812 else | |
813 retval = false; | |
4988 | 814 } |
815 | |
816 H5Sclose (space_hid); | |
817 H5Tclose (type_hid); | |
818 H5Gclose (group_hid); | |
819 | |
820 return retval; | |
821 } | |
822 | |
823 bool | |
824 octave_fcn_handle::load_hdf5 (hid_t loc_id, const char *name, | |
6625 | 825 bool have_h5giterate_bug) |
4988 | 826 { |
7336 | 827 bool success = true; |
828 | |
4988 | 829 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
830 hsize_t rank; | |
831 int slen; | |
832 | |
833 group_hid = H5Gopen (loc_id, name); | |
7336 | 834 if (group_hid < 0) |
835 return false; | |
4988 | 836 |
837 data_hid = H5Dopen (group_hid, "nm"); | |
838 | |
839 if (data_hid < 0) | |
840 { | |
841 H5Gclose (group_hid); | |
842 return false; | |
843 } | |
844 | |
845 type_hid = H5Dget_type (data_hid); | |
846 type_class_hid = H5Tget_class (type_hid); | |
847 | |
848 if (type_class_hid != H5T_STRING) | |
849 { | |
850 H5Tclose (type_hid); | |
851 H5Dclose (data_hid); | |
852 H5Gclose (group_hid); | |
853 return false; | |
854 } | |
855 | |
856 space_hid = H5Dget_space (data_hid); | |
857 rank = H5Sget_simple_extent_ndims (space_hid); | |
858 | |
859 if (rank != 0) | |
860 { | |
861 H5Sclose (space_hid); | |
862 H5Tclose (type_hid); | |
863 H5Dclose (data_hid); | |
864 H5Gclose (group_hid); | |
865 return false; | |
866 } | |
867 | |
868 slen = H5Tget_size (type_hid); | |
869 if (slen < 0) | |
870 { | |
871 H5Sclose (space_hid); | |
872 H5Tclose (type_hid); | |
873 H5Dclose (data_hid); | |
874 H5Gclose (group_hid); | |
875 return false; | |
876 } | |
877 | |
878 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
879 | |
880 // create datatype for (null-terminated) string to read into: | |
881 st_id = H5Tcopy (H5T_C_S1); | |
882 H5Tset_size (st_id, slen); | |
883 | |
5760 | 884 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4988 | 885 { |
6695 | 886 H5Tclose (st_id); |
4988 | 887 H5Sclose (space_hid); |
888 H5Tclose (type_hid); | |
6695 | 889 H5Dclose (data_hid); |
4988 | 890 H5Gclose (group_hid); |
891 return false; | |
892 } | |
893 H5Tclose (st_id); | |
894 H5Dclose (data_hid); | |
895 nm = nm_tmp; | |
896 | |
897 if (nm == "@<anonymous>") | |
898 { | |
899 data_hid = H5Dopen (group_hid, "fcn"); | |
900 | |
901 if (data_hid < 0) | |
902 { | |
6695 | 903 H5Sclose (space_hid); |
904 H5Tclose (type_hid); | |
4988 | 905 H5Gclose (group_hid); |
906 return false; | |
907 } | |
908 | |
6695 | 909 H5Tclose (type_hid); |
4988 | 910 type_hid = H5Dget_type (data_hid); |
911 type_class_hid = H5Tget_class (type_hid); | |
912 | |
913 if (type_class_hid != H5T_STRING) | |
914 { | |
6695 | 915 H5Sclose (space_hid); |
4988 | 916 H5Tclose (type_hid); |
917 H5Dclose (data_hid); | |
918 H5Gclose (group_hid); | |
919 return false; | |
920 } | |
921 | |
6695 | 922 H5Sclose (space_hid); |
4988 | 923 space_hid = H5Dget_space (data_hid); |
924 rank = H5Sget_simple_extent_ndims (space_hid); | |
925 | |
926 if (rank != 0) | |
927 { | |
928 H5Sclose (space_hid); | |
929 H5Tclose (type_hid); | |
930 H5Dclose (data_hid); | |
931 H5Gclose (group_hid); | |
932 return false; | |
933 } | |
934 | |
935 slen = H5Tget_size (type_hid); | |
936 if (slen < 0) | |
937 { | |
938 H5Sclose (space_hid); | |
939 H5Tclose (type_hid); | |
940 H5Dclose (data_hid); | |
941 H5Gclose (group_hid); | |
942 return false; | |
943 } | |
944 | |
945 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
946 | |
947 // create datatype for (null-terminated) string to read into: | |
948 st_id = H5Tcopy (H5T_C_S1); | |
949 H5Tset_size (st_id, slen); | |
950 | |
5760 | 951 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) |
4988 | 952 { |
6695 | 953 H5Tclose (st_id); |
4988 | 954 H5Sclose (space_hid); |
955 H5Tclose (type_hid); | |
6695 | 956 H5Dclose (data_hid); |
4988 | 957 H5Gclose (group_hid); |
958 return false; | |
959 } | |
6695 | 960 H5Tclose (st_id); |
4988 | 961 H5Dclose (data_hid); |
6625 | 962 |
963 octave_idx_type len = 0; | |
964 | |
965 // we have to pull some shenanigans here to make sure | |
966 // HDF5 doesn't print out all sorts of error messages if we | |
967 // call H5Aopen for a non-existing attribute | |
968 | |
969 H5E_auto_t err_func; | |
970 void *err_func_data; | |
4988 | 971 |
6625 | 972 // turn off error reporting temporarily, but save the error |
973 // reporting function: | |
974 H5Eget_auto (&err_func, &err_func_data); | |
975 H5Eset_auto (0, 0); | |
976 | |
977 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 978 |
6625 | 979 if (attr_id >= 0) |
980 { | |
981 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) | |
982 success = false; | |
983 | |
984 H5Aclose (attr_id); | |
985 } | |
986 | |
987 // restore error reporting: | |
988 H5Eset_auto (err_func, err_func_data); | |
989 | |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
990 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame (); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
991 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
992 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
993 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
994 |
7336 | 995 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
996 unwind_protect::add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
997 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
998 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
999 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1000 octave_call_stack::push (local_scope, 0); |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9395
diff
changeset
|
1001 unwind_protect::add_fcn (octave_call_stack::pop); |
7336 | 1002 |
6625 | 1003 if (len > 0 && success) |
4989 | 1004 { |
6625 | 1005 #ifdef HAVE_H5GGET_NUM_OBJS |
1006 hsize_t num_obj = 0; | |
1007 data_hid = H5Gopen (group_hid, "symbol table"); | |
1008 H5Gget_num_objs (data_hid, &num_obj); | |
1009 H5Gclose (data_hid); | |
1010 | |
1011 if (num_obj != static_cast<hsize_t>(len)) | |
1012 { | |
1013 error ("load: failed to load anonymous function handle"); | |
1014 success = false; | |
1015 } | |
1016 #endif | |
1017 | |
1018 if (! error_state) | |
1019 { | |
1020 hdf5_callback_data dsub; | |
1021 int current_item = 0; | |
1022 for (octave_idx_type i = 0; i < len; i++) | |
1023 { | |
1024 if (H5Giterate (group_hid, "symbol table", ¤t_item, | |
1025 hdf5_read_next_data, &dsub) <= 0) | |
1026 { | |
1027 error ("load: failed to load anonymous function handle"); | |
1028 success = false; | |
1029 break; | |
1030 } | |
1031 | |
1032 if (have_h5giterate_bug) | |
1033 current_item++; // H5Giterate returns last index processed | |
1034 | |
7336 | 1035 symbol_table::varref (dsub.name, local_scope) = dsub.tc; |
6625 | 1036 } |
1037 } | |
1038 } | |
1039 | |
1040 if (success) | |
1041 { | |
1042 int parse_status; | |
1043 octave_value anon_fcn_handle = | |
1044 eval_string (fcn_tmp, true, parse_status); | |
1045 | |
1046 if (parse_status == 0) | |
1047 { | |
1048 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1049 |
6625 | 1050 if (fh) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1051 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1052 fcn = fh->fcn; |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1053 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1054 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1055 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1056 if (uf) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1057 symbol_table::cache_name (uf->scope (), nm); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1058 } |
6625 | 1059 else |
1060 success = false; | |
1061 } | |
4989 | 1062 else |
6625 | 1063 success = false; |
4989 | 1064 } |
6625 | 1065 |
9377
610bf90fce2a
update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents:
9343
diff
changeset
|
1066 unwind_protect::run_frame (uwp_frame); |
4988 | 1067 } |
1068 else | |
1069 { | |
6625 | 1070 std::string octaveroot; |
1071 std::string fpath; | |
1072 | |
1073 // we have to pull some shenanigans here to make sure | |
1074 // HDF5 doesn't print out all sorts of error messages if we | |
1075 // call H5Aopen for a non-existing attribute | |
1076 | |
1077 H5E_auto_t err_func; | |
1078 void *err_func_data; | |
1079 | |
1080 // turn off error reporting temporarily, but save the error | |
1081 // reporting function: | |
1082 H5Eget_auto (&err_func, &err_func_data); | |
1083 H5Eset_auto (0, 0); | |
1084 | |
1085 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1086 if (attr_id >= 0) | |
6225 | 1087 { |
6695 | 1088 H5Tclose (type_hid); |
6625 | 1089 type_hid = H5Aget_type (attr_id); |
1090 type_class_hid = H5Tget_class (type_hid); | |
1091 | |
1092 if (type_class_hid != H5T_STRING) | |
1093 success = false; | |
1094 else | |
1095 { | |
1096 slen = H5Tget_size (type_hid); | |
1097 st_id = H5Tcopy (H5T_C_S1); | |
1098 H5Tset_size (st_id, slen); | |
1099 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); | |
1100 | |
1101 if (H5Aread (attr_id, st_id, root_tmp) < 0) | |
1102 success = false; | |
1103 else | |
1104 octaveroot = root_tmp; | |
6695 | 1105 |
1106 H5Tclose (st_id); | |
6625 | 1107 } |
1108 | |
1109 H5Aclose (attr_id); | |
6225 | 1110 } |
6625 | 1111 |
6695 | 1112 if (success) |
6625 | 1113 { |
6695 | 1114 attr_id = H5Aopen_name (group_hid, "FILE"); |
1115 if (attr_id >= 0) | |
1116 { | |
1117 H5Tclose (type_hid); | |
1118 type_hid = H5Aget_type (attr_id); | |
1119 type_class_hid = H5Tget_class (type_hid); | |
6625 | 1120 |
6695 | 1121 if (type_class_hid != H5T_STRING) |
6625 | 1122 success = false; |
1123 else | |
6695 | 1124 { |
1125 slen = H5Tget_size (type_hid); | |
1126 st_id = H5Tcopy (H5T_C_S1); | |
1127 H5Tset_size (st_id, slen); | |
1128 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); | |
1129 | |
1130 if (H5Aread (attr_id, st_id, path_tmp) < 0) | |
1131 success = false; | |
1132 else | |
1133 fpath = path_tmp; | |
1134 | |
1135 H5Tclose (st_id); | |
1136 } | |
1137 | |
1138 H5Aclose (attr_id); | |
6625 | 1139 } |
1140 } | |
1141 | |
1142 // restore error reporting: | |
1143 H5Eset_auto (err_func, err_func_data); | |
1144 | |
1145 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1146 } |
1147 | |
6695 | 1148 H5Tclose (type_hid); |
1149 H5Sclose (space_hid); | |
1150 H5Gclose (group_hid); | |
1151 | |
6625 | 1152 return success; |
4988 | 1153 } |
6625 | 1154 |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1155 #endif |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1156 |
6625 | 1157 /* |
1158 | |
1159 %!test | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1160 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1161 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1162 %! g = @(x) 2 * x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1163 %! hm = @flops; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1164 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1165 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1166 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1167 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1168 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1169 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1170 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1171 %! modes = {"-text", "-binary"}; |
6625 | 1172 %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_HDF5"))) |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1173 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1174 %! endif |
7901 | 1175 %! for i = 1:numel (modes) |
1176 %! mode = modes{i}; | |
6625 | 1177 %! nm = tmpnam(); |
1178 %! unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1179 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1180 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1181 %! load (nm); |
1182 %! assert (f(2),f2(2)); | |
1183 %! assert (g(2),g2(2)); | |
1184 %! assert (g(3),g2(3)); | |
1185 %! unlink (nm); | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1186 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1187 %! unwind_protect_cleanup |
1188 %! unlink (nm); | |
1189 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1190 %! endfor |
6625 | 1191 |
1192 */ | |
4988 | 1193 |
4343 | 1194 void |
1195 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const | |
1196 { | |
1197 print_raw (os, pr_as_read_syntax); | |
1198 newline (os); | |
1199 } | |
1200 | |
1201 void | |
1202 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1203 { | |
4980 | 1204 bool printed = false; |
1205 | |
1206 if (nm == "@<anonymous>") | |
1207 { | |
1208 tree_print_code tpc (os); | |
1209 | |
4989 | 1210 // FCN is const because this member function is, so we can't |
4980 | 1211 // use it to call user_function_value, so we make a copy first. |
1212 | |
1213 octave_value ftmp = fcn; | |
1214 | |
1215 octave_user_function *f = ftmp.user_function_value (); | |
1216 | |
1217 if (f) | |
1218 { | |
1219 tree_parameter_list *p = f->parameter_list (); | |
1220 | |
1221 os << "@("; | |
1222 | |
1223 if (p) | |
1224 p->accept (tpc); | |
1225 | |
1226 os << ") "; | |
1227 | |
1228 tree_statement_list *b = f->body (); | |
1229 | |
1230 if (b) | |
1231 { | |
1232 assert (b->length () == 1); | |
1233 | |
1234 tree_statement *s = b->front (); | |
1235 | |
1236 if (s) | |
1237 { | |
1238 if (s->is_expression ()) | |
1239 { | |
1240 tree_expression *e = s->expression (); | |
1241 | |
1242 if (e) | |
6657 | 1243 e->accept (tpc); |
4980 | 1244 } |
1245 else | |
1246 { | |
1247 tree_command *c = s->command (); | |
1248 | |
1249 tpc.suspend_newline (); | |
1250 c->accept (tpc); | |
1251 tpc.resume_newline (); | |
1252 } | |
1253 } | |
1254 } | |
1255 | |
1256 printed = true; | |
1257 } | |
1258 } | |
1259 | |
1260 if (! printed) | |
1261 octave_print_internal (os, nm, pr_as_read_syntax, | |
1262 current_print_indent_level ()); | |
4343 | 1263 } |
1264 | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1265 static string_vector |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1266 get_builtin_classes (void) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1267 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1268 // FIXME: this should really be read from somewhere else. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1269 static const char *cnames[15] = { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1270 "double", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1271 "single", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1272 "int8", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1273 "int16", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1274 "int32", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1275 "int64", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1276 "uint8", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1277 "uint16", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1278 "uint32", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1279 "uint64", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1280 "logical", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1281 "char", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1282 "cell", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1283 "struct", |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1284 "function_handle" |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1285 }; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1286 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1287 static string_vector retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1288 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1289 if (retval.is_empty ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1290 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1291 retval = string_vector (15); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1292 for (int i = 0; i < 15; i++) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1293 retval(i) = cnames[i]; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1294 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1295 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1296 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1297 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1298 |
4343 | 1299 octave_value |
1300 make_fcn_handle (const std::string& nm) | |
1301 { | |
1302 octave_value retval; | |
1303 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1304 // Bow to the god of compatibility. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1305 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1306 // FIXME -- it seems ugly to put this here, but there is no single |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1307 // function in the parser that converts from the operator name to |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1308 // the corresponding function name. At least try to do it without N |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1309 // string compares. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1310 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1311 std::string tnm = nm; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1312 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1313 size_t len = nm.length (); |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1314 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1315 if (len == 3 && nm == ".**") |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1316 tnm = "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1317 else if (len == 2) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1318 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1319 if (nm[0] == '.') |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1320 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1321 switch (nm[1]) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1322 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1323 case '\'': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1324 tnm = "transpose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1325 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1326 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1327 case '+': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1328 tnm = "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1329 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1330 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1331 case '-': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1332 tnm = "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1333 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1334 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1335 case '*': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1336 tnm = "times"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1337 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1338 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1339 case '/': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1340 tnm = "rdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1341 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1342 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1343 case '^': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1344 tnm = "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1345 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1346 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1347 case '\\': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1348 tnm = "ldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1349 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1350 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1351 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1352 else if (nm[1] == '=') |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1353 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1354 switch (nm[0]) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1355 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1356 case '<': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1357 tnm = "le"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1358 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1359 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1360 case '=': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1361 tnm = "eq"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1362 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1363 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1364 case '>': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1365 tnm = "ge"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1366 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1367 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1368 case '~': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1369 case '!': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1370 tnm = "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1371 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1372 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1373 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1374 else if (nm == "**") |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1375 tnm = "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1376 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1377 else if (len == 1) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1378 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1379 switch (nm[0]) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1380 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1381 case '~': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1382 case '!': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1383 tnm = "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1384 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1385 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1386 case '\'': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1387 tnm = "ctranspose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1388 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1389 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1390 case '+': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1391 tnm = "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1392 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1393 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1394 case '-': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1395 tnm = "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1396 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1397 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1398 case '*': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1399 tnm = "mtimes"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1400 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1401 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1402 case '/': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1403 tnm = "mrdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1404 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1405 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1406 case '^': |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1407 tnm = "mpower"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1408 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1409 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1410 case '\\': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1411 tnm = "mldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1412 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1413 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1414 case '<': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1415 tnm = "lt"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1416 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1417 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1418 case '>': |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1419 tnm = "gt"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1420 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1421 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1422 case '&': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1423 tnm = "and"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1424 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1425 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1426 case '|': |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1427 tnm = "or"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1428 break; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1429 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1430 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1431 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1432 octave_value f = symbol_table::find_function (tnm); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1433 octave_function *fptr = f.is_defined () ? f.function_value () : 0; |
6481 | 1434 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1435 if (fptr) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1436 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1437 // If it's a subfunction, private function, or class constructor, |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1438 // we want no dispatch. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1439 if (fptr->is_nested_function () || fptr->is_private_function () |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1440 || fptr->is_class_constructor ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1441 retval = octave_value (new octave_fcn_handle (f, tnm)); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1442 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1443 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1444 typedef octave_fcn_handle::str_ov_map str_ov_map; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1445 std::auto_ptr<str_ov_map> disp (new str_ov_map); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1446 const string_vector cnames = get_builtin_classes (); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1447 for (octave_idx_type i = 0; i < cnames.length (); i++) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1448 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1449 std::string cnam = cnames(i); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1450 octave_value method = symbol_table::find_method (tnm, cnam); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1451 if (method.is_defined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1452 (*disp)[cnam] = method; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1453 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1454 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1455 retval = octave_value (new octave_fcn_handle (f, tnm, disp.release ())); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1456 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1457 } |
9419
0dd3c7a2ba19
undo escaped change in previous patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9418
diff
changeset
|
1458 else |
0dd3c7a2ba19
undo escaped change in previous patch
Jaroslav Hajek <highegg@gmail.com>
parents:
9418
diff
changeset
|
1459 error ("error creating function handle \"@%s\"", nm.c_str ()); |
4343 | 1460 |
1461 return retval; | |
1462 } | |
1463 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1464 /* |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1465 %!test |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1466 %! x = {".**", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1467 %! ".'", "transpose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1468 %! ".+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1469 %! ".-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1470 %! ".*", "times"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1471 %! "./", "rdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1472 %! ".^", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1473 %! ".\\", "ldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1474 %! "<=", "le"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1475 %! "==", "eq"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1476 %! ">=", "ge"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1477 %! "~=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1478 %! "!=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1479 %! "**", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1480 %! "~", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1481 %! "!", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1482 %! "\'", "ctranspose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1483 %! "+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1484 %! "-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1485 %! "*", "mtimes"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1486 %! "/", "mrdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1487 %! "^", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1488 %! "\\", "mldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1489 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1490 %! ">", "gt"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1491 %! "&", "and"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1492 %! "|", "or"}; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1493 %! for i = 1:rows (x) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1494 %! assert (functions (str2func (x{i,1})).function, x{i,2}) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1495 %! endfor |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1496 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1497 |
4933 | 1498 DEFUN (functions, args, , |
4343 | 1499 "-*- texinfo -*-\n\ |
4933 | 1500 @deftypefn {Built-in Function} {} functions (@var{fcn_handle})\n\ |
1501 Return a struct containing information about the function handle\n\ | |
1502 @var{fcn_handle}.\n\ | |
1503 @end deftypefn") | |
4343 | 1504 { |
1505 octave_value retval; | |
1506 | |
4933 | 1507 if (args.length () == 1) |
4343 | 1508 { |
4933 | 1509 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4343 | 1510 |
1511 if (! error_state) | |
1512 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1513 octave_function *fcn = fh ? fh->function_value () : 0; |
4343 | 1514 |
4933 | 1515 if (fcn) |
4930 | 1516 { |
4933 | 1517 Octave_map m; |
4649 | 1518 |
4933 | 1519 std::string fh_nm = fh->fcn_name (); |
1520 | |
6625 | 1521 if (fh_nm == "@<anonymous>") |
1522 { | |
1523 std::ostringstream buf; | |
1524 fh->print_raw (buf); | |
1525 m.assign ("function", buf.str ()); | |
1526 | |
1527 m.assign ("type", "anonymous"); | |
1528 } | |
1529 else | |
1530 { | |
1531 m.assign ("function", fh_nm); | |
4343 | 1532 |
6625 | 1533 if (fcn->is_nested_function ()) |
1534 { | |
1535 m.assign ("type", "subfunction"); | |
1536 Cell parentage (dim_vector (1, 2)); | |
1537 parentage.elem(0) = fh_nm; | |
1538 parentage.elem(1) = fcn->parent_fcn_name (); | |
7756
45de7d8dac72
ov-fcn-handle.cc (Ffunctions): fix structure assignment
John W. Eaton <jwe@octave.org>
parents:
7745
diff
changeset
|
1539 m.assign ("parentage", octave_value (parentage)); |
6625 | 1540 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1541 else if (fh->is_overloaded ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1542 m.assign ("type", "overloaded"); |
6625 | 1543 else |
1544 m.assign ("type", "simple"); | |
1545 } | |
4933 | 1546 |
1547 std::string nm = fcn->fcn_file_name (); | |
4343 | 1548 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1549 if (fh_nm == "@<anonymous>") |
4935 | 1550 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1551 m.assign ("file", nm); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1552 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1553 octave_user_function *fu = fh->user_function_value (); |
6625 | 1554 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1555 std::list<symbol_table::symbol_record> vars |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1556 = symbol_table::all_variables (fu->scope (), 0); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1557 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1558 size_t varlen = vars.size (); |
6625 | 1559 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1560 if (varlen > 0) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1561 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1562 Octave_map ws; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1563 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1564 p != vars.end (); p++) |
6625 | 1565 { |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1566 ws.assign (p->name (), p->varval (0)); |
6625 | 1567 } |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1568 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1569 m.assign ("workspace", ws); |
6625 | 1570 } |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1571 } |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1572 else if (fcn->is_user_function () || fcn->is_user_script ()) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1573 { |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1574 octave_function *fu = fh->function_value (); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1575 m.assign ("file", fu->fcn_file_name ()); |
4935 | 1576 } |
4343 | 1577 else |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1578 m.assign ("file", ""); |
4933 | 1579 |
1580 retval = m; | |
4343 | 1581 } |
1582 else | |
4933 | 1583 error ("functions: invalid function handle object"); |
4343 | 1584 } |
1585 else | |
4933 | 1586 error ("functions: argument must be a function handle object"); |
4343 | 1587 } |
1588 else | |
5823 | 1589 print_usage (); |
4343 | 1590 |
1591 return retval; | |
1592 } | |
1593 | |
4933 | 1594 DEFUN (func2str, args, , |
4343 | 1595 "-*- texinfo -*-\n\ |
4933 | 1596 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\ |
1597 Return a string containing the name of the function referenced by\n\ | |
1598 the function handle @var{fcn_handle}.\n\ | |
1599 @end deftypefn") | |
4343 | 1600 { |
1601 octave_value retval; | |
1602 | |
4933 | 1603 if (args.length () == 1) |
4930 | 1604 { |
4933 | 1605 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4930 | 1606 |
4933 | 1607 if (! error_state && fh) |
1608 { | |
1609 std::string fh_nm = fh->fcn_name (); | |
6416 | 1610 |
1611 if (fh_nm == "@<anonymous>") | |
1612 { | |
1613 std::ostringstream buf; | |
1614 | |
1615 fh->print_raw (buf); | |
1616 | |
1617 retval = buf.str (); | |
1618 } | |
1619 else | |
1620 retval = fh_nm; | |
4933 | 1621 } |
4343 | 1622 else |
4933 | 1623 error ("func2str: expecting valid function handle as first argument"); |
4343 | 1624 } |
1625 else | |
5823 | 1626 print_usage (); |
4343 | 1627 |
1628 return retval; | |
1629 } | |
1630 | |
4933 | 1631 DEFUN (str2func, args, , |
4343 | 1632 "-*- texinfo -*-\n\ |
4933 | 1633 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\ |
1634 Return a function handle constructed from the string @var{fcn_name}.\n\ | |
1635 @end deftypefn") | |
4343 | 1636 { |
1637 octave_value retval; | |
1638 | |
4933 | 1639 if (args.length () == 1) |
4343 | 1640 { |
4933 | 1641 std::string nm = args(0).string_value (); |
4343 | 1642 |
4933 | 1643 if (! error_state) |
1644 retval = make_fcn_handle (nm); | |
4343 | 1645 else |
4933 | 1646 error ("str2func: expecting string as first argument"); |
4343 | 1647 } |
1648 else | |
5823 | 1649 print_usage (); |
4343 | 1650 |
1651 return retval; | |
1652 } | |
1653 | |
1654 /* | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1655 %!function y = testrecursionfunc (f, x, n) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1656 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1657 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1658 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1659 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1660 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1661 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1662 %! n++; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1663 %! y = testrecursionfunc (@(x) f(2*x), x, n); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1664 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1665 %!test |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1666 %! assert (testrecursionfunc (@(x) x, 1), 8); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1667 */ |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1668 |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1669 /* |
4343 | 1670 ;;; Local Variables: *** |
1671 ;;; mode: C++ *** | |
1672 ;;; End: *** | |
1673 */ |