Mercurial > octave
annotate libinterp/octave-value/ov-usr-fcn.cc @ 21581:6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
* testfun.txi: Document Octave conventions for use of semicolon in BIST tests.
* cellfun.cc, ellipj.cc, file-io.cc, gcd.cc, hash.cc, nproc.cc,
utils.cc, fftw.cc, ov-usr-fcn.cc, oct-parse.in.yy, md5sum.m, wavread.m, wavwrite.m,
cplxpair.m, rat.m, im2double.m, rref.m, stem3.m, rotate.m, pchip.m, blackman.m,
hamming.m, hanning.m, spectral_adf.m, spectral_xdf.m, assert.m, fail.m,
etime.m, build-sparse-tests.sh, classes.tst, ctor-vs-method.tst, index.tst,
io.tst, struct.tst: Follow Octave conventions for use of semicolon in BIST
tests.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 01 Apr 2016 18:16:01 -0700 |
parents | ad0599a0acc6 |
children | aba2e6293dd8 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2974 | 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" |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
33 #include "builtins.h" |
2974 | 34 #include "defun.h" |
35 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
36 #include "errwarn.h" |
2974 | 37 #include "input.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
38 #include "ovl.h" |
2974 | 39 #include "ov-usr-fcn.h" |
40 #include "ov.h" | |
41 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
42 #include "pt-eval.h" |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
43 #include "pt-jit.h" |
2985 | 44 #include "pt-jump.h" |
2974 | 45 #include "pt-misc.h" |
46 #include "pt-pr-code.h" | |
2982 | 47 #include "pt-stmt.h" |
2974 | 48 #include "pt-walk.h" |
49 #include "symtab.h" | |
50 #include "toplev.h" | |
51 #include "unwind-prot.h" | |
52 #include "utils.h" | |
3489 | 53 #include "parse.h" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
54 #include "profiler.h" |
2974 | 55 #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
|
56 #include "ov-fcn-handle.h" |
2974 | 57 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
58 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
59 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
60 |
16856
787de2f144d9
Use string_fill_char when creating argn automatic variable (bug #34183).
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
61 // The character to fill with when creating string arrays. |
787de2f144d9
Use string_fill_char when creating argn automatic variable (bug #34183).
Rik <rik@octave.org>
parents:
16627
diff
changeset
|
62 extern char Vstring_fill_char; // see pt-mat.cc |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
63 |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
64 std::map<std::string, octave_value> |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
65 octave_user_code::subfunctions (void) const |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
66 { |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
67 return std::map<std::string, octave_value> (); |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
68 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
69 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
70 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
71 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
72 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
73 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
|
74 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
75 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
76 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
77 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
|
78 : 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
|
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) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
82 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
83 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
84 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
|
85 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
86 tree_statement_list *cmds, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
87 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
|
88 : 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
|
89 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
|
90 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
|
91 call_depth (-1) |
7736 | 92 { |
93 if (cmd_list) | |
94 cmd_list->mark_as_script_body (); | |
95 } | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
96 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
97 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
|
98 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 const std::string& ds) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
100 : 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
|
101 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
|
102 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
|
103 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
104 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
105 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
106 octave_user_script::~octave_user_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
107 { |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
108 if (cmd_list) |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
109 cmd_list->remove_all_breakpoints (file_name); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
110 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
111 delete cmd_list; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
112 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
113 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
114 octave_value_list |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
115 octave_user_script::subsref (const std::string&, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
116 const std::list<octave_value_list>&, int) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
117 { |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20163
diff
changeset
|
118 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
|
119 } |
7336 | 120 |
121 octave_value_list | |
122 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
|
123 const octave_value_list& args) |
7336 | 124 { |
125 octave_value_list retval; | |
126 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
127 unwind_protect frame; |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
128 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
129 if (args.length () != 0 || nargout != 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
130 error ("invalid call to script %s", file_name.c_str ()); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
131 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
132 if (cmd_list) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
133 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
134 frame.protect_var (call_depth); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
135 call_depth++; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
136 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
137 if (call_depth >= Vmax_recursion_depth) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
138 error ("max_recursion_depth exceeded"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
139 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
140 octave_call_stack::push (this); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
141 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
142 frame.add_fcn (octave_call_stack::pop); |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
143 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
144 frame.protect_var (tree_evaluator::statement_context); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
145 tree_evaluator::statement_context = tree_evaluator::script; |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18699
diff
changeset
|
146 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
147 BEGIN_PROFILER_BLOCK (octave_user_script) |
7336 | 148 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
149 cmd_list->accept (*current_evaluator); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
150 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
151 END_PROFILER_BLOCK |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
152 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
153 if (tree_return_command::returning) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
154 tree_return_command::returning = 0; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
155 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
156 if (tree_break_command::breaking) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
157 tree_break_command::breaking--; |
7336 | 158 } |
159 | |
160 return retval; | |
161 } | |
162 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
163 void |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
164 octave_user_script::accept (tree_walker& tw) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
165 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
166 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
167 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
168 |
2974 | 169 // User defined functions. |
170 | |
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) | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
182 : octave_user_code ("", ""), |
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), |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
192 class_constructor (none), class_method (false), |
14544
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) |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
195 #ifdef HAVE_LLVM |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
196 , jit_info (0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
197 #endif |
7736 | 198 { |
199 if (cmd_list) | |
200 cmd_list->mark_as_function_body (); | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
201 |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
202 if (local_scope >= 0) |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
203 symbol_table::set_curr_fcn (this, local_scope); |
7736 | 204 } |
2974 | 205 |
206 octave_user_function::~octave_user_function (void) | |
207 { | |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
208 if (cmd_list) |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
209 cmd_list->remove_all_breakpoints (file_name); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
210 |
2974 | 211 delete param_list; |
212 delete ret_list; | |
213 delete cmd_list; | |
3665 | 214 delete lead_comm; |
215 delete trail_comm; | |
7336 | 216 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
217 #ifdef HAVE_LLVM |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
218 delete jit_info; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
219 #endif |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
220 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
221 // FIXME: this is really playing with fire. |
7336 | 222 symbol_table::erase_scope (local_scope); |
2974 | 223 } |
224 | |
225 octave_user_function * | |
226 octave_user_function::define_ret_list (tree_parameter_list *t) | |
227 { | |
228 ret_list = t; | |
229 | |
230 return this; | |
231 } | |
232 | |
233 void | |
4343 | 234 octave_user_function::stash_fcn_file_name (const std::string& nm) |
2974 | 235 { |
4343 | 236 file_name = nm; |
2974 | 237 } |
238 | |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
239 // If there is no explicit end statement at the end of the function, |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
240 // relocate the no_op that was generated for the end of file condition |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
241 // to appear on the next line after the last statement in the file, or |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
242 // the next line after the function keyword if there are no statements. |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
243 // More precisely, the new location should probably be on the next line |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
244 // after the end of the parameter list, but we aren't tracking that |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
245 // information (yet). |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
246 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
247 void |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
248 octave_user_function::maybe_relocate_end_internal (void) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
249 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
250 if (cmd_list && ! cmd_list->empty ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
251 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
252 tree_statement *last_stmt = cmd_list->back (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
253 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
254 if (last_stmt && last_stmt->is_end_of_fcn_or_script () |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
255 && last_stmt->is_end_of_file ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
256 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
257 tree_statement_list::reverse_iterator |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
258 next_to_last_elt = cmd_list->rbegin (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
259 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
260 next_to_last_elt++; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
261 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
262 int new_eof_line; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
263 int new_eof_col; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
264 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
265 if (next_to_last_elt == cmd_list->rend ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
266 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
267 new_eof_line = beginning_line (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
268 new_eof_col = beginning_column (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
269 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
270 else |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
271 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
272 tree_statement *next_to_last_stmt = *next_to_last_elt; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
273 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
274 new_eof_line = next_to_last_stmt->line (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
275 new_eof_col = next_to_last_stmt->column (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
276 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
277 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
278 last_stmt->set_location (new_eof_line + 1, new_eof_col); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
279 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
280 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
281 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
282 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
283 void |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
284 octave_user_function::maybe_relocate_end (void) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
285 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
286 std::map<std::string, octave_value> fcns = subfunctions (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
287 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
288 if (! fcns.empty ()) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
289 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
290 for (std::map<std::string, octave_value>::iterator p = fcns.begin (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
291 p != fcns.end (); p++) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
292 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
293 octave_user_function *f = (p->second).user_function_value (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
294 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
295 if (f) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
296 f->maybe_relocate_end_internal (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
297 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
298 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
299 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
300 maybe_relocate_end_internal (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
301 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
302 |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
303 std::string |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
304 octave_user_function::profiler_name (void) const |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
305 { |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
306 std::ostringstream result; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
307 |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
308 if (is_anonymous_function ()) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
309 result << "anonymous@" << fcn_file_name () |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
310 << ":" << location_line << ":" << location_column; |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
311 else if (is_subfunction ()) |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
312 result << parent_fcn_name () << ">" << name (); |
18752
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
313 else if (is_class_method ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
314 result << "@" << dispatch_class () << "/" << name (); |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
315 else if (is_class_constructor () || is_classdef_constructor ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
316 result << "@" << name (); |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
317 else if (is_inline_function ()) |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
318 result << "inline@" << fcn_file_name () |
e70373a98ffe
Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents:
18592
diff
changeset
|
319 << ":" << location_line << ":" << location_column; |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
320 else |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
321 result << name (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
322 |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
323 return result.str (); |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
324 } |
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
12546
diff
changeset
|
325 |
2974 | 326 void |
327 octave_user_function::mark_as_system_fcn_file (void) | |
328 { | |
329 if (! file_name.empty ()) | |
330 { | |
331 // We really should stash the whole path to the file we found, | |
332 // when we looked it up, to avoid possible race conditions... | |
5775 | 333 // FIXME |
2974 | 334 // |
335 // We probably also don't need to get the library directory | |
336 // every time, but since this function is only called when the | |
337 // function file is parsed, it probably doesn't matter that | |
338 // much. | |
339 | |
3523 | 340 std::string ff_name = fcn_file_in_path (file_name); |
2974 | 341 |
3565 | 342 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) |
14866
2309812f428e
Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14861
diff
changeset
|
343 system_fcn_file = true; |
2974 | 344 } |
345 else | |
14866
2309812f428e
Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14861
diff
changeset
|
346 system_fcn_file = false; |
2974 | 347 } |
348 | |
349 bool | |
350 octave_user_function::takes_varargs (void) const | |
351 { | |
352 return (param_list && param_list->takes_varargs ()); | |
353 } | |
354 | |
5848 | 355 bool |
356 octave_user_function::takes_var_return (void) const | |
2974 | 357 { |
5848 | 358 return (ret_list && ret_list->takes_varargs ()); |
2974 | 359 } |
360 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
361 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
362 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
363 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
364 symbol_table::lock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
365 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
366 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
367 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
368 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
369 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
370 symbol_table::unlock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
371 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
372 |
16596
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
373 std::map<std::string, octave_value> |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
374 octave_user_function::subfunctions (void) const |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
375 { |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
376 return symbol_table::subfunctions_defined_in_scope (local_scope); |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
377 } |
645672f1c873
handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
378 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
379 bool |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
380 octave_user_function::has_subfunctions (void) const |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
381 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
382 return ! subfcn_names.empty (); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
383 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
384 |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
385 void |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
386 octave_user_function::stash_subfunction_names |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
387 (const std::list<std::string>& names) |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
388 { |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
389 subfcn_names = names; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
390 } |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16605
diff
changeset
|
391 |
2974 | 392 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
393 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 394 { |
395 octave_value_list retval; | |
396 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
397 octave_idx_type n = args.length () - num_named_args; |
2974 | 398 |
3178 | 399 if (n > 0) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
400 retval = args.slice (num_named_args, n); |
2974 | 401 |
402 return retval; | |
403 } | |
404 | |
405 octave_value_list | |
4247 | 406 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
|
407 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 int nargout) |
3933 | 409 { |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
410 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
|
411 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
412 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
413 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
414 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
|
415 const std::list<octave_value_list>& idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
416 int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
417 const std::list<octave_lvalue>* lvalue_list) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
418 { |
3933 | 419 octave_value_list retval; |
420 | |
421 switch (type[0]) | |
422 { | |
423 case '(': | |
5154 | 424 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 426 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
427 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
|
428 idx.size () == 1 ? lvalue_list : 0); |
5154 | 429 } |
3933 | 430 break; |
431 | |
432 case '{': | |
433 case '.': | |
434 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 437 } |
438 break; | |
439 | |
440 default: | |
441 panic_impossible (); | |
442 } | |
443 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
444 // FIXME: perhaps there should be an |
4059 | 445 // octave_value_list::next_subsref member function? See also |
446 // octave_builtin::subsref. | |
3933 | 447 |
4219 | 448 if (idx.size () > 1) |
4994 | 449 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 450 |
451 return retval; | |
3933 | 452 } |
453 | |
454 octave_value_list | |
3544 | 455 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
|
456 const octave_value_list& args) |
2974 | 457 { |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
458 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
|
459 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
460 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
461 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
462 octave_user_function::do_multi_index_op (int nargout, |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
463 const octave_value_list& _args, |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
464 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
|
465 { |
2974 | 466 octave_value_list retval; |
467 | |
468 if (! cmd_list) | |
469 return retval; | |
470 | |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
471 // If this function is a classdef constructor, extract the first input |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
472 // argument, which must be the partially constructed object instance. |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
473 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
474 octave_value_list args (_args); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
475 octave_value_list ret_args; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
476 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
477 if (is_classdef_constructor ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
478 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
479 if (args.length () > 0) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
480 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
481 ret_args = args.slice (0, 1, true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
482 args = args.slice (1, args.length () - 1, true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
483 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
484 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
485 panic_impossible (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
486 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
487 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
488 #ifdef HAVE_LLVM |
15582
52df2e7baabe
Disable JIT when breakpoints are present
Max Brister <max@2bass.com>
parents:
15427
diff
changeset
|
489 if (is_special_expr () |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
490 && tree_jit::execute (*this, args, retval)) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
491 return retval; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
492 #endif |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
493 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
494 unwind_protect frame; |
2974 | 495 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
496 frame.protect_var (call_depth); |
2974 | 497 call_depth++; |
498 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
499 if (call_depth >= Vmax_recursion_depth) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
500 error ("max_recursion_depth exceeded"); |
3131 | 501 |
7336 | 502 // Save old and set current symbol table context, for |
503 // eval_undefined_error(). | |
504 | |
14544
be18c9e359bf
Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents:
14366
diff
changeset
|
505 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
|
506 |
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
507 octave_call_stack::push (this, local_scope, context); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
508 frame.add_fcn (octave_call_stack::pop); |
7901 | 509 |
14328
19078011cdc3
fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents:
14139
diff
changeset
|
510 if (call_depth > 0 && ! is_anonymous_function ()) |
2974 | 511 { |
7336 | 512 symbol_table::push_context (); |
2974 | 513 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
514 frame.add_fcn (symbol_table::pop_context); |
7336 | 515 } |
2974 | 516 |
517 string_vector arg_names = args.name_tags (); | |
518 | |
519 if (param_list && ! param_list->varargs_only ()) | |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
520 param_list->define_from_arg_vector (args); |
2974 | 521 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
522 // For classdef constructor, pre-populate the output arguments |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
523 // with the pre-initialized object instance, extracted above. |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
524 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
525 if (is_classdef_constructor ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
526 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
527 if (! ret_list) |
20956
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
528 error ("%s: invalid classdef constructor, no output argument defined", |
850e3d2533d4
maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
529 dispatch_class ().c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
530 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
531 ret_list->define_from_arg_vector (ret_args); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
532 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15582
diff
changeset
|
533 |
3239 | 534 // Force parameter list to be undefined when this function exits. |
535 // Doing so decrements the reference counts on the values of local | |
536 // variables that are also named function parameters. | |
537 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
538 if (param_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
539 frame.add_method (param_list, &tree_parameter_list::undefine); |
3239 | 540 |
541 // Force return list to be undefined when this function exits. | |
542 // Doing so decrements the reference counts on the values of local | |
543 // variables that are also named values returned by this function. | |
544 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
545 if (ret_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
546 frame.add_method (ret_list, &tree_parameter_list::undefine); |
3239 | 547 |
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
|
548 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
|
549 { |
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
|
550 // 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
|
551 // 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
|
552 // |
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
|
553 // 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
|
554 // 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
|
555 // 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
|
556 // 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
|
557 // 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
|
558 // 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
|
559 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
560 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
|
561 } |
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
|
562 |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
563 bind_automatic_vars (arg_names, args.length (), nargout, |
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
564 all_va_args (args), lvalue_list); |
2974 | 565 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
566 frame.add_method (this, &octave_user_function::restore_warning_states); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
567 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
568 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); |
2974 | 569 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
570 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
571 print_code_function_header (); |
2974 | 572 |
10637
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
573 // 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
|
574 // 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
|
575 // 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
|
576 frame.protect_var (curr_unwind_protect_frame); |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
577 curr_unwind_protect_frame = &frame; |
9cd5aa83fa62
implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents:
10578
diff
changeset
|
578 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
579 // Evaluate the commands that make up the function. |
2974 | 580 |
11304 | 581 frame.protect_var (tree_evaluator::statement_context); |
582 tree_evaluator::statement_context = tree_evaluator::function; | |
3489 | 583 |
19327
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
18699
diff
changeset
|
584 BEGIN_PROFILER_BLOCK (octave_user_function) |
6657 | 585 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
586 if (is_special_expr ()) |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
587 { |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
588 tree_expression *expr = special_expr (); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
589 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
590 if (expr) |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
591 retval = (lvalue_list |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
592 ? expr->rvalue (nargout, lvalue_list) |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
593 : expr->rvalue (nargout)); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
594 } |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
595 else |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
596 cmd_list->accept (*current_evaluator); |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
597 |
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
598 END_PROFILER_BLOCK |
2974 | 599 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
600 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
601 print_code_function_trailer (); |
2974 | 602 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
603 if (tree_return_command::returning) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
604 tree_return_command::returning = 0; |
2974 | 605 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
606 if (tree_break_command::breaking) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
607 tree_break_command::breaking--; |
2974 | 608 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
609 // Copy return values out. |
2974 | 610 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
611 if (ret_list && ! is_special_expr ()) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
612 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
613 ret_list->initialize_undefined_elements (my_name, nargout, Matrix ()); |
5848 | 614 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
615 Cell varargout; |
6591 | 616 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
617 if (ret_list->takes_varargs ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
618 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
619 octave_value varargout_varval = symbol_table::varval ("varargout"); |
5848 | 620 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
621 if (varargout_varval.is_defined ()) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
622 varargout = varargout_varval.xcell_value ("varargout must be a cell array object"); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
623 } |
2974 | 624 |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
625 retval = ret_list->convert_to_const_vector (nargout, varargout); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
626 } |
2974 | 627 |
628 return retval; | |
629 } | |
630 | |
631 void | |
632 octave_user_function::accept (tree_walker& tw) | |
633 { | |
634 tw.visit_octave_user_function (*this); | |
635 } | |
636 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
637 tree_expression * |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
638 octave_user_function::special_expr (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
639 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
640 assert (is_special_expr ()); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
641 assert (cmd_list->length () == 1); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
642 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
643 tree_statement *stmt = cmd_list->front (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
644 return stmt->expression (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
645 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15236
diff
changeset
|
646 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
647 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
648 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
649 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
650 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
651 if (Voptimize_subsasgn_calls |
18699
e3fca7930c1e
Fix segfault if subsasgn in @class returns no output (bug #41945)
Stefan Mahr <dac922@gmx.de>
parents:
18533
diff
changeset
|
652 && param_list && ret_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
653 && param_list->length () > 0 && ! param_list->varargs_only () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
654 && ret_list->length () == 1 && ! ret_list->takes_varargs ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
655 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
656 tree_identifier *par1 = param_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
657 tree_identifier *ret1 = ret_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
658 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
659 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
660 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
661 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
662 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
663 |
7336 | 664 #if 0 |
2974 | 665 void |
3933 | 666 octave_user_function::print_symtab_info (std::ostream& os) const |
667 { | |
7336 | 668 symbol_table::print_info (os, local_scope); |
3933 | 669 } |
7336 | 670 #endif |
3933 | 671 |
672 void | |
2974 | 673 octave_user_function::print_code_function_header (void) |
674 { | |
5794 | 675 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 676 |
677 tpc.visit_octave_user_function_header (*this); | |
678 } | |
679 | |
680 void | |
681 octave_user_function::print_code_function_trailer (void) | |
682 { | |
5794 | 683 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 684 |
685 tpc.visit_octave_user_function_trailer (*this); | |
686 } | |
687 | |
688 void | |
689 octave_user_function::bind_automatic_vars | |
3974 | 690 (const string_vector& arg_names, int nargin, int nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
691 const octave_value_list& va_args, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
692 const std::list<octave_lvalue> *lvalue_list) |
2974 | 693 { |
694 if (! arg_names.empty ()) | |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
695 { |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
696 // 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
|
697 // 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
|
698 // 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
|
699 // 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
|
700 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
701 symbol_table::force_assign ("argn", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
702 charMatrix (arg_names, Vstring_fill_char)); |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
703 symbol_table::force_assign (".argn.", Cell (arg_names)); |
11558
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
704 |
1e4dfc7a9487
use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents:
11557
diff
changeset
|
705 symbol_table::mark_hidden (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
706 |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
707 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
|
708 symbol_table::mark_automatic (".argn."); |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
709 } |
2974 | 710 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
711 symbol_table::force_assign (".nargin.", nargin); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
712 symbol_table::force_assign (".nargout.", nargout); |
7336 | 713 |
714 symbol_table::mark_hidden (".nargin."); | |
715 symbol_table::mark_hidden (".nargout."); | |
3974 | 716 |
11557
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
717 symbol_table::mark_automatic (".nargin."); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
718 symbol_table::mark_automatic (".nargout."); |
e9d72a3caa46
mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
719 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
720 symbol_table::assign (".saved_warning_states."); |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
721 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
722 symbol_table::mark_automatic (".saved_warning_states."); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
723 symbol_table::mark_automatic (".saved_warning_states."); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
724 |
3974 | 725 if (takes_varargs ()) |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
726 symbol_table::assign ("varargin", va_args.cell_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11558
diff
changeset
|
727 |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
728 // Force .ignored. variable to be undefined by default. |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
729 symbol_table::assign (".ignored."); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
730 |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
731 if (lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
732 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
733 octave_idx_type nbh = 0; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
734 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
|
735 p != lvalue_list->end (); p++) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
736 nbh += p->is_black_hole (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
737 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
738 if (nbh > 0) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
739 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
740 // 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
|
741 Matrix bh (1, nbh); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17856
diff
changeset
|
742 octave_idx_type k = 0; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17856
diff
changeset
|
743 octave_idx_type l = 0; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
744 for (std::list<octave_lvalue>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
745 p = lvalue_list->begin (); p != lvalue_list->end (); p++) |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
746 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
747 if (p->is_black_hole ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
748 bh(l++) = k+1; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
749 k += p->numel (); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
750 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
751 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16091
diff
changeset
|
752 symbol_table::assign (".ignored.", bh); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
753 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
754 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
755 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
756 symbol_table::mark_hidden (".ignored."); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
757 symbol_table::mark_automatic (".ignored."); |
2974 | 758 } |
759 | |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
760 void |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
761 octave_user_function::restore_warning_states (void) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
762 { |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
763 octave_value val = symbol_table::varval (".saved_warning_states."); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
764 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
765 if (val.is_defined ()) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
766 { |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
767 // Fail spectacularly if .saved_warning_states. is not an |
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
768 // octave_map (or octave_scalar_map) object. |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
769 |
17612
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
770 if (! val.is_map ()) |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
771 panic_impossible (); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
772 |
17612
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
773 octave_map m = val.map_value (); |
4669cfca69a0
avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
774 |
15427
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
775 Cell ids = m.contents ("identifier"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
776 Cell states = m.contents ("state"); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
777 |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
778 for (octave_idx_type i = 0; i < m.numel (); i++) |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
779 Fwarning (ovl (states(i), ids(i))); |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
780 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
781 } |
6823ad7a25b1
implement local option for warnings
John W. Eaton <jwe@octave.org>
parents:
15337
diff
changeset
|
782 |
4700 | 783 DEFUN (nargin, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
784 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
785 @deftypefn {} {} nargin ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
786 @deftypefnx {} {} nargin (@var{fcn})\n\ |
19195 | 787 Report the number of input arguments to a function.\n\ |
788 \n\ | |
789 Called from within a function, return the number of arguments passed to the\n\ | |
790 function. At the top level, return the number of command line arguments\n\ | |
791 passed to Octave.\n\ | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
792 \n\ |
21162 | 793 If called with the optional argument @var{fcn}---a function name or\n\ |
794 handle---return the declared number of arguments that the function can\n\ | |
795 accept.\n\ | |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
796 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
797 If the last argument to @var{fcn} is @var{varargin} the returned value is\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
798 negative. For example, the function @code{union} for sets is declared as\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
799 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
800 @example\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
801 @group\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
802 function [y, ia, ib] = union (a, b, varargin)\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
803 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
804 and\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
805 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
806 nargin (\"union\")\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
807 @result{} -3\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
808 @end group\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
809 @end example\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
810 \n\ |
21162 | 811 Programming Note: @code{nargin} does not work on compiled functions\n\ |
812 (@file{.oct} files) such as built-in or dynamically loaded functions.\n\ | |
19195 | 813 @seealso{nargout, narginchk, varargin, inputname}\n\ |
4700 | 814 @end deftypefn") |
815 { | |
816 int nargin = args.length (); | |
817 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
818 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
819 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
820 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
821 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
822 |
4700 | 823 if (nargin == 1) |
824 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
825 octave_value func = args(0); |
4700 | 826 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
827 if (func.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
828 { |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
829 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
|
830 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
|
831 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
832 error ("nargin: invalid function name: %s", name.c_str ()); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
833 } |
13785
daf81e42960c
allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents:
13749
diff
changeset
|
834 |
21179
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
835 octave_function *fcn_val = func.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
836 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
837 error ("nargin: FCN must be a string or function handle"); |
4700 | 838 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
839 octave_user_function *fcn = fcn_val->user_function_value (true); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
840 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
841 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
842 { |
21179
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
843 // Matlab gives up for histc, so maybe it's ok that that we |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
844 // give up sometimes too? |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
845 |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
846 std::string type = fcn_val->type_name (); |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
847 error ("nargin: number of input arguments unavailable for %s objects", |
8bec8855e9ce
improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21162
diff
changeset
|
848 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
849 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
850 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
851 tree_parameter_list *param_list = fcn->parameter_list (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
852 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
853 retval = param_list ? param_list->length () : 0; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
854 if (fcn->takes_varargs ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
855 retval = -1 - retval; |
4700 | 856 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
857 else |
4700 | 858 { |
7336 | 859 retval = symbol_table::varval (".nargin."); |
4700 | 860 |
7336 | 861 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 retval = 0; |
4700 | 863 } |
864 | |
865 return retval; | |
866 } | |
867 | |
868 DEFUN (nargout, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
869 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
870 @deftypefn {} {} nargout ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
871 @deftypefnx {} {} nargout (@var{fcn})\n\ |
19195 | 872 Report the number of output arguments from a function.\n\ |
873 \n\ | |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
874 Called from within a function, return the number of values the caller\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
875 expects to receive. At the top level, @code{nargout} with no argument is\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
876 undefined and will produce an error.\n\ |
19195 | 877 \n\ |
878 If called with the optional argument @var{fcn}---a function name or\n\ | |
879 handle---return the number of declared output values that the function can\n\ | |
880 produce.\n\ | |
881 \n\ | |
882 If the final output argument is @var{varargout} the returned value is\n\ | |
883 negative.\n\ | |
4700 | 884 \n\ |
885 For example,\n\ | |
886 \n\ | |
887 @example\n\ | |
888 f ()\n\ | |
889 @end example\n\ | |
890 \n\ | |
891 @noindent\n\ | |
4704 | 892 will cause @code{nargout} to return 0 inside the function @code{f} and\n\ |
4700 | 893 \n\ |
894 @example\n\ | |
895 [s, t] = f ()\n\ | |
896 @end example\n\ | |
897 \n\ | |
898 @noindent\n\ | |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
899 will cause @code{nargout} to return 2 inside the function @code{f}.\n\ |
4700 | 900 \n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
901 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
|
902 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
903 @example\n\ |
17757
dae2230227a7
doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
904 nargout (@@histc) \% or nargout (\"histc\")\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
905 @end example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
906 \n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14328
diff
changeset
|
907 @noindent\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
908 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
|
909 \n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
910 @example\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
911 nargout (@@imread)\n\ |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
912 @end example\n\ |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
913 \n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14328
diff
changeset
|
914 @noindent\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
915 will return -2, because @code{imread} has two outputs and the second is\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
916 @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
|
917 \n\ |
19195 | 918 Programming Note. @code{nargout} does not work for built-in functions and\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
919 returns -1 for all anonymous functions.\n\ |
19195 | 920 @seealso{nargin, varargout, isargout, nthargout}\n\ |
4700 | 921 @end deftypefn") |
922 { | |
923 int nargin = args.length (); | |
924 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
925 if (nargin > 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
926 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
927 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
928 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
929 |
4700 | 930 if (nargin == 1) |
931 { | |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
932 octave_value func = args(0); |
4700 | 933 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
934 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
|
935 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
936 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
|
937 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
|
938 if (func.is_undefined ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
939 error ("nargout: invalid function name: %s", name.c_str ()); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
940 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
941 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
942 if (func.is_inline_function ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
943 return ovl (1); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
944 |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
945 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
|
946 { |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
947 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
|
948 std::string fh_nm = fh->fcn_name (); |
4930 | 949 |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
950 if (fh_nm == octave_fcn_handle::anonymous) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
951 return ovl (-1); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
952 } |
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
953 |
21180
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
954 octave_function *fcn_val = func.function_value (true); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
955 if (! fcn_val) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
956 error ("nargout: FCN must be a string or function handle"); |
4700 | 957 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
958 octave_user_function *fcn = fcn_val->user_function_value (true); |
14136
20cb178716ee
Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents:
12483
diff
changeset
|
959 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
960 if (! fcn) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
961 { |
21180
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
962 // Matlab gives up for histc, so maybe it's ok that that we |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
963 // give up sometimes too? |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
964 |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
965 std::string type = fcn_val->type_name (); |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
966 error ("nargout: number of output arguments unavailable for %s objects", |
a428c6ba6334
improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents:
21179
diff
changeset
|
967 type.c_str ()); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
968 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
969 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
970 tree_parameter_list *ret_list = fcn->return_list (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
971 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
972 retval = ret_list ? ret_list->length () : 0; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
973 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
974 if (fcn->takes_var_return ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
975 retval = -1 - retval; |
4700 | 976 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
977 else |
4700 | 978 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
979 if (symbol_table::at_top_level ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
980 error ("nargout: invalid call at top level"); |
4700 | 981 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
982 retval = symbol_table::varval (".nargout."); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
983 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
984 if (retval.is_undefined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
985 retval = 0; |
4700 | 986 } |
987 | |
988 return retval; | |
989 } | |
990 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
991 DEFUN (optimize_subsasgn_calls, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
992 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
993 @deftypefn {} {@var{val} =} optimize_subsasgn_calls ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
994 @deftypefnx {} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
995 @deftypefnx {} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\ |
21072
a9ed4104ecfd
doc: Rewrite documentation for Object Oriented Programming.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
996 Query or set the internal flag for @code{subsasgn} method call\n\ |
a9ed4104ecfd
doc: Rewrite documentation for Object Oriented Programming.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
997 optimizations.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
998 \n\ |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
999 If true, Octave will attempt to eliminate the redundant copying when calling\n\ |
21072
a9ed4104ecfd
doc: Rewrite documentation for Object Oriented Programming.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
1000 the @code{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
|
1001 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16856
diff
changeset
|
1002 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1003 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16856
diff
changeset
|
1004 The original variable value is restored when exiting the function.\n\ |
21072
a9ed4104ecfd
doc: Rewrite documentation for Object Oriented Programming.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
1005 @seealso{subsasgn}\n\ |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1006 @end deftypefn") |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1007 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1008 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
1009 } |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1010 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1011 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
|
1012 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1013 if (table.is_empty ()) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1014 return false; |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1015 |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1016 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
|
1017 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
|
1018 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1019 |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1020 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
|
1021 { |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1022 if (k != xround (k) || k <= 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1023 error ("isargout: K must be a positive integer"); |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
1024 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1025 return (k == 1 || k <= nargout) && ! val_in_table (ignored, k); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1026 } |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1027 |
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1028 DEFUN (isargout, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17757
diff
changeset
|
1029 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20818
diff
changeset
|
1030 @deftypefn {} {} isargout (@var{k})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
1031 Within a function, return a logical value indicating whether the argument\n\ |
19195 | 1032 @var{k} will be assigned to a variable on output.\n\ |
1033 \n\ | |
1034 If the result is false, the argument has been ignored during the function\n\ | |
1035 call through the use of the tilde (~) special output argument. Functions\n\ | |
1036 can use @code{isargout} to avoid performing unnecessary calculations for\n\ | |
1037 outputs which are unwanted.\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11304
diff
changeset
|
1038 \n\ |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14573
diff
changeset
|
1039 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
|
1040 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
|
1041 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
|
1042 @code{isargout} returns an error.\n\ |
19195 | 1043 @seealso{nargout, varargout, nthargout}\n\ |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1044 @end deftypefn") |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1045 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
1046 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1047 print_usage (); |
10847
7fa3c8e43357
change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1048 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1049 if (symbol_table::at_top_level ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1050 error ("isargout: invalid call at top level"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1051 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1052 int nargout1 = symbol_table::varval (".nargout.").int_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1053 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1054 Matrix ignored; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1055 octave_value tmp = symbol_table::varval (".ignored."); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1056 if (tmp.is_defined ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1057 ignored = tmp.matrix_value (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1058 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1059 if (args(0).is_scalar_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1060 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1061 double k = args(0).double_value (); |
20557
b10432a40432
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20501
diff
changeset
|
1062 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1063 return ovl (isargout1 (nargout1, ignored, k)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1064 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1065 else if (args(0).is_numeric_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1066 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1067 const NDArray ka = args(0).array_value (); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1068 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1069 boolNDArray r (ka.dims ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1070 for (octave_idx_type i = 0; i < ka.numel (); i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1071 r(i) = isargout1 (nargout1, ignored, ka(i)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1072 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20921
diff
changeset
|
1073 return ovl (r); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1074 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1075 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21072
diff
changeset
|
1076 err_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
|
1077 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
1078 return ovl (); |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10637
diff
changeset
|
1079 } |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1080 |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1081 /* |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1082 %!function [x, y] = try_isargout () |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1083 %! if (isargout (1)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1084 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1085 %! x = 1; y = 2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1086 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1087 %! x = -1; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1088 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1089 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1090 %! if (isargout (2)) |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1091 %! y = -2; |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1092 %! else |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1093 %! error ("no outputs requested"); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1094 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1095 %! endif |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1096 %!endfunction |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1097 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1098 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1099 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1100 %! assert ([x, y], [1, 2]); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1101 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1102 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1103 %! [x, ~] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1104 %! assert (x, -1); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1105 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1106 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1107 %! [~, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1108 %! assert (y, -2); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1109 %! |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
1110 %!error [~, ~] = try_isargout () |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1111 %! |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1112 %% Check to see that isargout isn't sticky: |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1113 %!test |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1114 %! [x, y] = try_isargout (); |
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1115 %! assert ([x, y], [1, 2]); |
16091
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1116 %! |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1117 %% It should work without (): |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1118 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1119 %! [~, y] = try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1120 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1121 %! |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1122 %% It should work in function handles, anonymous functions, and cell |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1123 %% arrays of handles or anonymous functions. |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1124 %!test |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1125 %! fh = @try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1126 %! af = @() try_isargout; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1127 %! c = {fh, af}; |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1128 %! [~, y] = fh (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1129 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1130 %! [~, y] = af (); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1131 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1132 %! [~, y] = c{1}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1133 %! assert (y, -2); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1134 %! [~, y] = c{2}(); |
1785493171ac
pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents:
15582
diff
changeset
|
1135 %! assert (y, -2); |
14571
6131fead3135
ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1136 */ |