annotate libinterp/octave-value/ov-usr-fcn.cc @ 23729:06b3d1d54054

allow echo state to be modified from inside functions * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::curr_unwind_protect_frame, octave_user_code::unwind_protect_frame): Move variable and accessor function here from octave_user_function. (octave_user_script::call): Also unwind-protect and set current unwind_protect frame variable here. * pt-eval.h, pt-eval.cc (tree_evaluator::set_echo_state, tree_evaluator::maybe_set_echo_state, tree_evaluator::push_echo_state_cleanup, maybe_push_echo_state_cleanup): New functions. (tree_evaluator::push_echo_state): Call push_ech_state_cleanup and set_echo_state. (tree_evaluator::echo): Call maybe_push_echo_state_cleanup and set_echo_state.
author John W. Eaton <jwe@octave.org>
date Wed, 05 Jul 2017 08:37:45 -0400
parents b40b7243a782
children 85f1d31956c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
1 /*
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1996-2017 John W. Eaton
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
4
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
6
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
10 (at your option) any later version.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
15 GNU General Public License for more details.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
16
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6657
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6657
diff changeset
19 <http://www.gnu.org/licenses/>.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
20
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
21 */
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21581
diff changeset
23 #if defined (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
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
25 #endif
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
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
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
29 #include "file-info.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
30 #include "str-vec.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
31
22097
5ad67277b007 include builtin-defun-decls.h as needed
John W. Eaton <jwe@octave.org>
parents: 22096
diff changeset
32 #include "builtin-defun-decls.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
33 #include "call-stack.h"
23466
5da300c55e89 use "" instead of <> for including defaults.h and version.h
John W. Eaton <jwe@octave.org>
parents: 23450
diff changeset
34 #include "defaults.h"
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
35 #include "Cell.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
36 #include "defun.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
37 #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
38 #include "errwarn.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
39 #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
40 #include "ovl.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
41 #include "ov-usr-fcn.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
42 #include "ov.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
43 #include "pager.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
44 #include "pt-eval.h"
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
45 #include "pt-jit.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
46 #include "pt-jump.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
47 #include "pt-misc.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
48 #include "pt-pr-code.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2974
diff changeset
49 #include "pt-stmt.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
50 #include "pt-walk.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
51 #include "symtab.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
52 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
53 #include "interpreter.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
54 #include "unwind-prot.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
55 #include "utils.h"
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3445
diff changeset
56 #include "parse.h"
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
57 #include "profiler.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
58 #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
59 #include "ov-fcn-handle.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
60
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
61 // Whether to optimize subsasgn method calls.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
62 static bool Voptimize_subsasgn_calls = true;
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
63
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
64 octave_user_code::~octave_user_code (void)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
65 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
66 delete m_file_info;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
67 }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
68
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
69 std::string
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
70 octave_user_code::get_code_line (size_t line)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
71 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
72 if (! m_file_info)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
73 m_file_info = new octave::file_info (fcn_file_name ());
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
74
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
75 return m_file_info->get_line (line);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
76 }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
77
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
78 std::deque<std::string>
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
79 octave_user_code::get_code_lines (size_t line, size_t num_lines)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
80 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
81 if (! m_file_info)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
82 m_file_info = new octave::file_info (fcn_file_name ());
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
83
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
84 return m_file_info->get_lines (line, num_lines);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
85 }
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
86
16596
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
87 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
88 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
89 {
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
90 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
91 }
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
92
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
93 // User defined scripts.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
94
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
95 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
96 "user-defined script",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
97 "user-defined script");
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
98
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
99 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
100 : 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
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
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
106 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
107 const std::string& nm,
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
108 octave::tree_statement_list *cmds,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
109 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
110 : 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
111 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
112 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
113 call_depth (-1)
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
114 {
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
115 if (cmd_list)
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
116 cmd_list->mark_as_script_body ();
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
117 }
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
118
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
119 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
120 const std::string& nm,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
121 const std::string& ds)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11558
diff changeset
122 : 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
123 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
124 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
125 call_depth (-1)
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
126 { }
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
127
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
128 octave_user_script::~octave_user_script (void)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
129 {
16530
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
130 if (cmd_list)
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
131 cmd_list->remove_all_breakpoints (file_name);
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
132
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
133 delete cmd_list;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
134 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
135
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
136 octave_value_list
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
137 octave_user_script::call (octave::tree_evaluator& tw, int nargout,
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
138 const octave_value_list& args)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
139 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
140 octave_value_list retval;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
141
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
142 octave::unwind_protect frame;
8011
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
143
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
144 if (args.length () != 0 || nargout != 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
145 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
146
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
147 if (cmd_list)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
148 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
149 frame.protect_var (call_depth);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
150 call_depth++;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
151
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23704
diff changeset
152 if (call_depth >= tw.max_recursion_depth ())
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
153 error ("max_recursion_depth exceeded");
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
154
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
155 octave::call_stack& cs
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
156 = octave::__get_call_stack__ ("octave_user_script::call");
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
157
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
158 cs.push (this);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
159
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
160 // Set pointer to the current unwind_protect frame to allow
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
161 // certain builtins register simple cleanup in a very optimized manner.
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
162 // This is *not* intended as a general-purpose on-cleanup mechanism,
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
163 frame.protect_var (curr_unwind_protect_frame);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
164 curr_unwind_protect_frame = &frame;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
165
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
166 frame.add_method (cs, &octave::call_stack::pop);
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
167
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
168 // Update line number even if debugging.
22164
5d4a286061c8 Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22097
diff changeset
169 frame.protect_var (Vtrack_line_num);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
170 Vtrack_line_num = true;
22164
5d4a286061c8 Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22097
diff changeset
171
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
172 frame.protect_var (octave::tree_evaluator::statement_context);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
173 octave::tree_evaluator::statement_context = octave::tree_evaluator::script;
19327
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 18699
diff changeset
174
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
175 profile_data_accumulator::enter<octave_user_script>
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
176 block (profiler, *this);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
177
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
178 if (tw.echo ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
179 tw.push_echo_state (frame, octave::tree_evaluator::ECHO_SCRIPTS,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
180 file_name);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
181
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
182 cmd_list->accept (tw);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
183
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
184 if (octave::tree_return_command::returning)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
185 octave::tree_return_command::returning = 0;
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
186
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
187 if (octave::tree_break_command::breaking)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
188 octave::tree_break_command::breaking--;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
189 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
190
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
191 return retval;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
192 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
193
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
194 void
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
195 octave_user_script::accept (octave::tree_walker& tw)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
196 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
197 tw.visit_octave_user_script (*this);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
198 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
199
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
200 // User defined functions.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
201
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3178
diff changeset
202 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
203 "user-defined function",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
204 "user-defined function");
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
205
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
206 // Ugh. This really needs to be simplified (code/data?
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
207 // extrinsic/intrinsic state?).
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
208
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
209 octave_user_function::octave_user_function
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
210 (octave::symbol_table::scope *scope, octave::tree_parameter_list *pl,
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
211 octave::tree_parameter_list *rl, octave::tree_statement_list *cl)
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
212 : octave_user_code ("", ""), m_scope (scope),
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
213 param_list (pl), ret_list (rl), cmd_list (cl),
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
214 lead_comm (), trail_comm (), file_name (),
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
215 location_line (0), location_column (0),
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6149
diff changeset
216 parent_name (), t_parsed (static_cast<time_t> (0)),
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3239
diff changeset
217 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
218 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
219 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
220 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
221 anonymous_function (false), nested_function (false),
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
222 class_constructor (none), class_method (false),
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
223 parent_scope (0)
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21581
diff changeset
224 #if defined (HAVE_LLVM)
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
225 , jit_info (0)
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
226 #endif
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
227 {
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
228 if (cmd_list)
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
229 cmd_list->mark_as_function_body ();
9639
8d79f36ebdde store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents: 9529
diff changeset
230
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
231 if (m_scope)
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
232 m_scope->set_function (this);
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
233 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
234
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
235 octave_user_function::~octave_user_function (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
236 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
237 // FIXME: shouldn't this happen automatically when deleting cmd_list?
16530
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
238 if (cmd_list)
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
239 cmd_list->remove_all_breakpoints (file_name);
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
240
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
241 delete m_scope;
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
242
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
243 delete param_list;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
244 delete ret_list;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
245 delete cmd_list;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3565
diff changeset
246 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3565
diff changeset
247 delete trail_comm;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
248
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21581
diff changeset
249 #if defined (HAVE_LLVM)
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
250 delete jit_info;
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
251 #endif
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
252 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
253
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
254 octave_user_function *
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
255 octave_user_function::define_ret_list (octave::tree_parameter_list *t)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
256 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
257 ret_list = t;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
258
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
259 return this;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
260 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
261
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
262 void
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents: 4280
diff changeset
263 octave_user_function::stash_fcn_file_name (const std::string& nm)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
264 {
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents: 4280
diff changeset
265 file_name = nm;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
266 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
267
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
268 // 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
269 // 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
270 // 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
271 // 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
272 // 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
273 // 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
274 // 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
275
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 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
277 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
278 {
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 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
280 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
281 octave::tree_statement *last_stmt = cmd_list->back ();
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
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 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
284 && 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
285 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
286 octave::tree_statement_list::reverse_iterator
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
287 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
288
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 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
290
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 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
292 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
293
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 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
295 {
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 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
297 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
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 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
300 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
301 octave::tree_statement *next_to_last_stmt = *next_to_last_elt;
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
302
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
303 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
304 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
305 }
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
306
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
307 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
308 }
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
309 }
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
310 }
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
311
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
312 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
313 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
314 {
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
315 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
316
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
317 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
318 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22853
diff changeset
319 for (auto& nm_fnval : fcns)
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
320 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22853
diff changeset
321 octave_user_function *f = nm_fnval.second.user_function_value ();
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
322
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
323 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
324 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
325 }
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
326 }
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
327
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
328 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
329 }
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
330
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
331 void
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
332 octave_user_function::stash_parent_fcn_scope (octave::symbol_table::scope *ps)
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
333 {
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
334 parent_scope = ps;
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
335 }
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
336
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
337 std::string
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
338 octave_user_function::profiler_name (void) const
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
339 {
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
340 std::ostringstream result;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
341
18752
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
342 if (is_anonymous_function ())
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
343 result << "anonymous@" << fcn_file_name ()
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
344 << ":" << location_line << ":" << location_column;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
345 else if (is_subfunction ())
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
346 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
347 else if (is_class_method ())
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
348 result << "@" << dispatch_class () << "/" << name ();
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
349 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
350 result << "@" << name ();
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
351 else if (is_inline_function ())
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
352 result << "inline@" << fcn_file_name ()
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18592
diff changeset
353 << ":" << location_line << ":" << location_column;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
354 else
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
355 result << name ();
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
356
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
357 return result.str ();
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
358 }
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
359
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
360 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
361 octave_user_function::mark_as_system_fcn_file (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
362 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
363 if (! file_name.empty ())
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
364 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
365 // We really should stash the whole path to the file we found,
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
366 // when we looked it up, to avoid possible race conditions...
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5744
diff changeset
367 // FIXME
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
368 //
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
369 // We probably also don't need to get the library directory
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
370 // every time, but since this function is only called when the
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
371 // function file is parsed, it probably doesn't matter that
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
372 // much.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
373
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
374 std::string ff_name = fcn_file_in_path (file_name);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
375
23717
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23716
diff changeset
376 std::string fcn_file_dir = octave::config::fcn_file_dir ();
06579337237b move configuration variables inside octave::config namespace
John W. Eaton <jwe@octave.org>
parents: 23716
diff changeset
377 if (fcn_file_dir == ff_name.substr (0, fcn_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
378 system_fcn_file = true;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
379 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
380 else
14866
2309812f428e Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14861
diff changeset
381 system_fcn_file = false;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
382 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
383
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
384 void
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
385 octave_user_function::erase_subfunctions (void)
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
386 {
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
387 m_scope->erase_subfunctions ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
388 }
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
389
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
390 bool
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
391 octave_user_function::takes_varargs (void) const
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
392 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
393 return (param_list && param_list->takes_varargs ());
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
394 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
395
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
396 bool
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
397 octave_user_function::takes_var_return (void) const
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
398 {
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
399 return (ret_list && ret_list->takes_varargs ());
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
400 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
401
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
402 void
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
403 octave_user_function::mark_as_private_function (const std::string& cname)
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
404 {
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
405 m_scope->mark_subfunctions_in_scope_as_private (cname);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
406
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
407 octave_function::mark_as_private_function (cname);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
408 }
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
409
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
410 void
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
411 octave_user_function::lock_subfunctions (void)
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
412 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
413 m_scope->lock_subfunctions ();
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
414 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
415
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
416 void
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
417 octave_user_function::unlock_subfunctions (void)
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
418 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
419 m_scope->unlock_subfunctions ();
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
420 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
421
16596
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
422 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
423 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
424 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
425 return m_scope->subfunctions ();
16596
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
426 }
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
427
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
428 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
429 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
430 {
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
431 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
432 }
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
433
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
434 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
435 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
436 (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
437 {
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
438 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
439 }
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
440
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
441 octave_value_list
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
442 octave_user_function::all_va_args (const octave_value_list& args)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
443 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
444 octave_value_list retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
445
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
446 octave_idx_type n = args.length () - num_named_args;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
447
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
448 if (n > 0)
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
449 retval = args.slice (num_named_args, n);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
450
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
451 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
452 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
453
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
454 octave_value_list
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
455 octave_user_function::call (octave::tree_evaluator& tw, int nargout,
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
456 const octave_value_list& _args)
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
457 {
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
458 octave_value_list retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
459
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
460 if (! cmd_list)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
461 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
462
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
463 // 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
464 // 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
465
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
466 octave_value_list args (_args);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
467 octave_value_list ret_args;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
468
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
469 if (is_classdef_constructor ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
470 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
471 if (args.length () > 0)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
472 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
473 ret_args = args.slice (0, 1, true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
474 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
475 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
476 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
477 panic_impossible ();
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21581
diff changeset
480 #if defined (HAVE_LLVM)
15582
52df2e7baabe Disable JIT when breakpoints are present
Max Brister <max@2bass.com>
parents: 15427
diff changeset
481 if (is_special_expr ()
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
482 && octave::tree_jit::execute (*this, args, retval))
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
483 return retval;
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
484 #endif
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
485
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
486 octave::unwind_protect frame;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
487
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
488 frame.protect_var (call_depth);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
489 call_depth++;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
490
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23704
diff changeset
491 if (call_depth >= tw.max_recursion_depth ())
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
492 error ("max_recursion_depth exceeded");
3131
9c5160c83bd2 [project @ 1998-01-29 04:46:33 by jwe]
jwe
parents: 3014
diff changeset
493
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
494 // Save old and set current symbol table context, for
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
495 // eval_undefined_error().
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
496
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
497 octave::call_stack& cs
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
498 = octave::__get_call_stack__ ("octave_user_function::call");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
499
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
500 octave::symbol_table::context_id context = anonymous_function ? 0 : call_depth;
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
501 cs.push (this, m_scope, context);
22164
5d4a286061c8 Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22097
diff changeset
502
23704
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
503 // Set pointer to the current unwind_protect frame to allow
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
504 // certain builtins register simple cleanup in a very optimized manner.
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
505 // This is *not* intended as a general-purpose on-cleanup mechanism,
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
506 frame.protect_var (curr_unwind_protect_frame);
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
507 curr_unwind_protect_frame = &frame;
c495549e9a94 refactor local protection for internal variables
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
508
22164
5d4a286061c8 Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22097
diff changeset
509 frame.protect_var (Vtrack_line_num);
5d4a286061c8 Track line numbers when in debug mode (bug #45764)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22097
diff changeset
510 Vtrack_line_num = true; // update source line numbers, even if debugging
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
511 frame.add_method (cs, &octave::call_stack::pop);
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
512
14328
19078011cdc3 fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents: 14139
diff changeset
513 if (call_depth > 0 && ! is_anonymous_function ())
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
514 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
515 m_scope->push_context ();
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
516
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
517 #if 0
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
518 std::cerr << name () << " scope: " << m_scope
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
519 << " call depth: " << call_depth
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
520 << " context: " << m_scope->current_context () << std::endl;
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
521 #endif
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
522
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
523 frame.add_method (m_scope, &octave::symbol_table::scope::pop_context);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
524 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
525
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
526 string_vector arg_names = args.name_tags ();
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
527
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
528 if (param_list && ! param_list->varargs_only ())
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
529 {
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
530 #if 0
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
531 std::cerr << "defining param list, scope: " << m_scope
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
532 << ", context: " << m_scope->current_context () << std::endl;
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
533 #endif
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
534 tw.define_parameter_list_from_arg_vector (param_list, args);
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
535 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
536
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
537 // 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
538 // 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
539
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
540 if (is_classdef_constructor ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
541 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
542 if (! ret_list)
20956
850e3d2533d4 maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20941
diff changeset
543 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
544 dispatch_class ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
545
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
546 tw.define_parameter_list_from_arg_vector (ret_list, ret_args);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
547 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
548
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
549 // Force parameter list to be undefined when this function exits.
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
550 // Doing so decrements the reference counts on the values of local
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
551 // variables that are also named function parameters.
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
552
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
553 if (param_list)
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
554 frame.add_method (&tw, &octave::tree_evaluator::undefine_parameter_list,
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
555 param_list);
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
556
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
557 // Force return list to be undefined when this function exits.
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
558 // Doing so decrements the reference counts on the values of local
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
559 // variables that are also named values returned by this function.
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
560
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
561 if (ret_list)
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
562 frame.add_method (&tw, &octave::tree_evaluator::undefine_parameter_list,
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
563 ret_list);
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
564
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
565 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
566 {
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
567 // 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
568 // 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
569 //
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
570 // 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
571 // 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
572 // 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
573 // 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
574 // 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
575 // 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
576
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
577 frame.add_method (m_scope, &octave::symbol_table::scope::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
578 }
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
579
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
580 bind_automatic_vars (tw, arg_names, args.length (), nargout,
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
581 all_va_args (args));
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
582
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
583 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
584
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
585 // Evaluate the commands that make up the function.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
586
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
587 frame.protect_var (octave::tree_evaluator::statement_context);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22173
diff changeset
588 octave::tree_evaluator::statement_context = octave::tree_evaluator::function;
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3445
diff changeset
589
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
590 {
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
591 profile_data_accumulator::enter<octave_user_function>
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
592 block (profiler, *this);
6657
86354a8cd6a7 [project @ 2007-05-23 04:35:04 by jwe]
jwe
parents: 6591
diff changeset
593
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
594 if (tw.echo ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
595 tw.push_echo_state (frame, octave::tree_evaluator::ECHO_FUNCTIONS,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
596 file_name);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
597
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
598 if (is_special_expr ())
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
599 {
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
600 assert (cmd_list->length () == 1);
22253
dbf7fd79e391 More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents: 22196
diff changeset
601
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
602 octave::tree_statement *stmt = cmd_list->front ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
603
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
604 octave::tree_expression *expr = stmt->expression ();
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
605
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
606 if (expr)
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
607 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
608 cs.set_location (stmt->line (), stmt->column ());
22253
dbf7fd79e391 More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents: 22196
diff changeset
609
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
610 retval = tw.evaluate_n (expr, nargout);
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
611 }
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
612 }
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
613 else
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
614 cmd_list->accept (tw);
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
615 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
616
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
617 if (octave::tree_return_command::returning)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
618 octave::tree_return_command::returning = 0;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
619
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
620 if (octave::tree_break_command::breaking)
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
621 octave::tree_break_command::breaking--;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
622
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
623 // Copy return values out.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
624
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
625 if (ret_list && ! is_special_expr ())
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
626 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
627 tw.initialize_undefined_parameter_list_elements (ret_list, my_name,
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
628 nargout, Matrix ());
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
629
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
630 Cell varargout;
6591
fc0218995ee7 [project @ 2007-04-27 02:17:34 by jwe]
jwe
parents: 6505
diff changeset
631
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
632 if (ret_list->takes_varargs ())
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
633 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
634 octave_value varargout_varval = m_scope->varval ("varargout");
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
635
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
636 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
637 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
638 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
639
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
640 retval = tw.convert_parameter_list_to_const_vector (ret_list, nargout, varargout);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
641 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
642
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
643 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
644 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
645
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
646 void
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
647 octave_user_function::accept (octave::tree_walker& tw)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
648 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
649 tw.visit_octave_user_function (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
650 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
651
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
652 octave::tree_expression *
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
653 octave_user_function::special_expr (void)
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
654 {
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
655 assert (is_special_expr ());
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
656 assert (cmd_list->length () == 1);
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
657
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
658 octave::tree_statement *stmt = cmd_list->front ();
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
659 return stmt->expression ();
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
660 }
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
661
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
662 bool
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
663 octave_user_function::subsasgn_optimization_ok (void)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
664 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
665 bool retval = false;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
666 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
667 && param_list && ret_list
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
668 && param_list->length () > 0 && ! param_list->varargs_only ()
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
669 && ret_list->length () == 1 && ! ret_list->takes_varargs ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
670 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
671 octave::tree_identifier *par1 = param_list->front ()->ident ();
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
672 octave::tree_identifier *ret1 = ret_list->front ()->ident ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
673 retval = par1->name () == ret1->name ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
674 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
675
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
676 return retval;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
677 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
678
23680
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
679 std::string
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
680 octave_user_function::ctor_type_str (void) const
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
681 {
23680
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
682 std::string retval;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
683
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
684 switch (class_constructor)
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
685 {
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
686 case none:
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
687 retval = "none";
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
688 break;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
689
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
690 case legacy:
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
691 retval = "legacy";
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
692 break;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
693
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
694 case classdef:
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
695 retval = "classdef";
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
696 break;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
697
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
698 default:
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
699 retval = "unrecognized enum value";
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
700 break;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
701 }
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
702
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
703 return retval;
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
704 }
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
705
23680
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
706 octave_value
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
707 octave_user_function::dump (void) const
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
708 {
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
709 std::map<std::string, octave_value> m
23718
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
710 = {{ "file_name", file_name },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
711 { "line", location_line },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
712 { "col", location_column },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
713 { "end_line", end_location_line },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
714 { "end_col", end_location_column },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
715 { "time_parsed", t_parsed },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
716 { "time_checked", t_checked },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
717 { "parent_name", parent_name },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
718 { "system_fcn_file", system_fcn_file },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
719 { "call_depth", call_depth },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
720 { "num_named_args", num_named_args },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
721 { "subfunction", subfunction },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
722 { "inline_function", inline_function },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
723 { "anonymous_function", anonymous_function },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
724 { "nested_function", nested_function },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
725 { "ctor_type", ctor_type_str () },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
726 { "class_method", class_method },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
727 { "parent_scope", parent_scope ? parent_scope->name () : "0x0" },
251cb33c6570 style fixes for initializer lists
John W. Eaton <jwe@octave.org>
parents: 23717
diff changeset
728 { "scope_info", m_scope ? m_scope->dump () : "0x0" }};
23680
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
729
ef71711f6d64 rework __dump_symbol_table__ function
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
730 return octave_value (m);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
731 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
732
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
733 void
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
734 octave_user_function::print_code_function_header (const std::string& prefix)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
735 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
736 octave::tree_print_code tpc (octave_stdout, prefix);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
737
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
738 tpc.visit_octave_user_function_header (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
739 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
740
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
741 void
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
742 octave_user_function::print_code_function_trailer (const std::string& prefix)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
743 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23718
diff changeset
744 octave::tree_print_code tpc (octave_stdout, prefix);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
745
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
746 tpc.visit_octave_user_function_trailer (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
747 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
748
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
749 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
750 octave_user_function::bind_automatic_vars
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
751 (octave::tree_evaluator& tw, const string_vector& arg_names,
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23466
diff changeset
752 int nargin, int nargout, const octave_value_list& va_args)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
753 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
754 if (! arg_names.empty ())
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
755 {
11558
1e4dfc7a9487 use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents: 11557
diff changeset
756 // 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
757 // 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
758 // 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
759 // 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
760
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
761 charMatrix chm (arg_names, tw.string_fill_char ());
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
762 m_scope->force_assign ("argn", chm);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
763 m_scope->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
764
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
765 m_scope->mark_hidden (".argn.");
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
766
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
767 m_scope->mark_automatic ("argn");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
768 m_scope->mark_automatic (".argn.");
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
769 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
770
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
771 m_scope->force_assign (".nargin.", nargin);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
772 m_scope->force_assign (".nargout.", nargout);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
773
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
774 m_scope->mark_hidden (".nargin.");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
775 m_scope->mark_hidden (".nargout.");
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
776
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
777 m_scope->mark_automatic (".nargin.");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
778 m_scope->mark_automatic (".nargout.");
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
779
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
780 m_scope->assign (".saved_warning_states.");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
781
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
782 m_scope->mark_automatic (".saved_warning_states.");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
783 m_scope->mark_automatic (".saved_warning_states.");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
784
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
785 if (takes_varargs ())
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
786 m_scope->assign ("varargin", va_args.cell_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11558
diff changeset
787
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
788 Matrix ignored_fcn_outputs = tw.ignored_fcn_outputs ();
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
789
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
790 m_scope->assign (".ignored.", ignored_fcn_outputs);
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
791
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
792 m_scope->mark_hidden (".ignored.");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
793 m_scope->mark_automatic (".ignored.");
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
794 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
795
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
796 void
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
797 octave_user_function::restore_warning_states (void)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
798 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
799 octave_value val = m_scope->varval (".saved_warning_states.");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
800
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
801 if (val.is_defined ())
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
802 {
20557
b10432a40432 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20501
diff changeset
803 // 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
804 // octave_map (or octave_scalar_map) object.
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
805
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
806 if (! val.isstruct ())
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
807 panic_impossible ();
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
808
17612
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
809 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
810
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
811 Cell ids = m.contents ("identifier");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
812 Cell states = m.contents ("state");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
813
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
814 octave::interpreter& interp
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
815 = octave::__get_interpreter__ ("octave_user_function::restore_warning_states");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
816
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
817 for (octave_idx_type i = 0; i < m.numel (); i++)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
818 Fwarning (interp, ovl (states(i), ids(i)));
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
819 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
820 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
821
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
822 DEFMETHOD (nargin, interp, args, ,
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
823 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
824 @deftypefn {} {} nargin ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
825 @deftypefnx {} {} nargin (@var{fcn})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
826 Report the number of input arguments to a function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
827
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
828 Called from within a function, return the number of arguments passed to the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
829 function. At the top level, return the number of command line arguments
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
830 passed to Octave.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
831
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
832 If called with the optional argument @var{fcn}---a function name or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
833 handle---return the declared number of arguments that the function can
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
834 accept.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
835
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
836 If the last argument to @var{fcn} is @var{varargin} the returned value is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
837 negative. For example, the function @code{union} for sets is declared as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
838
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
839 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
840 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
841 function [y, ia, ib] = union (a, b, varargin)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
843 and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
844
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
845 nargin ("union")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
846 @result{} -3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
847 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
848 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
849
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
850 Programming Note: @code{nargin} does not work on compiled functions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
851 (@file{.oct} files) such as built-in or dynamically loaded functions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
852 @seealso{nargout, narginchk, varargin, inputname}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
853 @end deftypefn */)
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
854 {
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
855 int nargin = args.length ();
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
856
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
857 if (nargin > 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
858 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
859
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
860 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
861
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
862 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
863
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
864 if (nargin == 1)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
865 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
866 octave_value func = args(0);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
867
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
868 if (func.is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
869 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
870 std::string name = func.string_value ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
871 func = symtab.find_function (name);
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
872 if (func.is_undefined ())
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
873 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
874 }
13785
daf81e42960c allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents: 13749
diff changeset
875
21179
8bec8855e9ce improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21162
diff changeset
876 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
877 if (! fcn_val)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
878 error ("nargin: FCN must be a string or function handle");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
879
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
880 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
881
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
882 if (! fcn)
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
883 {
22173
8de49f15e182 doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 22164
diff changeset
884 // Matlab gives up for histc, so maybe it's ok that we
21179
8bec8855e9ce improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21162
diff changeset
885 // give up sometimes too?
8bec8855e9ce improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21162
diff changeset
886
8bec8855e9ce improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21162
diff changeset
887 std::string type = fcn_val->type_name ();
8bec8855e9ce improve nargin error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21162
diff changeset
888 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
889 type.c_str ());
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
890 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
891
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
892 octave::tree_parameter_list *param_list = fcn->parameter_list ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
893
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23436
diff changeset
894 retval = (param_list ? param_list->length () : 0);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
895 if (fcn->takes_varargs ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
896 retval = -1 - retval;
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
897 }
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
898 else
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
899 {
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
900 octave::symbol_table::scope *scope = symtab.require_current_scope ("nargin");
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
901 retval = scope->varval (".nargin.");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
902
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
903 if (retval.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
904 retval = 0;
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
905 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
906
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
907 return retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
908 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
909
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
910 DEFMETHOD (nargout, interp,args, ,
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
911 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
912 @deftypefn {} {} nargout ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
913 @deftypefnx {} {} nargout (@var{fcn})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
914 Report the number of output arguments from a function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
915
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
916 Called from within a function, return the number of values the caller
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
917 expects to receive. At the top level, @code{nargout} with no argument is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
918 undefined and will produce an error.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
919
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
920 If called with the optional argument @var{fcn}---a function name or
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
921 handle---return the number of declared output values that the function can
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
922 produce.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
923
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
924 If the final output argument is @var{varargout} the returned value is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
925 negative.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
926
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
927 For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
928
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
929 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
930 f ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
931 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
932
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
933 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
934 will cause @code{nargout} to return 0 inside the function @code{f} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
935
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
936 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
937 [s, t] = f ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
938 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
939
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
940 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
941 will cause @code{nargout} to return 2 inside the function @code{f}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
942
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
943 In the second usage,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
944
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
945 @example
22845
e23f7f47d8a3 doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents: 22407
diff changeset
946 nargout (@@histc) # or nargout ("histc") using a string input
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
947 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
948
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
949 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
950 will return 2, because @code{histc} has two outputs, whereas
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
951
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
952 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
953 nargout (@@imread)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
954 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
955
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
956 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
957 will return -2, because @code{imread} has two outputs and the second is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
958 @var{varargout}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
959
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
960 Programming Note. @code{nargout} does not work for built-in functions and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
961 returns -1 for all anonymous functions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
962 @seealso{nargin, varargout, isargout, nthargout}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
963 @end deftypefn */)
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
964 {
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
965 int nargin = args.length ();
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
966
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
967 if (nargin > 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
968 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
969
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
970 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
971
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
972 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
973
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
974 if (nargin == 1)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
975 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
976 octave_value func = args(0);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
977
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
978 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
979 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
980 std::string name = func.string_value ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
981 func = symtab.find_function (name);
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
982 if (func.is_undefined ())
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
983 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
984 }
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
985
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
986 if (func.is_inline_function ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
987 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
988
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
989 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
990 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
991 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
992 std::string fh_nm = fh->fcn_name ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4929
diff changeset
993
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
994 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
995 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
996 }
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
997
21180
a428c6ba6334 improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21179
diff changeset
998 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
999 if (! fcn_val)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1000 error ("nargout: FCN must be a string or function handle");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1001
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1002 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
1003
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1004 if (! fcn)
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1005 {
22173
8de49f15e182 doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 22164
diff changeset
1006 // Matlab gives up for histc, so maybe it's ok that we
21180
a428c6ba6334 improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21179
diff changeset
1007 // give up sometimes too?
a428c6ba6334 improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21179
diff changeset
1008
a428c6ba6334 improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21179
diff changeset
1009 std::string type = fcn_val->type_name ();
a428c6ba6334 improve nargout error message (bug #47021)
John W. Eaton <jwe@octave.org>
parents: 21179
diff changeset
1010 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
1011 type.c_str ());
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1012 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1013
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1014 octave::tree_parameter_list *ret_list = fcn->return_list ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1015
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23436
diff changeset
1016 retval = (ret_list ? ret_list->length () : 0);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1017
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1018 if (fcn->takes_var_return ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1019 retval = -1 - retval;
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1020 }
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
1021 else
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1022 {
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
1023 if (symtab.at_top_level ())
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1024 error ("nargout: invalid call at top level");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1025
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
1026 octave::symbol_table::scope *scope = symtab.require_current_scope ("nargout");
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
1027 retval = scope->varval (".nargout.");
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1028
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1029 if (retval.is_undefined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1030 retval = 0;
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1031 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1032
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1033 return retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1034 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1035
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1036 DEFUN (optimize_subsasgn_calls, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1037 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1038 @deftypefn {} {@var{val} =} optimize_subsasgn_calls ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1039 @deftypefnx {} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1040 @deftypefnx {} {} optimize_subsasgn_calls (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1041 Query or set the internal flag for @code{subsasgn} method call
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1042 optimizations.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1043
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1044 If true, Octave will attempt to eliminate the redundant copying when calling
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1045 the @code{subsasgn} method of a user-defined class.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1046
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1047 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1048 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1049 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1050 @seealso{subsasgn}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1051 @end deftypefn */)
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1052 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1053 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1054 }
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1055
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1056 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
1057 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23553
diff changeset
1058 if (table.isempty ())
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1059 return false;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1060
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1061 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
1062 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
1063 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1064
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1065 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
1066 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
1067 if (k != octave::math::round (k) || k <= 0)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
1068 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
1069
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
1070 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
1071 }
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1072
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
1073 DEFMETHOD (isargout, interp, args, ,
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
1074 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1075 @deftypefn {} {} isargout (@var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1076 Within a function, return a logical value indicating whether the argument
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1077 @var{k} will be assigned to a variable on output.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1078
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1079 If the result is false, the argument has been ignored during the function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1080 call through the use of the tilde (~) special output argument. Functions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1081 can use @code{isargout} to avoid performing unnecessary calculations for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1082 outputs which are unwanted.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1083
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1084 If @var{k} is outside the range @code{1:max (nargout)}, the function returns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1085 false. @var{k} can also be an array, in which case the function works
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1086 element-by-element and a logical array is returned. At the top level,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1087 @code{isargout} returns an error.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1088 @seealso{nargout, varargout, nthargout}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
1089 @end deftypefn */)
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1090 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20797
diff changeset
1091 if (args.length () != 1)
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
1092 print_usage ();
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1093
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
1094 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
1095
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
1096 if (symtab.at_top_level ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1097 error ("isargout: invalid call at top level");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1098
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23680
diff changeset
1099 octave::symbol_table::scope *scope = symtab.require_current_scope ("isargout");
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
1100
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
1101 int nargout1 = scope->varval (".nargout.").int_value ();
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1102
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1103 Matrix ignored;
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
1104 octave_value tmp = scope->varval (".ignored.");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1105 if (tmp.is_defined ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1106 ignored = tmp.matrix_value ();
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1107
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1108 if (args(0).is_scalar_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1109 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1110 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
1111
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1112 return ovl (isargout1 (nargout1, ignored, k));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1113 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23584
diff changeset
1114 else if (args(0).isnumeric ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1115 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1116 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
1117
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1118 boolNDArray r (ka.dims ());
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1119 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
1120 r(i) = isargout1 (nargout1, ignored, ka(i));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1121
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20921
diff changeset
1122 return ovl (r);
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1123 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1124 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
1125 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
1126
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
1127 return ovl ();
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1128 }
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1129
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1130 /*
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1131 %!function [x, y] = try_isargout ()
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1132 %! if (isargout (1))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1133 %! if (isargout (2))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1134 %! x = 1; y = 2;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1135 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1136 %! x = -1;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1137 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1138 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1139 %! if (isargout (2))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1140 %! y = -2;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1141 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1142 %! error ("no outputs requested");
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1143 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1144 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1145 %!endfunction
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1146 %!
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1147 %!function [a, b] = try_isargout2 (x, y)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1148 %! a = y;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1149 %! b = {isargout(1), isargout(2), x};
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1150 %!endfunction
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1151 %!
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1152 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1153 %! [x, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1154 %! assert ([x, y], [1, 2]);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1155 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1156 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1157 %! [x, ~] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1158 %! assert (x, -1);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1159 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1160 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1161 %! [~, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1162 %! assert (y, -2);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1163 %!
21581
6fab85c1538f maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents: 21547
diff changeset
1164 %!error [~, ~] = try_isargout ()
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1165 %!
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22407
diff changeset
1166 ## Check to see that isargout isn't sticky:
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1167 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1168 %! [x, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1169 %! 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
1170 %!
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22407
diff changeset
1171 ## It should work without ():
16091
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1172 %!test
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1173 %! [~, y] = try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1174 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1175 %!
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22407
diff changeset
1176 ## It should work in function handles, anonymous functions, and cell
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22407
diff changeset
1177 ## arrays of handles or anonymous functions.
16091
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1178 %!test
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1179 %! fh = @try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1180 %! af = @() try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1181 %! c = {fh, af};
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1182 %! [~, y] = fh ();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1183 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1184 %! [~, y] = af ();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1185 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1186 %! [~, y] = c{1}();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1187 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1188 %! [~, y] = c{2}();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1189 %! assert (y, -2);
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1190 %!
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1191 ## Nesting, anyone?
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1192 %!test
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1193 %! [~, b] = try_isargout2 (try_isargout, rand);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1194 %! assert (b, {0, 1, -1});
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1195 %!test
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1196 %! [~, b] = try_isargout2 ({try_isargout, try_isargout}, rand);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1197 %! assert (b, {0, 1, {-1, -1}});
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1198 */