2974
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2974
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "str-vec.h" |
|
32 |
|
33 #include <defaults.h> |
3974
|
34 #include "Cell.h" |
2974
|
35 #include "defun.h" |
|
36 #include "error.h" |
|
37 #include "input.h" |
|
38 #include "oct-obj.h" |
|
39 #include "ov-usr-fcn.h" |
|
40 #include "ov.h" |
|
41 #include "pager.h" |
2985
|
42 #include "pt-jump.h" |
2974
|
43 #include "pt-misc.h" |
|
44 #include "pt-pr-code.h" |
2982
|
45 #include "pt-stmt.h" |
2974
|
46 #include "pt-walk.h" |
|
47 #include "symtab.h" |
|
48 #include "toplev.h" |
|
49 #include "unwind-prot.h" |
|
50 #include "utils.h" |
3489
|
51 #include "parse.h" |
2974
|
52 #include "variables.h" |
|
53 |
3131
|
54 // Maximum nesting level for functions called recursively. |
|
55 static int Vmax_recursion_depth; |
|
56 |
2974
|
57 // User defined functions. |
|
58 |
3219
|
59 DEFINE_OCTAVE_ALLOCATOR (octave_user_function); |
2974
|
60 |
3219
|
61 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_function, |
4612
|
62 "user-defined function", |
3219
|
63 "user-defined function"); |
2974
|
64 |
|
65 // Ugh. This really needs to be simplified (code/data? |
|
66 // extrinsic/intrinsic state?). |
|
67 |
|
68 octave_user_function::octave_user_function |
|
69 (tree_parameter_list *pl, tree_parameter_list *rl, |
|
70 tree_statement_list *cl, symbol_table *st) |
3523
|
71 : octave_function (std::string (), std::string ()), |
2974
|
72 param_list (pl), ret_list (rl), cmd_list (cl), |
3665
|
73 sym_tab (st), lead_comm (), trail_comm (), |
|
74 file_name (), fcn_name (), |
3255
|
75 t_parsed (static_cast<time_t> (0)), |
|
76 t_checked (static_cast<time_t> (0)), |
|
77 system_fcn_file (false), call_depth (0), |
4238
|
78 num_named_args (0), nested_function (false), |
|
79 args_passed (), num_args_passed (0), |
3165
|
80 curr_va_arg_number (0), vr_list (0), symtab_entry (0), |
3974
|
81 argn_sr (0), nargin_sr (0), nargout_sr (0), varargin_sr (0) |
2974
|
82 { |
|
83 install_automatic_vars (); |
|
84 |
|
85 if (param_list) |
|
86 { |
|
87 num_named_args = param_list->length (); |
|
88 curr_va_arg_number = num_named_args; |
|
89 } |
|
90 } |
|
91 |
|
92 octave_user_function::~octave_user_function (void) |
|
93 { |
|
94 delete param_list; |
|
95 delete ret_list; |
|
96 delete sym_tab; |
|
97 delete cmd_list; |
|
98 delete vr_list; |
3665
|
99 delete lead_comm; |
|
100 delete trail_comm; |
2974
|
101 } |
|
102 |
|
103 octave_user_function * |
|
104 octave_user_function::define_ret_list (tree_parameter_list *t) |
|
105 { |
|
106 ret_list = t; |
|
107 |
|
108 if (ret_list && ret_list->takes_varargs ()) |
|
109 vr_list = new tree_va_return_list; |
|
110 |
|
111 return this; |
|
112 } |
|
113 |
|
114 void |
4343
|
115 octave_user_function::stash_fcn_file_name (const std::string& nm) |
2974
|
116 { |
4343
|
117 file_name = nm; |
2974
|
118 } |
|
119 |
|
120 void |
|
121 octave_user_function::mark_as_system_fcn_file (void) |
|
122 { |
|
123 if (! file_name.empty ()) |
|
124 { |
|
125 // We really should stash the whole path to the file we found, |
|
126 // when we looked it up, to avoid possible race conditions... |
|
127 // XXX FIXME XXX |
|
128 // |
|
129 // We probably also don't need to get the library directory |
|
130 // every time, but since this function is only called when the |
|
131 // function file is parsed, it probably doesn't matter that |
|
132 // much. |
|
133 |
3523
|
134 std::string ff_name = fcn_file_in_path (file_name); |
2974
|
135 |
3565
|
136 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) |
2974
|
137 system_fcn_file = 1; |
|
138 } |
|
139 else |
|
140 system_fcn_file = 0; |
|
141 } |
|
142 |
|
143 bool |
|
144 octave_user_function::takes_varargs (void) const |
|
145 { |
|
146 return (param_list && param_list->takes_varargs ()); |
|
147 } |
|
148 |
|
149 octave_value |
|
150 octave_user_function::octave_va_arg (void) |
|
151 { |
|
152 octave_value retval; |
|
153 |
|
154 if (curr_va_arg_number < num_args_passed) |
|
155 retval = args_passed (curr_va_arg_number++); |
|
156 else |
|
157 ::error ("va_arg: error getting arg number %d -- only %d provided", |
|
158 curr_va_arg_number + 1, num_args_passed); |
|
159 |
|
160 return retval; |
|
161 } |
|
162 |
|
163 octave_value_list |
|
164 octave_user_function::octave_all_va_args (void) |
|
165 { |
|
166 octave_value_list retval; |
|
167 |
3178
|
168 int n = num_args_passed - num_named_args; |
2974
|
169 |
3178
|
170 if (n > 0) |
|
171 { |
|
172 retval.resize (n); |
|
173 |
|
174 int k = 0; |
|
175 for (int i = num_named_args; i < num_args_passed; i++) |
|
176 retval(k++) = args_passed(i); |
|
177 } |
2974
|
178 |
|
179 return retval; |
|
180 } |
|
181 |
|
182 bool |
|
183 octave_user_function::takes_var_return (void) const |
|
184 { |
|
185 return (ret_list && ret_list->takes_varargs ()); |
|
186 } |
|
187 |
|
188 void |
|
189 octave_user_function::octave_vr_val (const octave_value& val) |
|
190 { |
4280
|
191 // Use != here to avoid possible conversion to int of smaller type |
|
192 // than the vr_list pointer. |
|
193 |
|
194 assert (vr_list != 0); |
2974
|
195 |
|
196 vr_list->append (val); |
|
197 } |
|
198 |
|
199 void |
3974
|
200 octave_user_function::varargout_to_vr_val (void) |
|
201 { |
|
202 assert (vr_list && vr_list->empty ()); |
|
203 |
|
204 symbol_record *sr = sym_tab->lookup ("varargout"); |
|
205 |
|
206 if (sr && sr->is_variable ()) |
|
207 { |
|
208 octave_value v = sr->def (); |
|
209 |
|
210 Cell c = v.cell_value (); |
|
211 |
|
212 if (! error_state) |
|
213 { |
|
214 // XXX FIXME XXX -- should varargout be required to be a |
|
215 // cell array with a single row or column? If not, should |
|
216 // we have a cleaner way of doing this operation? |
|
217 |
|
218 int n = c.length (); |
|
219 |
|
220 const octave_value *d = c.data (); |
|
221 |
|
222 for (int i = 0; i < n; i++) |
|
223 vr_list->append (d[i]); |
|
224 } |
|
225 else |
|
226 error ("expecting varargout to be a cell array object"); |
|
227 } |
|
228 } |
|
229 |
|
230 bool |
|
231 octave_user_function::has_varargout (void) const |
|
232 { |
|
233 bool retval = false; |
|
234 |
|
235 if (takes_var_return ()) |
|
236 { |
|
237 symbol_record *sr = sym_tab->lookup ("varargout"); |
|
238 |
|
239 retval = (sr && sr->is_variable ()); |
|
240 } |
|
241 |
|
242 return retval; |
|
243 } |
|
244 |
|
245 void |
3523
|
246 octave_user_function::stash_function_name (const std::string& s) |
2974
|
247 { |
|
248 fcn_name = s; |
|
249 } |
|
250 |
|
251 // For unwind protect. |
|
252 |
|
253 static void |
|
254 pop_symbol_table_context (void *table) |
|
255 { |
|
256 symbol_table *tmp = static_cast<symbol_table *> (table); |
|
257 tmp->pop_context (); |
|
258 } |
|
259 |
|
260 static void |
|
261 delete_vr_list (void *list) |
|
262 { |
|
263 tree_va_return_list *tmp = static_cast<tree_va_return_list *> (list); |
|
264 tmp->clear (); |
|
265 delete tmp; |
|
266 } |
|
267 |
|
268 static void |
|
269 clear_symbol_table (void *table) |
|
270 { |
|
271 symbol_table *tmp = static_cast<symbol_table *> (table); |
4239
|
272 tmp->clear (); |
2974
|
273 } |
|
274 |
|
275 static void |
3239
|
276 clear_param_list (void *lst) |
|
277 { |
|
278 tree_parameter_list *tmp = static_cast<tree_parameter_list *> (lst); |
|
279 |
|
280 if (tmp) |
4219
|
281 tmp->undefine (); |
3239
|
282 } |
|
283 |
|
284 static void |
3875
|
285 restore_args_passed (void *fcn) |
3239
|
286 { |
|
287 octave_user_function *tmp = static_cast<octave_user_function *> (fcn); |
|
288 |
|
289 if (tmp) |
3875
|
290 tmp->restore_args_passed (); |
3239
|
291 } |
|
292 |
|
293 static void |
2974
|
294 unprotect_function (void *sr_arg) |
|
295 { |
|
296 symbol_record *sr = static_cast<symbol_record *> (sr_arg); |
|
297 sr->unprotect (); |
|
298 } |
|
299 |
|
300 octave_value_list |
4247
|
301 octave_user_function::subsref (const std::string& type, |
4219
|
302 const std::list<octave_value_list>& idx, |
3933
|
303 int nargout) |
|
304 { |
|
305 octave_value_list retval; |
|
306 |
|
307 switch (type[0]) |
|
308 { |
|
309 case '(': |
|
310 retval = do_multi_index_op (nargout, idx.front ()); |
|
311 break; |
|
312 |
|
313 case '{': |
|
314 case '.': |
|
315 { |
|
316 std::string nm = type_name (); |
|
317 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
318 } |
|
319 break; |
|
320 |
|
321 default: |
|
322 panic_impossible (); |
|
323 } |
|
324 |
4059
|
325 // XXX FIXME XXX -- perhaps there should be an |
|
326 // octave_value_list::next_subsref member function? See also |
|
327 // octave_builtin::subsref. |
3933
|
328 |
4219
|
329 if (idx.size () > 1) |
4059
|
330 retval = retval(0).next_subsref (type, idx); |
|
331 |
|
332 return retval; |
3933
|
333 } |
|
334 |
|
335 octave_value_list |
3544
|
336 octave_user_function::do_multi_index_op (int nargout, |
|
337 const octave_value_list& args) |
2974
|
338 { |
|
339 octave_value_list retval; |
|
340 |
|
341 if (error_state) |
|
342 return retval; |
|
343 |
|
344 if (! cmd_list) |
|
345 return retval; |
|
346 |
|
347 int nargin = args.length (); |
|
348 |
2985
|
349 unwind_protect::begin_frame ("func_eval"); |
2974
|
350 |
|
351 unwind_protect_int (call_depth); |
|
352 call_depth++; |
|
353 |
3131
|
354 if (call_depth > Vmax_recursion_depth) |
|
355 { |
|
356 ::error ("max_recursion_limit exceeded"); |
3321
|
357 unwind_protect::run_frame ("func_eval"); |
3131
|
358 return retval; |
|
359 } |
|
360 |
2974
|
361 if (symtab_entry && ! symtab_entry->is_read_only ()) |
|
362 { |
|
363 symtab_entry->protect (); |
2985
|
364 unwind_protect::add (unprotect_function, symtab_entry); |
2974
|
365 } |
|
366 |
|
367 if (call_depth > 1) |
|
368 { |
|
369 sym_tab->push_context (); |
2985
|
370 unwind_protect::add (pop_symbol_table_context, sym_tab); |
2974
|
371 |
|
372 if (vr_list) |
|
373 { |
|
374 // Push new vr_list. |
|
375 |
|
376 unwind_protect_ptr (vr_list); |
|
377 vr_list = new tree_va_return_list; |
|
378 |
|
379 // Clear and delete the new one before restoring the old |
|
380 // one. |
|
381 |
2985
|
382 unwind_protect::add (delete_vr_list, vr_list); |
2974
|
383 } |
|
384 } |
|
385 |
|
386 if (vr_list) |
|
387 vr_list->clear (); |
|
388 |
|
389 // Force symbols to be undefined again when this function exits. |
|
390 |
2985
|
391 unwind_protect::add (clear_symbol_table, sym_tab); |
2974
|
392 |
|
393 // Save old and set current symbol table context, for |
|
394 // eval_undefined_error(). |
|
395 |
4245
|
396 unwind_protect_ptr (curr_caller_sym_tab); |
|
397 curr_caller_sym_tab = curr_sym_tab; |
|
398 |
2974
|
399 unwind_protect_ptr (curr_sym_tab); |
|
400 curr_sym_tab = sym_tab; |
|
401 |
|
402 unwind_protect_ptr (curr_function); |
|
403 curr_function = this; |
|
404 |
4238
|
405 if (! is_nested_function ()) |
|
406 { |
|
407 unwind_protect_ptr (curr_parent_function); |
|
408 curr_parent_function = this; |
|
409 } |
|
410 |
3875
|
411 // Save and restore args passed for recursive calls. |
2974
|
412 |
3875
|
413 save_args_passed (args); |
3239
|
414 |
3875
|
415 unwind_protect::add (::restore_args_passed, this); |
3239
|
416 |
2974
|
417 string_vector arg_names = args.name_tags (); |
|
418 |
|
419 unwind_protect_int (num_args_passed); |
|
420 num_args_passed = nargin; |
|
421 |
|
422 unwind_protect_int (curr_va_arg_number); |
|
423 |
3876
|
424 curr_va_arg_number = num_named_args; |
|
425 |
2974
|
426 if (param_list && ! param_list->varargs_only ()) |
|
427 { |
|
428 param_list->define_from_arg_vector (args); |
|
429 if (error_state) |
|
430 goto abort; |
|
431 } |
|
432 |
3239
|
433 // Force parameter list to be undefined when this function exits. |
|
434 // Doing so decrements the reference counts on the values of local |
|
435 // variables that are also named function parameters. |
|
436 |
|
437 unwind_protect::add (clear_param_list, param_list); |
|
438 |
|
439 // Force return list to be undefined when this function exits. |
|
440 // Doing so decrements the reference counts on the values of local |
|
441 // variables that are also named values returned by this function. |
|
442 |
|
443 unwind_protect::add (clear_param_list, ret_list); |
|
444 |
2974
|
445 // The following code is in a separate scope to avoid warnings from |
|
446 // G++ about `goto abort' crossing the initialization of some |
|
447 // variables. |
|
448 |
|
449 { |
3974
|
450 bind_automatic_vars (arg_names, nargin, nargout, octave_all_va_args ()); |
2974
|
451 |
|
452 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); |
|
453 |
|
454 if (echo_commands) |
|
455 print_code_function_header (); |
|
456 |
|
457 // Evaluate the commands that make up the function. |
|
458 |
3489
|
459 unwind_protect_bool (evaluating_function_body); |
|
460 evaluating_function_body = true; |
|
461 |
2974
|
462 octave_value_list tmp = cmd_list->eval (); |
|
463 |
|
464 octave_value last_computed_value; |
|
465 |
|
466 if (! tmp.empty ()) |
|
467 last_computed_value = tmp(0); |
|
468 |
|
469 if (echo_commands) |
|
470 print_code_function_trailer (); |
|
471 |
4207
|
472 if (tree_return_command::returning) |
|
473 tree_return_command::returning = 0; |
2974
|
474 |
4207
|
475 if (tree_break_command::breaking) |
|
476 tree_break_command::breaking--; |
2974
|
477 |
|
478 if (error_state) |
|
479 { |
|
480 traceback_error (); |
|
481 goto abort; |
|
482 } |
|
483 |
|
484 // Copy return values out. |
|
485 |
|
486 if (ret_list) |
3871
|
487 { |
4466
|
488 ret_list->initialize_undefined_elements (function_name (), |
|
489 nargout, Matrix ()); |
3871
|
490 |
3974
|
491 if (has_varargout ()) |
|
492 varargout_to_vr_val (); |
|
493 |
3871
|
494 retval = ret_list->convert_to_const_vector (vr_list); |
|
495 } |
2974
|
496 } |
|
497 |
|
498 abort: |
2985
|
499 unwind_protect::run_frame ("func_eval"); |
2974
|
500 |
|
501 return retval; |
|
502 } |
|
503 |
|
504 void |
4346
|
505 octave_user_function::traceback_error (void) const |
2974
|
506 { |
|
507 if (error_state >= 0) |
|
508 error_state = -1; |
|
509 |
|
510 if (fcn_name.empty ()) |
|
511 { |
|
512 if (file_name.empty ()) |
|
513 ::error ("called from `?unknown?'"); |
|
514 else |
|
515 ::error ("called from file `%s'", file_name.c_str ()); |
|
516 } |
|
517 else |
|
518 { |
|
519 if (file_name.empty ()) |
|
520 ::error ("called from `%s'", fcn_name.c_str ()); |
|
521 else |
|
522 ::error ("called from `%s' in file `%s'", |
|
523 fcn_name.c_str (), file_name.c_str ()); |
|
524 } |
|
525 } |
|
526 |
|
527 void |
|
528 octave_user_function::accept (tree_walker& tw) |
|
529 { |
|
530 tw.visit_octave_user_function (*this); |
|
531 } |
|
532 |
|
533 void |
3933
|
534 octave_user_function::print_symtab_info (std::ostream& os) const |
|
535 { |
|
536 if (sym_tab) |
|
537 sym_tab->print_info (os); |
|
538 else |
|
539 warning ("%s: no symbol table info!", fcn_name.c_str ()); |
|
540 } |
|
541 |
|
542 void |
2974
|
543 octave_user_function::print_code_function_header (void) |
|
544 { |
|
545 tree_print_code tpc (octave_stdout, Vps4); |
|
546 |
|
547 tpc.visit_octave_user_function_header (*this); |
|
548 } |
|
549 |
|
550 void |
|
551 octave_user_function::print_code_function_trailer (void) |
|
552 { |
|
553 tree_print_code tpc (octave_stdout, Vps4); |
|
554 |
|
555 tpc.visit_octave_user_function_trailer (*this); |
|
556 } |
|
557 |
|
558 void |
|
559 octave_user_function::install_automatic_vars (void) |
|
560 { |
|
561 argn_sr = sym_tab->lookup ("argn", true); |
|
562 nargin_sr = sym_tab->lookup ("nargin", true); |
|
563 nargout_sr = sym_tab->lookup ("nargout", true); |
3974
|
564 |
|
565 if (takes_varargs ()) |
|
566 varargin_sr = sym_tab->lookup ("varargin", true); |
2974
|
567 } |
|
568 |
|
569 void |
|
570 octave_user_function::bind_automatic_vars |
3974
|
571 (const string_vector& arg_names, int nargin, int nargout, |
|
572 const octave_value_list& va_args) |
2974
|
573 { |
|
574 if (! arg_names.empty ()) |
|
575 argn_sr->define (arg_names); |
|
576 |
4233
|
577 nargin_sr->define (nargin); |
|
578 nargout_sr->define (nargout); |
3974
|
579 |
|
580 if (takes_varargs ()) |
|
581 { |
|
582 int n = va_args.length (); |
|
583 |
|
584 Cell varargin (1, n); |
|
585 |
|
586 for (int i = 0; i < n; i++) |
|
587 varargin(0,i) = va_args(i); |
|
588 |
|
589 varargin_sr->define (varargin); |
|
590 } |
2974
|
591 } |
|
592 |
3743
|
593 DEFUNX ("va_arg", Fva_arg, args, , |
3445
|
594 "-*- texinfo -*-\n\ |
|
595 @deftypefn {Built-in Function} {} va_arg ()\n\ |
3745
|
596 Return the value of the next available argument and move the internal\n\ |
3445
|
597 pointer to the next argument. It is an error to call @code{va_arg}\n\ |
|
598 when ther eare no more arguments available, or in a function that\n\ |
|
599 has not been declared to take a variable number of parameters.\n\ |
|
600 @end deftypefn") |
2974
|
601 { |
4124
|
602 static bool warned = false; |
|
603 |
|
604 if (! warned) |
|
605 { |
|
606 ::warning ("va_arg is deprecated; use varargin instead"); |
|
607 warned = true; |
|
608 } |
3975
|
609 |
2974
|
610 octave_value_list retval; |
|
611 |
|
612 int nargin = args.length (); |
|
613 |
|
614 if (nargin == 0) |
|
615 { |
|
616 if (curr_function) |
|
617 { |
|
618 if (curr_function->takes_varargs ()) |
|
619 retval = curr_function->octave_va_arg (); |
|
620 else |
|
621 { |
|
622 ::error ("va_arg only valid within function taking variable"); |
|
623 ::error ("number of arguments"); |
|
624 } |
|
625 } |
|
626 else |
|
627 ::error ("va_arg only valid within function body"); |
|
628 } |
|
629 else |
|
630 print_usage ("va_arg"); |
|
631 |
|
632 return retval; |
|
633 } |
|
634 |
|
635 DEFUN (va_start, args, , |
3445
|
636 "-*- texinfo -*-\n\ |
|
637 @deftypefn {Built-in Function} {} va_start ()\n\ |
|
638 Position an internal pointer to the first unnamed argument in\n\ |
|
639 functions that have been declared to accept a variable number of\n\ |
|
640 arguments. It is an error to call @code{va_start} in a function\n\ |
|
641 that has not been declared to take a variable number of parameters.\n\ |
|
642 @end deftypefn") |
2974
|
643 { |
4124
|
644 static bool warned = false; |
|
645 |
|
646 if (! warned) |
|
647 { |
|
648 ::warning ("va_start is deprecated; use varargin instead"); |
|
649 warned = true; |
|
650 } |
3975
|
651 |
2974
|
652 octave_value_list retval; |
|
653 |
|
654 int nargin = args.length (); |
|
655 |
|
656 if (nargin == 0) |
|
657 { |
|
658 if (curr_function) |
|
659 { |
|
660 if (curr_function->takes_varargs ()) |
|
661 curr_function->octave_va_start (); |
|
662 else |
|
663 { |
|
664 ::error ("va_start only valid within function taking variable"); |
|
665 ::error ("number of arguments"); |
|
666 } |
|
667 } |
|
668 else |
|
669 ::error ("va_start only valid within function body"); |
|
670 } |
|
671 else |
|
672 print_usage ("va_start"); |
|
673 |
|
674 return retval; |
|
675 } |
|
676 |
|
677 DEFUN (vr_val, args, , |
3445
|
678 "-*- texinfo -*-\n\ |
|
679 @deftypefn {Built-in Function} {} vr_val (@var{x})\n\ |
|
680 Each time this function is called, it places the value of its argument\n\ |
|
681 at the end of the list of values to return from the current\n\ |
|
682 function. Once @code{vr_val} has been called, there is no way to go\n\ |
|
683 back to the beginning of the list and rewrite any of the return\n\ |
|
684 values. This function may only be called within functions that have\n\ |
|
685 been declared to return an unspecified number of output arguments.\n\ |
|
686 @end deftypefn") |
2974
|
687 { |
4124
|
688 static bool warned = false; |
|
689 |
|
690 if (! warned) |
|
691 { |
|
692 ::warning ("vr_val is deprecated; use varargout instead"); |
|
693 warned = true; |
|
694 } |
3975
|
695 |
2974
|
696 octave_value_list retval; |
|
697 |
|
698 int nargin = args.length (); |
|
699 |
|
700 if (nargin == 1) |
|
701 { |
|
702 if (curr_function) |
|
703 { |
3974
|
704 if (curr_function->has_varargout ()) |
|
705 ::error ("vr_val and varargout cannot both be used in the same function"); |
|
706 else if (curr_function->takes_var_return ()) |
2974
|
707 curr_function->octave_vr_val (args(0)); |
|
708 else |
|
709 { |
|
710 ::error ("vr_val only valid within function declared to"); |
|
711 ::error ("produce a variable number of values"); |
|
712 } |
|
713 } |
|
714 else |
|
715 ::error ("vr_val only valid within function body"); |
|
716 } |
|
717 else |
|
718 print_usage ("vr_val"); |
|
719 |
|
720 return retval; |
|
721 } |
|
722 |
|
723 static int |
3131
|
724 max_recursion_depth (void) |
|
725 { |
|
726 Vmax_recursion_depth = check_preference ("max_recursion_depth"); |
|
727 |
|
728 return 0; |
|
729 } |
|
730 |
2974
|
731 void |
|
732 symbols_of_ov_usr_fcn (void) |
|
733 { |
3258
|
734 DEFVAR (max_recursion_depth, 256.0, max_recursion_depth, |
3371
|
735 "-*- texinfo -*-\n\ |
|
736 @defvr {Built-in Variable} max_recursion_depth\n\ |
|
737 Limit the number of times a function may be called recursively.\n\ |
|
738 If the limit is exceeded, an error message is printed and control\n\ |
|
739 returns to the top level.\n\ |
|
740 \n\ |
|
741 The default value is 256.\n\ |
|
742 @end defvr"); |
2974
|
743 } |
|
744 |
|
745 /* |
|
746 ;;; Local Variables: *** |
|
747 ;;; mode: C++ *** |
|
748 ;;; End: *** |
|
749 */ |