Mercurial > hg > octave-lyh
annotate src/ov-usr-fcn.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | cd96d29c5efa |
children | cb0883127251 |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2006, 2007, 2008, 2009 John W. Eaton |
2974 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2974 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2974 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "str-vec.h" | |
29 | |
30 #include <defaults.h> | |
3974 | 31 #include "Cell.h" |
2974 | 32 #include "defun.h" |
33 #include "error.h" | |
34 #include "input.h" | |
35 #include "oct-obj.h" | |
36 #include "ov-usr-fcn.h" | |
37 #include "ov.h" | |
38 #include "pager.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
39 #include "pt-eval.h" |
2985 | 40 #include "pt-jump.h" |
2974 | 41 #include "pt-misc.h" |
42 #include "pt-pr-code.h" | |
2982 | 43 #include "pt-stmt.h" |
2974 | 44 #include "pt-walk.h" |
45 #include "symtab.h" | |
46 #include "toplev.h" | |
47 #include "unwind-prot.h" | |
48 #include "utils.h" | |
3489 | 49 #include "parse.h" |
2974 | 50 #include "variables.h" |
51 | |
3131 | 52 // Maximum nesting level for functions called recursively. |
5794 | 53 static int Vmax_recursion_depth = 256; |
3131 | 54 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
55 // Whether to optimize subsasgn method calls. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
56 static bool Voptimize_subsasgn_calls = true; |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
57 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
58 // User defined scripts. |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
59 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
60 DEFINE_OCTAVE_ALLOCATOR (octave_user_script); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
61 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
62 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
|
63 "user-defined script", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 "user-defined script"); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
65 |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
66 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
|
67 : 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
|
68 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
|
69 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
|
70 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
71 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
72 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
73 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
|
74 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
75 tree_statement_list *cmds, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 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
|
77 : 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
|
78 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
|
79 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
|
80 call_depth (-1) |
7736 | 81 { |
82 if (cmd_list) | |
83 cmd_list->mark_as_script_body (); | |
84 } | |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
85 |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
86 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
|
87 const std::string& nm, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
88 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
|
89 : octave_user_code (nm, ds), cmd_list (0), file_name (fnm), |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
90 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
|
91 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
|
92 call_depth (-1) |
7731
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
93 { } |
2d2a969c731c
fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents:
7719
diff
changeset
|
94 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
95 octave_user_script::~octave_user_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
96 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
97 delete cmd_list; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
98 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
99 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
100 octave_value_list |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
101 octave_user_script::subsref (const std::string&, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 const std::list<octave_value_list>&, int) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
103 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
104 octave_value_list retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
105 |
10001
6918d86add73
Print script filename in script indexing errors
David Grundberg <davidg@cs.umu.se>
parents:
9646
diff
changeset
|
106 ::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
|
107 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
108 return retval; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
109 } |
7336 | 110 |
111 octave_value_list | |
112 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
|
113 const octave_value_list& args) |
7336 | 114 { |
115 octave_value_list retval; | |
116 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
117 unwind_protect frame; |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
118 |
7336 | 119 if (! error_state) |
120 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
121 if (args.length () == 0 && nargout == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 if (cmd_list) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 frame.protect_var (call_depth); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 call_depth++; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
127 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 if (call_depth < Vmax_recursion_depth) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 octave_call_stack::push (this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
131 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
132 frame.add_fcn (octave_call_stack::pop); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
133 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 frame.protect_var (tree_evaluator::in_fcn_or_script_body); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 tree_evaluator::in_fcn_or_script_body = true; |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
136 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 cmd_list->accept (*current_evaluator); |
7336 | 138 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 if (tree_return_command::returning) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 tree_return_command::returning = 0; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
141 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
142 if (tree_break_command::breaking) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 tree_break_command::breaking--; |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
144 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
146 octave_call_stack::backtrace_error_message (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 ::error ("max_recursion_limit exceeded"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 } |
7336 | 152 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 error ("invalid call to script %s", file_name.c_str ()); |
7336 | 154 } |
155 | |
156 return retval; | |
157 } | |
158 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
159 void |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
160 octave_user_script::accept (tree_walker& tw) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
161 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
162 tw.visit_octave_user_script (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
163 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7589
diff
changeset
|
164 |
2974 | 165 // User defined functions. |
166 | |
3219 | 167 DEFINE_OCTAVE_ALLOCATOR (octave_user_function); |
2974 | 168 |
3219 | 169 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
|
170 "user-defined function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 "user-defined function"); |
2974 | 172 |
173 // Ugh. This really needs to be simplified (code/data? | |
174 // extrinsic/intrinsic state?). | |
175 | |
176 octave_user_function::octave_user_function | |
7336 | 177 (symbol_table::scope_id sid, tree_parameter_list *pl, |
178 tree_parameter_list *rl, tree_statement_list *cl) | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
179 : octave_user_code (std::string (), std::string ()), |
2974 | 180 param_list (pl), ret_list (rl), cmd_list (cl), |
7336 | 181 lead_comm (), trail_comm (), file_name (), |
6323 | 182 parent_name (), t_parsed (static_cast<time_t> (0)), |
3255 | 183 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
|
184 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
|
185 num_named_args (param_list ? param_list->length () : 0), |
7336 | 186 nested_function (false), inline_function (false), |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
187 class_constructor (false), class_method (false), |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
188 parent_scope (-1), local_scope (sid) |
7736 | 189 { |
190 if (cmd_list) | |
191 cmd_list->mark_as_function_body (); | |
9639
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
192 |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
193 if (local_scope >= 0) |
8d79f36ebdde
store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents:
9529
diff
changeset
|
194 symbol_table::set_curr_fcn (this, local_scope); |
7736 | 195 } |
2974 | 196 |
197 octave_user_function::~octave_user_function (void) | |
198 { | |
199 delete param_list; | |
200 delete ret_list; | |
201 delete cmd_list; | |
3665 | 202 delete lead_comm; |
203 delete trail_comm; | |
7336 | 204 |
205 symbol_table::erase_scope (local_scope); | |
2974 | 206 } |
207 | |
208 octave_user_function * | |
209 octave_user_function::define_ret_list (tree_parameter_list *t) | |
210 { | |
211 ret_list = t; | |
212 | |
213 return this; | |
214 } | |
215 | |
216 void | |
4343 | 217 octave_user_function::stash_fcn_file_name (const std::string& nm) |
2974 | 218 { |
4343 | 219 file_name = nm; |
2974 | 220 } |
221 | |
222 void | |
223 octave_user_function::mark_as_system_fcn_file (void) | |
224 { | |
225 if (! file_name.empty ()) | |
226 { | |
227 // We really should stash the whole path to the file we found, | |
228 // when we looked it up, to avoid possible race conditions... | |
5775 | 229 // FIXME |
2974 | 230 // |
231 // We probably also don't need to get the library directory | |
232 // every time, but since this function is only called when the | |
233 // function file is parsed, it probably doesn't matter that | |
234 // much. | |
235 | |
3523 | 236 std::string ff_name = fcn_file_in_path (file_name); |
2974 | 237 |
3565 | 238 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 system_fcn_file = 1; |
2974 | 240 } |
241 else | |
242 system_fcn_file = 0; | |
243 } | |
244 | |
245 bool | |
246 octave_user_function::takes_varargs (void) const | |
247 { | |
248 return (param_list && param_list->takes_varargs ()); | |
249 } | |
250 | |
5848 | 251 bool |
252 octave_user_function::takes_var_return (void) const | |
2974 | 253 { |
5848 | 254 return (ret_list && ret_list->takes_varargs ()); |
2974 | 255 } |
256 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
257 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
258 octave_user_function::lock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
259 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
260 symbol_table::lock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
261 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
262 |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
263 void |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
264 octave_user_function::unlock_subfunctions (void) |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
265 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
266 symbol_table::unlock_subfunctions (local_scope); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
267 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
268 |
2974 | 269 octave_value_list |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
270 octave_user_function::all_va_args (const octave_value_list& args) |
2974 | 271 { |
272 octave_value_list retval; | |
273 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
274 octave_idx_type n = args.length () - num_named_args; |
2974 | 275 |
3178 | 276 if (n > 0) |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
277 retval = args.slice (num_named_args, n); |
2974 | 278 |
279 return retval; | |
280 } | |
281 | |
282 octave_value_list | |
4247 | 283 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
|
284 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 int nargout) |
3933 | 286 { |
287 octave_value_list retval; | |
288 | |
289 switch (type[0]) | |
290 { | |
291 case '(': | |
5154 | 292 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 294 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
295 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
5154 | 296 } |
3933 | 297 break; |
298 | |
299 case '{': | |
300 case '.': | |
301 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 304 } |
305 break; | |
306 | |
307 default: | |
308 panic_impossible (); | |
309 } | |
310 | |
5775 | 311 // FIXME -- perhaps there should be an |
4059 | 312 // octave_value_list::next_subsref member function? See also |
313 // octave_builtin::subsref. | |
3933 | 314 |
4219 | 315 if (idx.size () > 1) |
4994 | 316 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 317 |
318 return retval; | |
3933 | 319 } |
320 | |
321 octave_value_list | |
3544 | 322 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
|
323 const octave_value_list& args) |
2974 | 324 { |
325 octave_value_list retval; | |
326 | |
327 if (error_state) | |
328 return retval; | |
329 | |
330 if (! cmd_list) | |
331 return retval; | |
332 | |
333 int nargin = args.length (); | |
334 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
335 unwind_protect frame; |
2974 | 336 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
337 frame.protect_var (call_depth); |
2974 | 338 call_depth++; |
339 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 if (call_depth >= Vmax_recursion_depth) |
3131 | 341 { |
342 ::error ("max_recursion_limit exceeded"); | |
343 return retval; | |
344 } | |
345 | |
7336 | 346 // Save old and set current symbol table context, for |
347 // eval_undefined_error(). | |
348 | |
7901 | 349 octave_call_stack::push (this, local_scope, call_depth); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
350 frame.add_fcn (octave_call_stack::pop); |
7901 | 351 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
352 if (call_depth > 0) |
2974 | 353 { |
7336 | 354 symbol_table::push_context (); |
2974 | 355 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
356 frame.add_fcn (symbol_table::pop_context); |
7336 | 357 } |
2974 | 358 |
359 string_vector arg_names = args.name_tags (); | |
360 | |
361 if (param_list && ! param_list->varargs_only ()) | |
362 { | |
363 param_list->define_from_arg_vector (args); | |
364 if (error_state) | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
365 return retval; |
2974 | 366 } |
367 | |
3239 | 368 // Force parameter list to be undefined when this function exits. |
369 // Doing so decrements the reference counts on the values of local | |
370 // variables that are also named function parameters. | |
371 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
372 if (param_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
373 frame.add_method (param_list, &tree_parameter_list::undefine); |
3239 | 374 |
375 // Force return list to be undefined when this function exits. | |
376 // Doing so decrements the reference counts on the values of local | |
377 // variables that are also named values returned by this function. | |
378 | |
9396
17af7cce7d1b
yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
379 if (ret_list) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
380 frame.add_method (ret_list, &tree_parameter_list::undefine); |
3239 | 381 |
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
|
382 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
|
383 { |
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
|
384 // 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
|
385 // 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
|
386 // |
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
|
387 // 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
|
388 // 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
|
389 // 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
|
390 // 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
|
391 // 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
|
392 // 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
|
393 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
394 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
|
395 } |
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
|
396 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
397 bind_automatic_vars (arg_names, nargin, nargout, all_va_args (args)); |
2974 | 398 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
399 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); |
2974 | 400 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
401 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
402 print_code_function_header (); |
2974 | 403 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
404 // Evaluate the commands that make up the function. |
2974 | 405 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
406 frame.protect_var (tree_evaluator::in_fcn_or_script_body); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
407 tree_evaluator::in_fcn_or_script_body = true; |
3489 | 408 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
409 bool special_expr = (is_inline_function () |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
410 || cmd_list->is_anon_function_body ()); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
411 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
412 if (special_expr) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
413 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
414 assert (cmd_list->length () == 1); |
6657 | 415 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
416 tree_statement *stmt = 0; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
417 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
418 if ((stmt = cmd_list->front ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
419 && stmt->is_expression ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
420 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
421 tree_expression *expr = stmt->expression (); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8580
diff
changeset
|
422 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
423 retval = expr->rvalue (nargout); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
424 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
425 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
426 else |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
427 cmd_list->accept (*current_evaluator); |
2974 | 428 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
429 if (echo_commands) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
430 print_code_function_trailer (); |
2974 | 431 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
432 if (tree_return_command::returning) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
433 tree_return_command::returning = 0; |
2974 | 434 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
435 if (tree_break_command::breaking) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
436 tree_break_command::breaking--; |
2974 | 437 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
438 if (error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
439 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
440 octave_call_stack::backtrace_error_message (); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
441 return retval; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
442 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
443 |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
444 // Copy return values out. |
2974 | 445 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
446 if (ret_list && ! special_expr) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
447 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
448 ret_list->initialize_undefined_elements (my_name, nargout, Matrix ()); |
5848 | 449 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
450 Cell varargout; |
6591 | 451 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
452 if (ret_list->takes_varargs ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
453 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
454 octave_value varargout_varval = symbol_table::varval ("varargout"); |
5848 | 455 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
456 if (varargout_varval.is_defined ()) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
457 { |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
458 varargout = varargout_varval.cell_value (); |
5848 | 459 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
460 if (error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
461 error ("expecting varargout to be a cell array object"); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
462 } |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
463 } |
2974 | 464 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
465 if (! error_state) |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
466 retval = ret_list->convert_to_const_vector (nargout, varargout); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
10001
diff
changeset
|
467 } |
2974 | 468 |
469 return retval; | |
470 } | |
471 | |
472 void | |
473 octave_user_function::accept (tree_walker& tw) | |
474 { | |
475 tw.visit_octave_user_function (*this); | |
476 } | |
477 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
478 bool |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
479 octave_user_function::subsasgn_optimization_ok (void) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
480 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
481 bool retval = false; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
482 if (Voptimize_subsasgn_calls |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
483 && param_list->length () > 0 && ! param_list->varargs_only () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
484 && ret_list->length () == 1 && ! ret_list->takes_varargs ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
485 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
486 tree_identifier *par1 = param_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
487 tree_identifier *ret1 = ret_list->front ()->ident (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
488 retval = par1->name () == ret1->name (); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
489 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
490 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
491 return retval; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
492 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
493 |
7336 | 494 #if 0 |
2974 | 495 void |
3933 | 496 octave_user_function::print_symtab_info (std::ostream& os) const |
497 { | |
7336 | 498 symbol_table::print_info (os, local_scope); |
3933 | 499 } |
7336 | 500 #endif |
3933 | 501 |
502 void | |
2974 | 503 octave_user_function::print_code_function_header (void) |
504 { | |
5794 | 505 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 506 |
507 tpc.visit_octave_user_function_header (*this); | |
508 } | |
509 | |
510 void | |
511 octave_user_function::print_code_function_trailer (void) | |
512 { | |
5794 | 513 tree_print_code tpc (octave_stdout, VPS4); |
2974 | 514 |
515 tpc.visit_octave_user_function_trailer (*this); | |
516 } | |
517 | |
518 void | |
519 octave_user_function::bind_automatic_vars | |
3974 | 520 (const string_vector& arg_names, int nargin, int nargout, |
521 const octave_value_list& va_args) | |
2974 | 522 { |
523 if (! arg_names.empty ()) | |
7336 | 524 symbol_table::varref ("argn") = arg_names; |
2974 | 525 |
7336 | 526 symbol_table::varref (".nargin.") = nargin; |
527 symbol_table::varref (".nargout.") = nargout; | |
528 | |
529 symbol_table::mark_hidden (".nargin."); | |
530 symbol_table::mark_hidden (".nargout."); | |
3974 | 531 |
532 if (takes_varargs ()) | |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8142
diff
changeset
|
533 symbol_table::varref ("varargin") = va_args.cell_value (); |
2974 | 534 } |
535 | |
4700 | 536 DEFUN (nargin, args, , |
537 "-*- texinfo -*-\n\ | |
538 @deftypefn {Built-in Function} {} nargin ()\n\ | |
539 @deftypefnx {Built-in Function} {} nargin (@var{fcn_name})\n\ | |
540 Within a function, return the number of arguments passed to the function.\n\ | |
541 At the top level, return the number of command line arguments passed to\n\ | |
542 Octave. If called with the optional argument @var{fcn_name}, return the\n\ | |
543 maximum number of arguments the named function can accept, or -1 if the\n\ | |
544 function accepts a variable number of arguments.\n\ | |
5642 | 545 @seealso{nargout, varargin, varargout}\n\ |
4700 | 546 @end deftypefn") |
547 { | |
548 octave_value retval; | |
549 | |
550 int nargin = args.length (); | |
551 | |
552 if (nargin == 1) | |
553 { | |
554 std::string fname = args(0).string_value (); | |
555 | |
556 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
558 octave_value fcn_val = symbol_table::find_user_function (fname); |
4930 | 559 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 octave_user_function *fcn = fcn_val.user_function_value (true); |
4700 | 561 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 if (fcn->takes_varargs ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 retval = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
567 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 tree_parameter_list *param_list = fcn->parameter_list (); |
4700 | 569 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
570 retval = param_list ? param_list->length () : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 error ("nargin: invalid function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 } |
4700 | 576 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 error ("nargin: expecting string as first argument"); |
4700 | 578 } |
579 else if (nargin == 0) | |
580 { | |
7336 | 581 retval = symbol_table::varval (".nargin."); |
4700 | 582 |
7336 | 583 if (retval.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 retval = 0; |
4700 | 585 } |
586 else | |
5823 | 587 print_usage (); |
4700 | 588 |
589 return retval; | |
590 } | |
591 | |
592 DEFUN (nargout, args, , | |
593 "-*- texinfo -*-\n\ | |
594 @deftypefn {Built-in Function} {} nargout ()\n\ | |
595 @deftypefnx {Built-in Function} {} nargout (@var{fcn_name})\n\ | |
596 Within a function, return the number of values the caller expects to\n\ | |
597 receive. If called with the optional argument @var{fcn_name}, return the\n\ | |
598 maximum number of values the named function can produce, or -1 if the\n\ | |
599 function can produce a variable number of values.\n\ | |
600 \n\ | |
601 For example,\n\ | |
602 \n\ | |
603 @example\n\ | |
604 f ()\n\ | |
605 @end example\n\ | |
606 \n\ | |
607 @noindent\n\ | |
4704 | 608 will cause @code{nargout} to return 0 inside the function @code{f} and\n\ |
4700 | 609 \n\ |
610 @example\n\ | |
611 [s, t] = f ()\n\ | |
612 @end example\n\ | |
613 \n\ | |
614 @noindent\n\ | |
615 will cause @code{nargout} to return 2 inside the function\n\ | |
616 @code{f}.\n\ | |
617 \n\ | |
618 At the top level, @code{nargout} is undefined.\n\ | |
5642 | 619 @seealso{nargin, varargin, varargout}\n\ |
4700 | 620 @end deftypefn") |
621 { | |
622 octave_value retval; | |
623 | |
624 int nargin = args.length (); | |
625 | |
626 if (nargin == 1) | |
627 { | |
628 std::string fname = args(0).string_value (); | |
629 | |
630 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
632 octave_value fcn_val = symbol_table::find_user_function (fname); |
4930 | 633 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 octave_user_function *fcn = fcn_val.user_function_value (true); |
4700 | 635 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
636 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
637 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
638 if (fcn->takes_var_return ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 retval = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
640 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
642 tree_parameter_list *ret_list = fcn->return_list (); |
4700 | 643 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
644 retval = ret_list ? ret_list->length () : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
645 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
647 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 error ("nargout: invalid function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
649 } |
4700 | 650 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
651 error ("nargout: expecting string as first argument"); |
4700 | 652 } |
653 else if (nargin == 0) | |
654 { | |
7336 | 655 if (! symbol_table::at_top_level ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
656 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
657 retval = symbol_table::varval (".nargout."); |
4700 | 658 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
659 if (retval.is_undefined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
660 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
661 } |
4700 | 662 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
663 error ("nargout: invalid call at top level"); |
4700 | 664 } |
665 else | |
5823 | 666 print_usage (); |
4700 | 667 |
668 return retval; | |
669 } | |
670 | |
5794 | 671 DEFUN (max_recursion_depth, args, nargout, |
672 "-*- texinfo -*-\n\ | |
673 @deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\ | |
674 @deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\ | |
675 Query or set the internal limit on the number of times a function may\n\ | |
676 be called recursively. If the limit is exceeded, an error message is\n\ | |
677 printed and control returns to the top level.\n\ | |
678 @end deftypefn") | |
3131 | 679 { |
5794 | 680 return SET_INTERNAL_VARIABLE (max_recursion_depth); |
2974 | 681 } |
682 | |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
683 DEFUN (optimize_subsasgn_calls, args, nargout, |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
684 "-*- texinfo -*-\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
685 @deftypefn {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
686 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
687 Query or set the internal flag for subsasgn method call optimizations.\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
688 If true, Octave will attempt to eliminate the redundant copying when calling\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
689 subsasgn method of a user-defined class.\n\ |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
690 @end deftypefn") |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
691 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
692 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
693 } |