Mercurial > octave-antonio
annotate src/ov-usr-fcn.cc @ 14861:f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
* bitfcns.cc, comment-list.cc, data.cc, defun.cc, error.cc, gl-render.cc,
graphics.cc, graphics.in.h, load-path.cc, load-path.h, load-save.cc,
ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-ascii.cc, mappers.cc, mex.cc,
oct-map.cc, oct-obj.cc, ov-base-int.cc, ov-base-mat.h, ov-base-sparse.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-cell.cc, ov-class.cc, ov-complex.cc,
ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc,
ov-struct.cc, ov-usr-fcn.cc, ov.cc, pr-output.cc, procstream.h, sighandlers.cc,
sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, symtab.cc, syscalls.cc, sysdep.cc,
txt-eng-ft.cc, variables.cc, zfstream.cc, zfstream.h: Use Octave coding
conventions for cuddling parentheses.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 14 Jul 2012 06:22:56 -0700 |
parents | 1c0f0e8f9a1b |
children | 2309812f428e |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2974 | 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. | |
2974 | 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/>. | |
2974 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
27 #include <sstream> |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
28 |
2974 | 29 #include "str-vec.h" |
30 | |
31 #include <defaults.h> | |
3974 | 32 #include "Cell.h" |
2974 | 33 #include "defun.h" |
34 #include "error.h" | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
35 #include "gripes.h" |
2974 | 36 #include "input.h" |
37 #include "oct-obj.h" | |
38 #include "ov-usr-fcn.h" | |
39 #include "ov.h" | |
40 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
41 #include "pt-eval.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" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
52 #include "profiler.h" |
2974 | 53 #include "variables.h" |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
54 #include "ov-fcn-handle.h" |
2974 | 55 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
56 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
57 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
58 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
59 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
60 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
61 DEFINE_OCTAVE_ALLOCATOR (octave_user_script); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
62 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
63 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_script, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
65 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
66 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
67 octave_user_script::octave_user_script (void) |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
68 : octave_user_code (), cmd_list (0), file_name (), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
69 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
70 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
71 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
72 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
73 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
74 octave_user_script::octave_user_script (const std::string& fnm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
75 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 tree_statement_list *cmds, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 const std::string& ds) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
78 : octave_user_code (nm, ds), cmd_list (cmds), file_name (fnm), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
79 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
80 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
81 call_depth (-1) |
7736 | 82 { |
83 if (cmd_list) | |
84 cmd_list->mark_as_script_body (); | |
85 } | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
86 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
87 octave_user_script::octave_user_script (const std::string& fnm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
89 const std::string& ds) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
90 : octave_user_code (nm, ds), cmd_list (0), file_name (fnm), |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
91 t_parsed (static_cast<time_t> (0)), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
92 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
93 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
94 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
95 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
96 octave_user_script::~octave_user_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
97 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
98 delete cmd_list; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
99 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
100 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
101 octave_value_list |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
102 octave_user_script::subsref (const std::string&, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 const std::list<octave_value_list>&, int) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
104 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
105 octave_value_list retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
106 |
10001
6918d86add73
Print script filename in script indexing errors
David Grundberg <davidg@cs.umu.se>
parents:
9646
diff
changeset
|
107 ::error ("invalid use of script %s in index expression", file_name.c_str ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
108 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
109 return retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
110 } |
7336 | 111 |
112 octave_value_list | |
113 octave_user_script::do_multi_index_op (int nargout, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 const octave_value_list& args) |
7336 | 115 { |
116 octave_value_list retval; | |
117 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
118 unwind_protect frame; |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
119 |
7336 | 120 if (! error_state) |
121 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
122 if (args.length () == 0 && nargout == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 if (cmd_list) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 frame.protect_var (call_depth); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
127 call_depth++; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
128 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 if (call_depth < Vmax_recursion_depth) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
131 octave_call_stack::push (this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
132 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
133 frame.add_fcn (octave_call_stack::pop); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
134 |
11304 | 135 frame.protect_var (tree_evaluator::statement_context); |
136 tree_evaluator::statement_context = tree_evaluator::script; | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
137 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
138 BEGIN_PROFILER_BLOCK (profiler_name ()) |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
139 cmd_list->accept (*current_evaluator); |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
140 END_PROFILER_BLOCK |
7336 | 141 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
142 if (tree_return_command::returning) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 tree_return_command::returning = 0; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
144 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 if (tree_break_command::breaking) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
146 tree_break_command::breaking--; |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
147 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 octave_call_stack::backtrace_error_message (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 else |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
152 ::error ("max_recursion_depth exceeded"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 } |
7336 | 155 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 error ("invalid call to script %s", file_name.c_str ()); |
7336 | 157 } |
158 | |
159 return retval; | |
160 } | |
161 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
162 void |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
163 octave_user_script::accept (tree_walker& tw) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
164 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
165 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
166 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
167 |
2974 | 168 // User defined functions. |
169 | |
3219 | 170 DEFINE_OCTAVE_ALLOCATOR (octave_user_function); |
2974 | 171 |
3219 | 172 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_function, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 "user-defined function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 "user-defined function"); |
2974 | 175 |
176 // Ugh. This really needs to be simplified (code/data? | |
177 // extrinsic/intrinsic state?). | |
178 | |
179 octave_user_function::octave_user_function | |
7336 | 180 (symbol_table::scope_id sid, tree_parameter_list *pl, |
181 tree_parameter_list *rl, tree_statement_list *cl) | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
182 : octave_user_code (std::string (), std::string ()), |
2974 | 183 param_list (pl), ret_list (rl), cmd_list (cl), |
7336 | 184 lead_comm (), trail_comm (), file_name (), |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
185 location_line (0), location_column (0), |
6323 | 186 parent_name (), t_parsed (static_cast<time_t> (0)), |
3255 | 187 t_checked (static_cast<time_t> (0)), |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
188 system_fcn_file (false), call_depth (-1), |
7589
90fb25a5a3fa
minor cleanup in octave_user_function constructor
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
189 num_named_args (param_list ? param_list->length () : 0), |
11461
2b8531a6a3c9
Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents:
11431
diff
changeset
|
190 subfunction (false), inline_function (false), |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14573
diff
changeset
|
191 anonymous_function (false), nested_function (false), |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14366
diff
changeset
|
192 class_constructor (false), class_method (false), |
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14366
diff
changeset
|
193 parent_scope (-1), local_scope (sid), |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
194 curr_unwind_protect_frame (0) |
7736 | 195 { |
196 if (cmd_list) | |
197 cmd_list->mark_as_function_body (); | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
198 |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
199 if (local_scope >= 0) |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
200 symbol_table::set_curr_fcn (this, local_scope); |
7736 | 201 } |
2974 | 202 |
203 octave_user_function::~octave_user_function (void) | |
204 { | |
205 delete param_list; | |
206 delete ret_list; | |
207 delete cmd_list; | |
3665 | 208 delete lead_comm; |
209 delete trail_comm; | |
7336 | 210 |
211 symbol_table::erase_scope (local_scope); | |
2974 | 212 } |
213 | |
214 octave_user_function * | |
215 octave_user_function::define_ret_list (tree_parameter_list *t) | |
216 { | |
217 ret_list = t; | |
218 | |
219 return this; | |
220 } | |
221 | |
222 void | |
4343 | 223 octave_user_function::stash_fcn_file_name (const std::string& nm) |
2974 | 224 { |
4343 | 225 file_name = nm; |
2974 | 226 } |
227 | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
228 std::string |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
229 octave_user_function::profiler_name (void) const |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
230 { |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
231 std::ostringstream result; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
232 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
233 if (is_inline_function ()) |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12960
diff
changeset
|
234 result << "inline@" << fcn_file_name () |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12960
diff
changeset
|
235 << ":" << location_line << ":" << location_column; |
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12960
diff
changeset
|
236 else if (is_anonymous_function ()) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
237 result << "anonymous@" << fcn_file_name () |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
238 << ":" << location_line << ":" << location_column; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
239 else if (is_subfunction ()) |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
240 result << parent_fcn_name () << ">" << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
241 else |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
242 result << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
243 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
244 return result.str (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
245 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
246 |
2974 | 247 void |
248 octave_user_function::mark_as_system_fcn_file (void) | |
249 { | |
250 if (! file_name.empty ()) | |
251 { | |
252 // We really should stash the whole path to the file we found, | |
253 // when we looked it up, to avoid possible race conditions... | |
5775 | 254 // FIXME |
2974 | 255 // |
256 // We probably also don't need to get the library directory | |
257 // every time, but since this function is only called when the | |
258 // function file is parsed, it probably doesn't matter that | |
259 // much. | |
260 | |
3523 | 261 std::string ff_name = fcn_file_in_path (file_name); |
2974 | 262 |
3565 | 263 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
264 system_fcn_file = 1; |
2974 | 265 } |
266 else | |
267 system_fcn_file = 0; | |
268 } | |
269 | |
270 bool | |
271 octave_user_function::takes_varargs (void) const | |
272 { | |
273 return (param_list && param_list->takes_varargs ()); | |
274 } | |
275 | |
5848 | 276 bool |
277 octave_user_function::takes_var_return (void) const | |
2974 | 278 { |
5848 | 279 return (ret_list && ret_list->takes_varargs ()); |
2974 | 280 } |
281 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
282 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
283 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
284 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
285 symbol_table::lock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
286 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
287 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
288 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
289 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
290 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
291 symbol_table::unlock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
292 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
293 |
2974 | 294 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
295 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 296 { |
297 octave_value_list retval; | |
298 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
299 octave_idx_type n = args.length () - num_named_args; |
2974 | 300 |
3178 | 301 if (n > 0) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
302 retval = args.slice (num_named_args, n); |
2974 | 303 |
304 return retval; | |
305 } | |
306 | |
307 octave_value_list | |
4247 | 308 octave_user_function::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 int nargout) |
3933 | 311 { |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
312 return octave_user_function::subsref (type, idx, nargout, 0); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
313 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
314 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
315 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
316 octave_user_function::subsref (const std::string& type, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
317 const std::list<octave_value_list>& idx, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
318 int nargout, const std::list<octave_lvalue>* lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
319 { |
3933 | 320 octave_value_list retval; |
321 | |
322 switch (type[0]) | |
323 { | |
324 case '(': | |
5154 | 325 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
326 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 327 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
328 retval = do_multi_index_op (tmp_nargout, idx.front (), |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
329 idx.size () == 1 ? lvalue_list : 0); |
5154 | 330 } |
3933 | 331 break; |
332 | |
333 case '{': | |
334 case '.': | |
335 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
336 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 338 } |
339 break; | |
340 | |
341 default: | |
342 panic_impossible (); | |
343 } | |
344 | |
5775 | 345 // FIXME -- perhaps there should be an |
4059 | 346 // octave_value_list::next_subsref member function? See also |
347 // octave_builtin::subsref. | |
3933 | 348 |
4219 | 349 if (idx.size () > 1) |
4994 | 350 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 351 |
352 return retval; | |
3933 | 353 } |
354 | |
355 octave_value_list | |
3544 | 356 octave_user_function::do_multi_index_op (int nargout, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 const octave_value_list& args) |
2974 | 358 { |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
359 return do_multi_index_op (nargout, args, 0); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
360 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
361 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
362 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
363 octave_user_function::do_multi_index_op (int nargout, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
364 const octave_value_list& args, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
365 const std::list<octave_lvalue>* lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
366 { |
2974 | 367 octave_value_list retval; |
368 | |
369 if (error_state) | |
370 return retval; | |
371 | |
372 if (! cmd_list) | |
373 return retval; | |
374 | |
375 int nargin = args.length (); | |
376 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
377 unwind_protect frame; |
2974 | 378 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
379 frame.protect_var (call_depth); |
2974 | 380 call_depth++; |
381 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
382 if (call_depth >= Vmax_recursion_depth) |
3131 | 383 { |
10578
cb0883127251
limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
384 ::error ("max_recursion_depth exceeded"); |
3131 | 385 return retval; |
386 } | |
387 | |
7336 | 388 // Save old and set current symbol table context, for |
389 // eval_undefined_error(). | |
390 | |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14366
diff
changeset
|
391 int context = active_context (); |
14328
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
392 |
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
393 octave_call_stack::push (this, local_scope, context); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
394 frame.add_fcn (octave_call_stack::pop); |
7901 | 395 |
14328
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
396 if (call_depth > 0 && ! is_anonymous_function ()) |
2974 | 397 { |
7336 | 398 symbol_table::push_context (); |
2974 | 399 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
400 frame.add_fcn (symbol_table::pop_context); |
7336 | 401 } |
2974 | 402 |
403 string_vector arg_names = args.name_tags (); | |
404 | |
405 if (param_list && ! param_list->varargs_only ()) | |
406 { | |
407 param_list->define_from_arg_vector (args); | |
408 if (error_state) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
409 return retval; |
2974 | 410 } |
411 | |
3239 | 412 // Force parameter list to be undefined when this function exits. |
413 // Doing so decrements the reference counts on the values of local | |
414 // variables that are also named function parameters. | |
415 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
416 if (param_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
417 frame.add_method (param_list, &tree_parameter_list::undefine); |
3239 | 418 |
419 // Force return list to be undefined when this function exits. | |
420 // Doing so decrements the reference counts on the values of local | |
421 // variables that are also named values returned by this function. | |
422 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
423 if (ret_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
424 frame.add_method (ret_list, &tree_parameter_list::undefine); |
3239 | 425 |
8142
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
426 if (call_depth == 0) |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
427 { |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
428 // Force symbols to be undefined again when this function |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
429 // exits. |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
430 // |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
431 // This cleanup function is added to the unwind_protect stack |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
432 // after the calls to clear the parameter lists so that local |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
433 // variables will be cleared before the parameter lists are |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
434 // cleared. That way, any function parameters that have been |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
435 // declared global will be unmarked as global before they are |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
436 // undefined by the clear_param_list cleanup function. |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
437 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
438 frame.add_fcn (symbol_table::clear_variables); |
8142
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
439 } |
54b41376e381
ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents:
8013
diff
changeset
|
440 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
441 bind_automatic_vars (arg_names, nargin, nargout, all_va_args (args), |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
442 lvalue_list); |
2974 | 443 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
444 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); |
2974 | 445 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
446 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
447 print_code_function_header (); |
2974 | 448 |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
449 // Set pointer to the current unwind_protect frame to allow |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
450 // certain builtins register simple cleanup in a very optimized manner. |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
451 // This is *not* intended as a general-purpose on-cleanup mechanism, |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
452 frame.protect_var (curr_unwind_protect_frame); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
453 curr_unwind_protect_frame = &frame; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
454 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
455 // Evaluate the commands that make up the function. |
2974 | 456 |
11304 | 457 frame.protect_var (tree_evaluator::statement_context); |
458 tree_evaluator::statement_context = tree_evaluator::function; | |
3489 | 459 |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
12960
diff
changeset
|
460 bool special_expr = (is_inline_function () || is_anonymous_function ()); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
461 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
462 BEGIN_PROFILER_BLOCK (profiler_name ()) |
6657 | 463 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
464 if (special_expr) |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
465 { |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
466 assert (cmd_list->length () == 1); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
467 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
468 tree_statement *stmt = 0; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
469 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
470 if ((stmt = cmd_list->front ()) |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
471 && stmt->is_expression ()) |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
472 { |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
473 tree_expression *expr = stmt->expression (); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
474 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
475 retval = expr->rvalue (nargout); |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
476 } |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
477 } |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
478 else |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
479 cmd_list->accept (*current_evaluator); |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
480 |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
481 END_PROFILER_BLOCK |
2974 | 482 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
483 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
484 print_code_function_trailer (); |
2974 | 485 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
486 if (tree_return_command::returning) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
487 tree_return_command::returning = 0; |
2974 | 488 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
489 if (tree_break_command::breaking) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
490 tree_break_command::breaking--; |
2974 | 491 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
492 if (error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
493 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
494 octave_call_stack::backtrace_error_message (); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
495 return retval; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
496 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
497 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
498 // Copy return values out. |
2974 | 499 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
500 if (ret_list && ! special_expr) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
501 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
502 ret_list->initialize_undefined_elements (my_name, nargout, Matrix ()); |
5848 | 503 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
504 Cell varargout; |
6591 | 505 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
506 if (ret_list->takes_varargs ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
507 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
508 octave_value varargout_varval = symbol_table::varval ("varargout"); |
5848 | 509 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
510 if (varargout_varval.is_defined ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
511 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
512 varargout = varargout_varval.cell_value (); |
5848 | 513 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
514 if (error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
515 error ("expecting varargout to be a cell array object"); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
516 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
517 } |
2974 | 518 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
519 if (! error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
520 retval = ret_list->convert_to_const_vector (nargout, varargout); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
521 } |
2974 | 522 |
523 return retval; | |
524 } | |
525 | |
526 void | |
527 octave_user_function::accept (tree_walker& tw) | |
528 { | |
529 tw.visit_octave_user_function (*this); | |
530 } | |
531 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
532 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
533 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
534 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
535 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
536 if (Voptimize_subsasgn_calls |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
537 && param_list->length () > 0 && ! param_list->varargs_only () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
538 && ret_list->length () == 1 && ! ret_list->takes_varargs ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
539 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
540 tree_identifier *par1 = param_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
541 tree_identifier *ret1 = ret_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
542 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
543 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
544 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
545 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
546 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
547 |
7336 | 548 #if 0 |
2974 | 549 void |
3933 | 550 octave_user_function::print_symtab_info (std::ostream& os) const |
551 { | |
7336 | 552 symbol_table::print_info (os, local_scope); |
3933 | 553 } |
7336 | 554 #endif |
3933 | 555 |
556 void | |
2974 | 557 octave_user_function::print_code_function_header (void) |
558 { | |
5794 | 559 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 560 |
561 tpc.visit_octave_user_function_header (*this); | |
562 } | |
563 | |
564 void | |
565 octave_user_function::print_code_function_trailer (void) | |
566 { | |
5794 | 567 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 568 |
569 tpc.visit_octave_user_function_trailer (*this); | |
570 } | |
571 | |
572 void | |
573 octave_user_function::bind_automatic_vars | |
3974 | 574 (const string_vector& arg_names, int nargin, int nargout, |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
575 const octave_value_list& va_args, const std::list<octave_lvalue> *lvalue_list) |
2974 | 576 { |
577 if (! arg_names.empty ()) | |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
578 { |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
579 // It is better to save this in the hidden variable .argn. and |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
580 // then use that in the inputname function instead of using argn, |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
581 // which might be redefined in a function. Keep the old argn name |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
582 // for backward compatibility of functions that use it directly. |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
583 |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
584 symbol_table::varref ("argn") = arg_names; |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
585 symbol_table::varref (".argn.") = Cell (arg_names); |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
586 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
587 symbol_table::mark_hidden (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
588 |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
589 symbol_table::mark_automatic ("argn"); |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
590 symbol_table::mark_automatic (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
591 } |
2974 | 592 |
7336 | 593 symbol_table::varref (".nargin.") = nargin; |
594 symbol_table::varref (".nargout.") = nargout; | |
595 | |
596 symbol_table::mark_hidden (".nargin."); | |
597 symbol_table::mark_hidden (".nargout."); | |
3974 | 598 |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
599 symbol_table::mark_automatic (".nargin."); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
600 symbol_table::mark_automatic (".nargout."); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
601 |
3974 | 602 if (takes_varargs ()) |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8142
diff
changeset
|
603 symbol_table::varref ("varargin") = va_args.cell_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
604 |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
605 // Force .ignored. variable to be undefined by default. |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
606 symbol_table::varref (".ignored.") = octave_value (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
607 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
608 if (lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
609 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
610 octave_idx_type nbh = 0; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
611 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
612 p != lvalue_list->end (); p++) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
613 nbh += p->is_black_hole (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
614 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
615 if (nbh > 0) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
616 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
617 // Only assign the hidden variable if black holes actually present. |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
618 Matrix bh (1, nbh); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
619 octave_idx_type k = 0, l = 0; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
620 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
621 p != lvalue_list->end (); p++) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
622 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
623 if (p->is_black_hole ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
624 bh(l++) = k+1; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
625 k += p->numel (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
626 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
627 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
628 symbol_table::varref (".ignored.") = bh; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
629 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
630 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
631 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
632 symbol_table::mark_hidden (".ignored."); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
633 symbol_table::mark_automatic (".ignored."); |
2974 | 634 } |
635 | |
4700 | 636 DEFUN (nargin, args, , |
637 "-*- texinfo -*-\n\ | |
10840 | 638 @deftypefn {Built-in Function} {} nargin ()\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
639 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\ |
4700 | 640 Within a function, return the number of arguments passed to the function.\n\ |
641 At the top level, return the number of command line arguments passed to\n\ | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
642 Octave.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
643 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
644 If called with the optional argument @var{fcn}, a function name or handle,\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
645 return the declared number of arguments that the function can accept.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
646 If the last argument is @var{varargin} the returned value is negative.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
647 This feature does not work on builtin functions.\n\ |
13749
62d1f56b0be7
New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13241
diff
changeset
|
648 @seealso{nargout, varargin, isargout, varargout, nthargout}\n\ |
4700 | 649 @end deftypefn") |
650 { | |
651 octave_value retval; | |
652 | |
653 int nargin = args.length (); | |
654 | |
655 if (nargin == 1) | |
656 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
657 octave_value func = args(0); |
4700 | 658 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
659 if (func.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
660 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
661 std::string name = func.string_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
662 func = symbol_table::find_function (name); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
663 if (func.is_undefined ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
664 error ("nargout: invalid function name: %s", name.c_str ()); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
665 } |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
666 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
667 octave_function *fcn_val = func.function_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
668 if (fcn_val) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
669 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
670 octave_user_function *fcn = fcn_val->user_function_value (true); |
4700 | 671 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
674 tree_parameter_list *param_list = fcn->parameter_list (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
675 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
676 retval = param_list ? param_list->length () : 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
677 if (fcn->takes_varargs ()) |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
678 retval = -1 - retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
679 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 else |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
681 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
682 // Matlab gives up for histc, so maybe it's ok we give up somtimes too. |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
683 error ("nargin: nargin information not available for builtin functions"); |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
684 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 } |
4700 | 686 else |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
687 error ("nargin: FCN must be a string or function handle"); |
4700 | 688 } |
689 else if (nargin == 0) | |
690 { | |
7336 | 691 retval = symbol_table::varval (".nargin."); |
4700 | 692 |
7336 | 693 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 retval = 0; |
4700 | 695 } |
696 else | |
5823 | 697 print_usage (); |
4700 | 698 |
699 return retval; | |
700 } | |
701 | |
702 DEFUN (nargout, args, , | |
703 "-*- texinfo -*-\n\ | |
10840 | 704 @deftypefn {Built-in Function} {} nargout ()\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
705 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\ |
4700 | 706 Within a function, return the number of values the caller expects to\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
707 receive. If called with the optional argument @var{fcn}, a function\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
708 name or handle, return the number of declared output values that the\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14328
diff
changeset
|
709 function can produce. If the final output argument is @var{varargout}\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
710 the returned value is negative.\n\ |
4700 | 711 \n\ |
712 For example,\n\ | |
713 \n\ | |
714 @example\n\ | |
715 f ()\n\ | |
716 @end example\n\ | |
717 \n\ | |
718 @noindent\n\ | |
4704 | 719 will cause @code{nargout} to return 0 inside the function @code{f} and\n\ |
4700 | 720 \n\ |
721 @example\n\ | |
722 [s, t] = f ()\n\ | |
723 @end example\n\ | |
724 \n\ | |
725 @noindent\n\ | |
726 will cause @code{nargout} to return 2 inside the function\n\ | |
727 @code{f}.\n\ | |
728 \n\ | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
729 In the second usage,\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
730 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
731 @example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
732 nargout (@@histc) \% or nargout ('histc')\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
733 @end example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
734 \n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14328
diff
changeset
|
735 @noindent\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
736 will return 2, because @code{histc} has two outputs, whereas\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
737 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
738 @example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
739 nargout (@@deal)\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
740 @end example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
741 \n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14328
diff
changeset
|
742 @noindent\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
743 will return -1, because @code{deal} has a variable number of outputs.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
744 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
745 At the top level, @code{nargout} with no argument is undefined.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
746 @code{nargout} does not work on builtin functions.\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
747 @code{nargout} returns -1 for all anonymous functions.\n\ |
13749
62d1f56b0be7
New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13241
diff
changeset
|
748 @seealso{nargin, varargin, isargout, varargout, nthargout}\n\ |
4700 | 749 @end deftypefn") |
750 { | |
751 octave_value retval; | |
752 | |
753 int nargin = args.length (); | |
754 | |
755 if (nargin == 1) | |
756 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
757 octave_value func = args(0); |
4700 | 758 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
759 if (func.is_string ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
760 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
761 std::string name = func.string_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
762 func = symbol_table::find_function (name); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
763 if (func.is_undefined ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
764 error ("nargout: invalid function name: %s", name.c_str ()); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
765 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
766 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
767 if (func.is_inline_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
768 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
769 retval = 1; |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
770 return retval; |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
771 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
772 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
773 if (func.is_function_handle ()) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
774 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
775 octave_fcn_handle *fh = func.fcn_handle_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
776 std::string fh_nm = fh->fcn_name (); |
4930 | 777 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
778 if (fh_nm == octave_fcn_handle::anonymous) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
779 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
780 retval = -1; |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
781 return retval; |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
782 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
783 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
784 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
785 octave_function *fcn_val = func.function_value (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
786 if (fcn_val) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
787 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
788 octave_user_function *fcn = fcn_val->user_function_value (true); |
4700 | 789 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
792 tree_parameter_list *ret_list = fcn->return_list (); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
793 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
794 retval = ret_list ? ret_list->length () : 0; |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
795 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
796 if (fcn->takes_var_return ()) |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
797 retval = -1 - retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
799 else |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
800 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
801 // JWE said this information is not available (currently, 2011-03-10) |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
802 // without making intrusive changes to Octave. |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
803 // Matlab gives up for histc, so maybe it's ok we give up somtimes too. |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
804 error ("nargout: nargout information not available for builtin functions."); |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
805 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
806 } |
4700 | 807 else |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
808 error ("nargout: FCN must be a string or function handle"); |
4700 | 809 } |
810 else if (nargin == 0) | |
811 { | |
7336 | 812 if (! symbol_table::at_top_level ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
813 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
814 retval = symbol_table::varval (".nargout."); |
4700 | 815 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
816 if (retval.is_undefined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
817 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 } |
4700 | 819 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
820 error ("nargout: invalid call at top level"); |
4700 | 821 } |
822 else | |
5823 | 823 print_usage (); |
4700 | 824 |
825 return retval; | |
826 } | |
827 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
828 DEFUN (optimize_subsasgn_calls, args, nargout, |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
829 "-*- texinfo -*-\n\ |
10840 | 830 @deftypefn {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\ |
831 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13785
diff
changeset
|
832 @deftypefnx {Built-in Function} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\ |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
833 Query or set the internal flag for subsasgn method call optimizations.\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
834 If true, Octave will attempt to eliminate the redundant copying when calling\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
835 subsasgn method of a user-defined class.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13785
diff
changeset
|
836 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13785
diff
changeset
|
837 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13785
diff
changeset
|
838 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13785
diff
changeset
|
839 variable value is restored when exiting the function.\n\ |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
840 @end deftypefn") |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
841 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
842 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
843 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
844 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
845 static bool val_in_table (const Matrix& table, double val) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
846 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
847 if (table.is_empty ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
848 return false; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
849 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
850 octave_idx_type i = table.lookup (val, ASCENDING); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
851 return (i > 0 && table(i-1) == val); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
852 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
853 |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
854 static bool isargout1 (int nargout, const Matrix& ignored, double k) |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
855 { |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
856 if (k != xround (k) || k <= 0) |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
857 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
858 error ("isargout: K must be a positive integer"); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
859 return false; |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
860 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
861 else |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
862 return (k == 1 || k <= nargout) && ! val_in_table (ignored, k); |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
863 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
864 |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
865 DEFUN (isargout, args, , |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
866 "-*- texinfo -*-\n\ |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
867 @deftypefn {Built-in Function} {} isargout (@var{k})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
868 Within a function, return a logical value indicating whether the argument\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
869 @var{k} will be assigned on output to a variable. If the result is false,\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
870 the argument has been ignored during the function call through the use of\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
871 the tilde (~) special output argument. Functions can use @code{isargout} to\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
872 avoid performing unnecessary calculations for outputs which are unwanted.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
873 \n\ |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14573
diff
changeset
|
874 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
875 false. @var{k} can also be an array, in which case the function works\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
876 element-by-element and a logical array is returned. At the top level,\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
877 @code{isargout} returns an error.\n\ |
13749
62d1f56b0be7
New nthargout function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13241
diff
changeset
|
878 @seealso{nargout, nargin, varargin, varargout, nthargout}\n\ |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
879 @end deftypefn") |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
880 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
881 octave_value retval; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
882 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
883 int nargin = args.length (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
884 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
885 if (nargin == 1) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
886 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
887 if (! symbol_table::at_top_level ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
888 { |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
889 int nargout1 = symbol_table::varval (".nargout.").int_value (); |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
890 if (error_state) |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
891 { |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
892 error ("isargout: internal error"); |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
893 return retval; |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
894 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
895 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
896 Matrix ignored; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
897 octave_value tmp = symbol_table::varval (".ignored."); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
898 if (tmp.is_defined ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
899 ignored = tmp.matrix_value (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
900 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
901 if (args(0).is_scalar_type ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
902 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
903 double k = args(0).double_value (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
904 if (! error_state) |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
905 retval = isargout1 (nargout1, ignored, k); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
906 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
907 else if (args(0).is_numeric_type ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
908 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
909 const NDArray ka = args(0).array_value (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
910 if (! error_state) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
911 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
912 boolNDArray r (ka.dims ()); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
913 for (octave_idx_type i = 0; i < ka.numel () && ! error_state; i++) |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
914 r(i) = isargout1 (nargout1, ignored, ka(i)); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
915 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
916 retval = r; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
917 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
918 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
919 else |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
920 gripe_wrong_type_arg ("isargout", args(0)); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
921 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
922 else |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
923 error ("isargout: invalid call at top level"); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
924 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
925 else |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
926 print_usage (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
927 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
928 return retval; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
929 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
930 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
931 /* |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
932 %!function [x, y] = try_isargout () |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
933 %! if (isargout (1)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
934 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
935 %! x = 1; y = 2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
936 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
937 %! x = -1; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
938 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
939 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
940 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
941 %! y = -2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
942 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
943 %! error ("no outputs requested"); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
944 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
945 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
946 %!endfunction |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
947 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
948 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
949 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
950 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
951 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
952 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
953 %! [x, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
954 %! assert (x, -1); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
955 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
956 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
957 %! [~, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
958 %! assert (y, -2); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
959 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
960 %!error [~, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
961 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
962 %% Check to see that isargout isn't sticky: |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
963 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
964 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
965 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
966 */ |