annotate libinterp/octave-value/ov-usr-fcn.cc @ 20533:19617a5b7202 stable

Fix regression in displayed error message for nargin and nargout. * ov-usr-fcn.cc (nargin, nargout): After printing error message, use 'return retval' to immediately break out of the function.
author Rik <rik@octave.org>
date Tue, 22 Sep 2015 03:08:14 -0700
parents 075a5e2e1ba5
children 1f330d33388f
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19632
diff changeset
3 Copyright (C) 1996-2015 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
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6657
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6657
diff changeset
10 option) any later version.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
11
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
15 for more details.
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
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
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
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
29 #include "str-vec.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
30
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
31 #include <defaults.h>
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
32 #include "Cell.h"
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
33 #include "builtins.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
34 #include "defun.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
35 #include "error.h"
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
36 #include "gripes.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
37 #include "input.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
38 #include "oct-obj.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
39 #include "ov-usr-fcn.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
40 #include "ov.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
41 #include "pager.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
42 #include "pt-eval.h"
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
43 #include "pt-jit.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
44 #include "pt-jump.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
45 #include "pt-misc.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
46 #include "pt-pr-code.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2974
diff changeset
47 #include "pt-stmt.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
48 #include "pt-walk.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
49 #include "symtab.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
50 #include "toplev.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
51 #include "unwind-prot.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
52 #include "utils.h"
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3445
diff changeset
53 #include "parse.h"
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
54 #include "profiler.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
55 #include "variables.h"
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
56 #include "ov-fcn-handle.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
57
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
58 // Whether to optimize subsasgn method calls.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
59 static bool Voptimize_subsasgn_calls = true;
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
60
16856
787de2f144d9 Use string_fill_char when creating argn automatic variable (bug #34183).
Rik <rik@octave.org>
parents: 16627
diff changeset
61 // The character to fill with when creating string arrays.
787de2f144d9 Use string_fill_char when creating argn automatic variable (bug #34183).
Rik <rik@octave.org>
parents: 16627
diff changeset
62 extern char Vstring_fill_char; // see pt-mat.cc
16596
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
63
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
64 std::map<std::string, octave_value>
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
65 octave_user_code::subfunctions (void) const
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
66 {
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
67 return std::map<std::string, octave_value> ();
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
68 }
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
69
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
70 // User defined scripts.
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
71
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
72
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
73 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_script,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
74 "user-defined script",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
75 "user-defined script");
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
76
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
77 octave_user_script::octave_user_script (void)
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
78 : octave_user_code (), cmd_list (0), file_name (),
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
79 t_parsed (static_cast<time_t> (0)),
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
80 t_checked (static_cast<time_t> (0)),
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
81 call_depth (-1)
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
82 { }
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
83
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
84 octave_user_script::octave_user_script (const std::string& fnm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
85 const std::string& nm,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
86 tree_statement_list *cmds,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
87 const std::string& ds)
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
88 : octave_user_code (nm, ds), cmd_list (cmds), file_name (fnm),
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
89 t_parsed (static_cast<time_t> (0)),
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
90 t_checked (static_cast<time_t> (0)),
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
91 call_depth (-1)
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
92 {
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
93 if (cmd_list)
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
94 cmd_list->mark_as_script_body ();
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
95 }
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
96
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
97 octave_user_script::octave_user_script (const std::string& fnm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
98 const std::string& nm,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
99 const std::string& ds)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11558
diff changeset
100 : octave_user_code (nm, ds), cmd_list (0), file_name (fnm),
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
101 t_parsed (static_cast<time_t> (0)),
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
102 t_checked (static_cast<time_t> (0)),
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
103 call_depth (-1)
7731
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
104 { }
2d2a969c731c fix max_recursion_limit exceeded at startup with Intel C++
Jaroslav Hajek <highegg@gmail.com>
parents: 7719
diff changeset
105
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
106 octave_user_script::~octave_user_script (void)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
107 {
16530
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
108 if (cmd_list)
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
109 cmd_list->remove_all_breakpoints (file_name);
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
110
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
111 delete cmd_list;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
112 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
113
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
114 octave_value_list
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
115 octave_user_script::subsref (const std::string&,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
116 const std::list<octave_value_list>&, int)
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
117 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
118 octave_value_list retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
119
10001
6918d86add73 Print script filename in script indexing errors
David Grundberg <davidg@cs.umu.se>
parents: 9646
diff changeset
120 ::error ("invalid use of script %s in index expression", file_name.c_str ());
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
121
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
122 return retval;
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
123 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
124
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
125 octave_value_list
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
126 octave_user_script::do_multi_index_op (int nargout,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
127 const octave_value_list& args)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
128 {
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
129 octave_value_list retval;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
130
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
131 unwind_protect frame;
8011
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
132
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
133 if (! error_state)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
134 {
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
135 if (args.length () == 0 && nargout == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
137 if (cmd_list)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
138 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
139 frame.protect_var (call_depth);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
140 call_depth++;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
141
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
142 if (call_depth < Vmax_recursion_depth)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
143 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
144 octave_call_stack::push (this);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
145
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
146 frame.add_fcn (octave_call_stack::pop);
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
147
11304
c9fefa096ce2 echo commands in scripts
John W. Eaton <jwe@octave.org>
parents: 10848
diff changeset
148 frame.protect_var (tree_evaluator::statement_context);
c9fefa096ce2 echo commands in scripts
John W. Eaton <jwe@octave.org>
parents: 10848
diff changeset
149 tree_evaluator::statement_context = tree_evaluator::script;
8669
33783e94fb16 line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
150
19361
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 18740
diff changeset
151 BEGIN_PROFILER_BLOCK (octave_user_script)
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 18740
diff changeset
152
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
153 cmd_list->accept (*current_evaluator);
19361
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 18740
diff changeset
154
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
155 END_PROFILER_BLOCK
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
156
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
157 if (tree_return_command::returning)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
158 tree_return_command::returning = 0;
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
159
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
160 if (tree_break_command::breaking)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
161 tree_break_command::breaking--;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
162 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
163 else
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
164 ::error ("max_recursion_depth exceeded");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
165 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
166 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
167 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
168 error ("invalid call to script %s", file_name.c_str ());
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
169 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
170
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
171 return retval;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
172 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
173
7715
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
174 void
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
175 octave_user_script::accept (tree_walker& tw)
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
176 {
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
177 tw.visit_octave_user_script (*this);
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
178 }
5b4d278ec828 parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents: 7589
diff changeset
179
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
180 // User defined functions.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
181
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
182
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3178
diff changeset
183 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
184 "user-defined function",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
185 "user-defined function");
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
186
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
187 // Ugh. This really needs to be simplified (code/data?
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
188 // extrinsic/intrinsic state?).
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
189
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
190 octave_user_function::octave_user_function
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
191 (symbol_table::scope_id sid, tree_parameter_list *pl,
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
192 tree_parameter_list *rl, tree_statement_list *cl)
7719
87eda1f8faaa octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents: 7715
diff changeset
193 : octave_user_code (std::string (), std::string ()),
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
194 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
195 lead_comm (), trail_comm (), file_name (),
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
196 location_line (0), location_column (0),
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6149
diff changeset
197 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
198 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
199 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
200 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
201 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
202 anonymous_function (false), nested_function (false),
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
203 class_constructor (none), class_method (false),
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14366
diff changeset
204 parent_scope (-1), local_scope (sid),
10637
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
205 curr_unwind_protect_frame (0)
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
206 #ifdef HAVE_LLVM
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
207 , jit_info (0)
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
208 #endif
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
209 {
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
210 if (cmd_list)
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
211 cmd_list->mark_as_function_body ();
9639
8d79f36ebdde store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents: 9529
diff changeset
212
8d79f36ebdde store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents: 9529
diff changeset
213 if (local_scope >= 0)
8d79f36ebdde store scope->function pointer
Jaroslav Hajek <highegg@gmail.com>
parents: 9529
diff changeset
214 symbol_table::set_curr_fcn (this, local_scope);
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7731
diff changeset
215 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
216
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
217 octave_user_function::~octave_user_function (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
218 {
16530
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
219 if (cmd_list)
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
220 cmd_list->remove_all_breakpoints (file_name);
7ca7e7d5eb91 remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents: 16442
diff changeset
221
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
222 delete param_list;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
223 delete ret_list;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
224 delete cmd_list;
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3565
diff changeset
225 delete lead_comm;
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3565
diff changeset
226 delete trail_comm;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
227
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
228 #ifdef HAVE_LLVM
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
229 delete jit_info;
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
230 #endif
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
231
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
232 // FIXME: this is really playing with fire.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
233 symbol_table::erase_scope (local_scope);
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
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
236 octave_user_function *
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
237 octave_user_function::define_ret_list (tree_parameter_list *t)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
238 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
239 ret_list = t;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
240
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
241 return this;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
242 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
243
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
244 void
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents: 4280
diff changeset
245 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
246 {
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents: 4280
diff changeset
247 file_name = nm;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
248 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
249
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
250 // 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
251 // 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
252 // 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
253 // 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
254 // 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
255 // 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
256 // 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
257
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
258 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
259 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
260 {
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
261 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
262 {
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
263 tree_statement *last_stmt = cmd_list->back ();
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
264
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
265 if (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
266 && 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
267 {
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 tree_statement_list::reverse_iterator
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
269 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
270
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 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
272
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 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
274 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
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 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
277 {
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
278 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
279 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
280 }
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
281 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
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 tree_statement *next_to_last_stmt = *next_to_last_elt;
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
284
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 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
286 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
287 }
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
288
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 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
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 }
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
292 }
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
293
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 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
295 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
296 {
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 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
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 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
300 {
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
301 for (std::map<std::string, octave_value>::iterator p = fcns.begin ();
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
302 p != fcns.end (); p++)
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
303 {
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 octave_user_function *f = (p->second).user_function_value ();
de91b1621260 adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents: 16605
diff changeset
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 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
307 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
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 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
312 }
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
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
314 std::string
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
315 octave_user_function::profiler_name (void) const
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
316 {
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
317 std::ostringstream result;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
318
18786
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
319 if (is_anonymous_function ())
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
320 result << "anonymous@" << fcn_file_name ()
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
321 << ":" << location_line << ":" << location_column;
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
322 else if (is_subfunction ())
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
323 result << parent_fcn_name () << ">" << name ();
18786
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
324 else if (is_class_method ())
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
325 result << "@" << dispatch_class () << "/" << name ();
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
326 else if (is_class_constructor () || is_classdef_constructor ())
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
327 result << "@" << name ();
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
328 else if (is_inline_function ())
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
329 result << "inline@" << fcn_file_name ()
e70373a98ffe Change profile() to report method names of classes (bug #38480).
Rik <rik@octave.org>
parents: 18626
diff changeset
330 << ":" << location_line << ":" << location_column;
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
331 else
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
332 result << name ();
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
333
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
334 return result.str ();
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
335 }
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 12546
diff changeset
336
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
337 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
338 octave_user_function::mark_as_system_fcn_file (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
339 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
340 if (! file_name.empty ())
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
341 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
342 // 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
343 // 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
344 // FIXME
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
345 //
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
346 // 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
347 // 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
348 // function file is parsed, it probably doesn't matter that
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
349 // much.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
350
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3489
diff changeset
351 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
352
3565
4290f11c8d3b [project @ 2000-02-03 08:32:41 by jwe]
jwe
parents: 3544
diff changeset
353 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ()))
14866
2309812f428e Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14861
diff changeset
354 system_fcn_file = true;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
355 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
356 else
14866
2309812f428e Use explicit false and true instead of 0 and 1
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14861
diff changeset
357 system_fcn_file = false;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
358 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
359
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
360 bool
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
361 octave_user_function::takes_varargs (void) const
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 return (param_list && param_list->takes_varargs ());
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
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
366 bool
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
367 octave_user_function::takes_var_return (void) const
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
368 {
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
369 return (ret_list && ret_list->takes_varargs ());
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
370 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
371
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
372 void
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
373 octave_user_function::lock_subfunctions (void)
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
374 {
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
375 symbol_table::lock_subfunctions (local_scope);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
376 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
377
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
378 void
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
379 octave_user_function::unlock_subfunctions (void)
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
380 {
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
381 symbol_table::unlock_subfunctions (local_scope);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
382 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7752
diff changeset
383
16596
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
384 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
385 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
386 {
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
387 return symbol_table::subfunctions_defined_in_scope (local_scope);
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
388 }
645672f1c873 handle setting breakpoints in subfunctions in GUI editor
John W. Eaton <jwe@octave.org>
parents: 16530
diff changeset
389
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
390 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
391 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
392 {
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
393 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
394 }
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
395
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
396 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
397 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
398 (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
399 {
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
400 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
401 }
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
402
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
403 octave_value_list
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
404 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
405 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
406 octave_value_list retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
407
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
408 octave_idx_type n = args.length () - num_named_args;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
409
3178
09a3064a3a17 [project @ 1998-06-23 03:46:42 by jwe]
jwe
parents: 3165
diff changeset
410 if (n > 0)
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
411 retval = args.slice (num_named_args, n);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
412
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
413 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
414 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
415
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
416 octave_value_list
4247
fc9a075d10fb [project @ 2002-12-30 23:05:27 by jwe]
jwe
parents: 4245
diff changeset
417 octave_user_function::subsref (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
418 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
419 int nargout)
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
420 {
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
421 return octave_user_function::subsref (type, idx, nargout, 0);
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
422 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
423
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
424 octave_value_list
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
425 octave_user_function::subsref (const std::string& type,
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
426 const std::list<octave_value_list>& idx,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
427 int nargout,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
428 const std::list<octave_lvalue>* lvalue_list)
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
429 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
430 octave_value_list retval;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
431
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
432 switch (type[0])
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
433 {
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
434 case '(':
5154
9cb38bfb04ea [project @ 2005-02-21 21:23:28 by jwe]
jwe
parents: 5105
diff changeset
435 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
5154
9cb38bfb04ea [project @ 2005-02-21 21:23:28 by jwe]
jwe
parents: 5105
diff changeset
437
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
438 retval = do_multi_index_op (tmp_nargout, idx.front (),
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
439 idx.size () == 1 ? lvalue_list : 0);
5154
9cb38bfb04ea [project @ 2005-02-21 21:23:28 by jwe]
jwe
parents: 5105
diff changeset
440 }
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
441 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
442
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
443 case '{':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
444 case '.':
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
445 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
446 std::string nm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
447 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
448 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
449 break;
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
450
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
451 default:
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
452 panic_impossible ();
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
453 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
454
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
455 // FIXME: perhaps there should be an
4059
db58c1a1e6ce [project @ 2002-09-18 07:21:12 by jwe]
jwe
parents: 3975
diff changeset
456 // octave_value_list::next_subsref member function? See also
db58c1a1e6ce [project @ 2002-09-18 07:21:12 by jwe]
jwe
parents: 3975
diff changeset
457 // octave_builtin::subsref.
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
458
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4207
diff changeset
459 if (idx.size () > 1)
4994
48d0defe9445 [project @ 2004-09-15 20:31:31 by jwe]
jwe
parents: 4987
diff changeset
460 retval = retval(0).next_subsref (nargout, type, idx);
4059
db58c1a1e6ce [project @ 2002-09-18 07:21:12 by jwe]
jwe
parents: 3975
diff changeset
461
db58c1a1e6ce [project @ 2002-09-18 07:21:12 by jwe]
jwe
parents: 3975
diff changeset
462 return retval;
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
463 }
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
464
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
465 octave_value_list
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3523
diff changeset
466 octave_user_function::do_multi_index_op (int nargout,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
467 const octave_value_list& args)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
468 {
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
469 return do_multi_index_op (nargout, args, 0);
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
470 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
471
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
472 octave_value_list
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
473 octave_user_function::do_multi_index_op (int nargout,
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
474 const octave_value_list& _args,
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
475 const std::list<octave_lvalue>* lvalue_list)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
476 {
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
477 octave_value_list retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
478
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
479 if (error_state)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
480 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
481
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
482 if (! cmd_list)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
483 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
484
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
485 // 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
486 // 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
487
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
488 octave_value_list args (_args);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
489 octave_value_list ret_args;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
490
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
491 if (is_classdef_constructor ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
492 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
493 if (args.length () > 0)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
494 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
495 ret_args = args.slice (0, 1, true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
496 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
497 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
498 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
499 panic_impossible ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
500 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
501
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
502 #ifdef HAVE_LLVM
15582
52df2e7baabe Disable JIT when breakpoints are present
Max Brister <max@2bass.com>
parents: 15427
diff changeset
503 if (is_special_expr ()
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
504 && tree_jit::execute (*this, args, retval))
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
505 return retval;
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
506 #endif
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
507
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
508 int nargin = args.length ();
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
509
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
510 unwind_protect frame;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
511
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
512 frame.protect_var (call_depth);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
513 call_depth++;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
514
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
515 if (call_depth >= Vmax_recursion_depth)
3131
9c5160c83bd2 [project @ 1998-01-29 04:46:33 by jwe]
jwe
parents: 3014
diff changeset
516 {
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
517 ::error ("max_recursion_depth exceeded");
3131
9c5160c83bd2 [project @ 1998-01-29 04:46:33 by jwe]
jwe
parents: 3014
diff changeset
518 return retval;
9c5160c83bd2 [project @ 1998-01-29 04:46:33 by jwe]
jwe
parents: 3014
diff changeset
519 }
9c5160c83bd2 [project @ 1998-01-29 04:46:33 by jwe]
jwe
parents: 3014
diff changeset
520
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
521 // Save old and set current symbol table context, for
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
522 // eval_undefined_error().
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
523
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14366
diff changeset
524 int context = active_context ();
14328
19078011cdc3 fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents: 14139
diff changeset
525
19078011cdc3 fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents: 14139
diff changeset
526 octave_call_stack::push (this, local_scope, context);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
527 frame.add_fcn (octave_call_stack::pop);
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
528
14328
19078011cdc3 fix problem with recursion and anonymous functions (bug #31371)
John W. Eaton <jwe@octave.org>
parents: 14139
diff changeset
529 if (call_depth > 0 && ! is_anonymous_function ())
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
530 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
531 symbol_table::push_context ();
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
532
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
533 frame.add_fcn (symbol_table::pop_context);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
534 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
535
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
536 string_vector arg_names = args.name_tags ();
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
537
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
538 if (param_list && ! param_list->varargs_only ())
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
539 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
540 param_list->define_from_arg_vector (args);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
541 if (error_state)
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
542 return retval;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
543 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
544
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
545 // 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
546 // 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
547
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
548 if (is_classdef_constructor ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
549 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
550 if (ret_list)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
551 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
552 ret_list->define_from_arg_vector (ret_args);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
553 if (error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
554 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
555 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
556 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
557 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
558 ::error ("%s: invalid classdef constructor, no output argument defined",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
559 dispatch_class ().c_str ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
560 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
561 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
562 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15582
diff changeset
563
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
564 // 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
565 // 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
566 // variables that are also named function parameters.
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
567
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
568 if (param_list)
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
569 frame.add_method (param_list, &tree_parameter_list::undefine);
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
570
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
571 // 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
572 // 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
573 // 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
574
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
575 if (ret_list)
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
576 frame.add_method (ret_list, &tree_parameter_list::undefine);
3239
d54ef0aa6e82 [project @ 1999-03-27 17:40:45 by jwe]
jwe
parents: 3219
diff changeset
577
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 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
579 {
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
580 // 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
581 // 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
582 //
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
583 // 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
584 // 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
585 // 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
586 // 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
587 // 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
588 // 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
589
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
590 frame.add_fcn (symbol_table::clear_variables);
8142
54b41376e381 ov-usr-fcn.cc (octave_user_function::do_multi_index_op): add symbol_table::clear_variables cleanup function to the unwind_protect stack after the parameter list cleanup functions
John W. Eaton <jwe@octave.org>
parents: 8013
diff changeset
591 }
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
592
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
593 bind_automatic_vars (arg_names, nargin, nargout, all_va_args (args),
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
594 lvalue_list);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
595
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
596 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
597
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
598 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
599
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
600 if (echo_commands)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
601 print_code_function_header ();
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
602
10637
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
603 // Set pointer to the current unwind_protect frame to allow
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
604 // certain builtins register simple cleanup in a very optimized manner.
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
605 // This is *not* intended as a general-purpose on-cleanup mechanism,
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
606 frame.protect_var (curr_unwind_protect_frame);
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
607 curr_unwind_protect_frame = &frame;
9cd5aa83fa62 implement 'local' parameter to pseudo-variables
Jaroslav Hajek <highegg@gmail.com>
parents: 10578
diff changeset
608
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
609 // Evaluate the commands that make up the function.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
610
11304
c9fefa096ce2 echo commands in scripts
John W. Eaton <jwe@octave.org>
parents: 10848
diff changeset
611 frame.protect_var (tree_evaluator::statement_context);
c9fefa096ce2 echo commands in scripts
John W. Eaton <jwe@octave.org>
parents: 10848
diff changeset
612 tree_evaluator::statement_context = tree_evaluator::function;
3489
cbee5fbb696d [project @ 2000-01-28 09:14:32 by jwe]
jwe
parents: 3445
diff changeset
613
19361
91cd85a75705 Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents: 18740
diff changeset
614 BEGIN_PROFILER_BLOCK (octave_user_function)
6657
86354a8cd6a7 [project @ 2007-05-23 04:35:04 by jwe]
jwe
parents: 6591
diff changeset
615
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
616 if (is_special_expr ())
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
617 {
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
618 tree_expression *expr = special_expr ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8580
diff changeset
619
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
620 if (expr)
16091
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
621 retval = (lvalue_list
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
622 ? expr->rvalue (nargout, lvalue_list)
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
623 : expr->rvalue (nargout));
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
624 }
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
625 else
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
626 cmd_list->accept (*current_evaluator);
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
627
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
628 END_PROFILER_BLOCK
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
629
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
630 if (echo_commands)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
631 print_code_function_trailer ();
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
632
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
633 if (tree_return_command::returning)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
634 tree_return_command::returning = 0;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
635
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
636 if (tree_break_command::breaking)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
637 tree_break_command::breaking--;
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
638
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
639 if (error_state)
19449
972abb60c30f emit stack trace immediately at point of error
John W. Eaton <jwe@octave.org>
parents: 19362
diff changeset
640 return retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11558
diff changeset
641
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
642 // Copy return values out.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
643
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
644 if (ret_list && ! is_special_expr ())
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
645 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
646 ret_list->initialize_undefined_elements (my_name, nargout, Matrix ());
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
647
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
648 Cell varargout;
6591
fc0218995ee7 [project @ 2007-04-27 02:17:34 by jwe]
jwe
parents: 6505
diff changeset
649
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
650 if (ret_list->takes_varargs ())
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
651 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
652 octave_value varargout_varval = symbol_table::varval ("varargout");
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
653
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
654 if (varargout_varval.is_defined ())
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
655 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
656 varargout = varargout_varval.cell_value ();
5848
415ae81d331b [project @ 2006-06-08 20:37:29 by jwe]
jwe
parents: 5823
diff changeset
657
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
658 if (error_state)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
659 error ("expecting varargout to be a cell array object");
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
660 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
661 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
662
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
663 if (! error_state)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
664 retval = ret_list->convert_to_const_vector (nargout, varargout);
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10001
diff changeset
665 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
666
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
667 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
668 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
669
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
670 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
671 octave_user_function::accept (tree_walker& tw)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
672 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
673 tw.visit_octave_user_function (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
674 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
675
15337
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
676 tree_expression *
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
677 octave_user_function::special_expr (void)
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
678 {
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
679 assert (is_special_expr ());
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
680 assert (cmd_list->length () == 1);
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
681
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
682 tree_statement *stmt = cmd_list->front ();
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
683 return stmt->expression ();
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
684 }
3f43e9d6d86e JIT compile anonymous functions
Max Brister <max@2bass.com>
parents: 15236
diff changeset
685
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
686 bool
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
687 octave_user_function::subsasgn_optimization_ok (void)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
688 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
689 bool retval = false;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
690 if (Voptimize_subsasgn_calls
18740
e3fca7930c1e Fix segfault if subsasgn in @class returns no output (bug #41945)
Stefan Mahr <dac922@gmx.de>
parents: 18533
diff changeset
691 && param_list && ret_list
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
692 && param_list->length () > 0 && ! param_list->varargs_only ()
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
693 && ret_list->length () == 1 && ! ret_list->takes_varargs ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
694 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
695 tree_identifier *par1 = param_list->front ()->ident ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
696 tree_identifier *ret1 = ret_list->front ()->ident ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
697 retval = par1->name () == ret1->name ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
698 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
699
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
700 return retval;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
701 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
702
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
703 #if 0
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
704 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
705 octave_user_function::print_symtab_info (std::ostream& os) const
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
706 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
707 symbol_table::print_info (os, local_scope);
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
708 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
709 #endif
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
710
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3876
diff changeset
711 void
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
712 octave_user_function::print_code_function_header (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
713 {
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
714 tree_print_code tpc (octave_stdout, VPS4);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
715
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
716 tpc.visit_octave_user_function_header (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
717 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
718
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
719 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
720 octave_user_function::print_code_function_trailer (void)
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
721 {
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
722 tree_print_code tpc (octave_stdout, VPS4);
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
723
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
724 tpc.visit_octave_user_function_trailer (*this);
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
725 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
726
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
727 void
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
728 octave_user_function::bind_automatic_vars
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
729 (const string_vector& arg_names, int nargin, int nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
730 const octave_value_list& va_args,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
731 const std::list<octave_lvalue> *lvalue_list)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
732 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
733 if (! arg_names.empty ())
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
734 {
11558
1e4dfc7a9487 use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents: 11557
diff changeset
735 // 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
736 // 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
737 // 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
738 // 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
739
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
740 symbol_table::force_assign ("argn",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
741 charMatrix (arg_names, Vstring_fill_char));
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
742 symbol_table::force_assign (".argn.", Cell (arg_names));
11558
1e4dfc7a9487 use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents: 11557
diff changeset
743
1e4dfc7a9487 use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents: 11557
diff changeset
744 symbol_table::mark_hidden (".argn.");
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
745
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
746 symbol_table::mark_automatic ("argn");
11558
1e4dfc7a9487 use .argn. to store argument names for inputname function
John W. Eaton <jwe@octave.org>
parents: 11557
diff changeset
747 symbol_table::mark_automatic (".argn.");
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
748 }
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
749
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
750 symbol_table::force_assign (".nargin.", nargin);
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
751 symbol_table::force_assign (".nargout.", nargout);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
752
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
753 symbol_table::mark_hidden (".nargin.");
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
754 symbol_table::mark_hidden (".nargout.");
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
755
11557
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
756 symbol_table::mark_automatic (".nargin.");
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
757 symbol_table::mark_automatic (".nargout.");
e9d72a3caa46 mark automatic variables as automatic
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
758
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
759 symbol_table::assign (".saved_warning_states.");
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
760
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
761 symbol_table::mark_automatic (".saved_warning_states.");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
762 symbol_table::mark_automatic (".saved_warning_states.");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
763
3974
e2290bf911f0 [project @ 2002-07-04 17:38:22 by jwe]
jwe
parents: 3933
diff changeset
764 if (takes_varargs ())
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
765 symbol_table::assign ("varargin", va_args.cell_value ());
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11558
diff changeset
766
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
767 // Force .ignored. variable to be undefined by default.
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
768 symbol_table::assign (".ignored.");
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
769
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
770 if (lvalue_list)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
771 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
772 octave_idx_type nbh = 0;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
773 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
774 p != lvalue_list->end (); p++)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
775 nbh += p->is_black_hole ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
776
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
777 if (nbh > 0)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
778 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
779 // Only assign the hidden variable if black holes actually present.
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
780 Matrix bh (1, nbh);
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17856
diff changeset
781 octave_idx_type k = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17856
diff changeset
782 octave_idx_type l = 0;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
783 for (std::list<octave_lvalue>::const_iterator
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
784 p = lvalue_list->begin (); p != lvalue_list->end (); p++)
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
785 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
786 if (p->is_black_hole ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
787 bh(l++) = k+1;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
788 k += p->numel ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
789 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
790
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16091
diff changeset
791 symbol_table::assign (".ignored.", bh);
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
792 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
793 }
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
794
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
795 symbol_table::mark_hidden (".ignored.");
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
796 symbol_table::mark_automatic (".ignored.");
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
797 }
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
798
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
799 void
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
800 octave_user_function::restore_warning_states (void)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
801 {
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
802 octave_value val = symbol_table::varval (".saved_warning_states.");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
803
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
804 if (val.is_defined ())
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
805 {
17612
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
806 // Don't use the usual approach of attempting to extract a value
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
807 // and then checking error_state since this code might be
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
808 // executing when error_state is already set. But do fail
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
809 // spectacularly if .saved_warning_states. is not an octave_map
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
810 // (or octave_scalar_map) object.
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
811
17612
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
812 if (! val.is_map ())
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
813 panic_impossible ();
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
814
17612
4669cfca69a0 avoid crash when restoring warning states (bug #40199)
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
815 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
816
15427
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
817 Cell ids = m.contents ("identifier");
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
818 Cell states = m.contents ("state");
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 for (octave_idx_type i = 0; i < m.numel (); i++)
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
821 Fwarning (ovl (states(i), ids(i)));
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
822 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
823 }
6823ad7a25b1 implement local option for warnings
John W. Eaton <jwe@octave.org>
parents: 15337
diff changeset
824
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
825 DEFUN (nargin, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
826 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10832
diff changeset
827 @deftypefn {Built-in Function} {} nargin ()\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
828 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
829 Report the number of input arguments to a function.\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
830 \n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
831 Called from within a function, return the number of arguments passed to the\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
832 function. At the top level, return the number of command line arguments\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
833 passed to Octave.\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
834 \n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
835 If called with the optional argument @var{fcn}---a function name or handle---\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
836 return the declared number of arguments that the function can accept.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
837 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
838 If the last argument to @var{fcn} is @var{varargin} the returned value is\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
839 negative. For example, the function @code{union} for sets is declared as\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
840 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
841 @example\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
842 @group\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
843 function [y, ia, ib] = union (a, b, varargin)\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
844 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
845 and\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
846 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
847 nargin (\"union\")\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
848 @result{} -3\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
849 @end group\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
850 @end example\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
851 \n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
852 Programming Note: @code{nargin} does not work on built-in functions.\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
853 @seealso{nargout, narginchk, varargin, inputname}\n\
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
854 @end deftypefn")
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
855 {
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
856 octave_value retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
857
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
858 int nargin = args.length ();
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
859
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
860 if (nargin == 1)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
861 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
862 octave_value func = args(0);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
863
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
864 if (func.is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
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 std::string name = func.string_value ();
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
867 func = symbol_table::find_function (name);
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
868 if (func.is_undefined ())
20533
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
869 {
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
870 error ("nargin: invalid function name: %s", name.c_str ());
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
871 return retval;
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
872 }
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
873 }
13785
daf81e42960c allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents: 13749
diff changeset
874
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
875 octave_function *fcn_val = func.function_value ();
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
876 if (fcn_val)
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
877 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
878 octave_user_function *fcn = fcn_val->user_function_value (true);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
879
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
880 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
881 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
882 tree_parameter_list *param_list = fcn->parameter_list ();
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
883
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
884 retval = param_list ? param_list->length () : 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
885 if (fcn->takes_varargs ())
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
886 retval = -1 - retval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
888 else
13785
daf81e42960c allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents: 13749
diff changeset
889 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
890 // Matlab gives up for histc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
891 // so maybe it's ok that that we give up somtimes too?
18915
4cdab2973171 maint: Fix some spellings in error messages.
Rik <rik@octave.org>
parents: 18795
diff changeset
892 error ("nargin: nargin information not available for built-in functions");
13785
daf81e42960c allow nargin to work for functions that are not already loaded
John W. Eaton <jwe@octave.org>
parents: 13749
diff changeset
893 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
894 }
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
895 else
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
896 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
897 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
898 else if (nargin == 0)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
899 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
900 retval = symbol_table::varval (".nargin.");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
901
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
902 if (retval.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
903 retval = 0;
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
904 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
905 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
906 print_usage ();
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
907
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
908 return retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
909 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
910
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
911 DEFUN (nargout, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
912 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10832
diff changeset
913 @deftypefn {Built-in Function} {} nargout ()\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
914 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
915 Report the number of output arguments from a function.\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
916 \n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
917 Called from within a function, return the number of values the caller expects\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
918 to receive. At the top level, @code{nargout} with no argument is undefined\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
919 and will produce an error.\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
920 \n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
921 If called with the optional argument @var{fcn}---a function name or\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
922 handle---return the number of declared output values that the function can\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
923 produce.\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
924 \n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
925 If the final output argument is @var{varargout} the returned value is\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
926 negative.\n\
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
927 \n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
928 For example,\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
929 \n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
930 @example\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
931 f ()\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
932 @end example\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
933 \n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
934 @noindent\n\
4704
e1b71baef20c [project @ 2004-01-22 04:03:21 by jwe]
jwe
parents: 4700
diff changeset
935 will cause @code{nargout} to return 0 inside the function @code{f} and\n\
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
936 \n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
937 @example\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
938 [s, t] = f ()\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
939 @end example\n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
940 \n\
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
941 @noindent\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
942 will cause @code{nargout} to return 2 inside the function @code{f}.\n\
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
943 \n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
944 In the second usage,\n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
945 \n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
946 @example\n\
17757
dae2230227a7 doc: Use double-quote in preference to single quote in code examples.
Rik <rik@octave.org>
parents: 17744
diff changeset
947 nargout (@@histc) \% or nargout (\"histc\")\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
948 @end example\n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
949 \n\
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14328
diff changeset
950 @noindent\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
951 will return 2, because @code{histc} has two outputs, whereas\n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
952 \n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
953 @example\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
954 nargout (@@imread)\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
955 @end example\n\
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
956 \n\
14366
b76f0740940e doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14328
diff changeset
957 @noindent\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
958 will return -2, because @code{imread} has two outputs and the second is\n\
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
959 @var{varargout}.\n\
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
960 \n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
961 Programming Note. @code{nargout} does not work for built-in functions and\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
962 returns -1 for all anonymous functions.\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
963 @seealso{nargin, varargout, isargout, nthargout}\n\
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
964 @end deftypefn")
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
965 {
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
966 octave_value retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
967
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
968 int nargin = args.length ();
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
969
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
970 if (nargin == 1)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
971 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
972 octave_value func = args(0);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
973
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
974 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
975 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
976 std::string name = func.string_value ();
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
977 func = symbol_table::find_function (name);
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
978 if (func.is_undefined ())
20533
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
979 {
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
980 error ("nargout: invalid function name: %s", name.c_str ());
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
981 return retval;
19617a5b7202 Fix regression in displayed error message for nargin and nargout.
Rik <rik@octave.org>
parents: 20198
diff changeset
982 }
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
983 }
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 if (func.is_inline_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
986 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
987 retval = 1;
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
988 return retval;
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
989 }
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 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
992 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
993 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
994 std::string fh_nm = fh->fcn_name ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4929
diff changeset
995
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
996 if (fh_nm == octave_fcn_handle::anonymous)
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
997 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
998 retval = -1;
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
999 return retval;
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1000 }
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1001 }
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1002
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1003 octave_function *fcn_val = func.function_value ();
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1004 if (fcn_val)
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1005 {
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1006 octave_user_function *fcn = fcn_val->user_function_value (true);
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1007
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1008 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1009 {
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1010 tree_parameter_list *ret_list = fcn->return_list ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1011
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1012 retval = ret_list ? ret_list->length () : 0;
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1013
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1014 if (fcn->takes_var_return ())
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1015 retval = -1 - retval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1016 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1017 else
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1018 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1019 // JWE said this information is not available (2011-03-10)
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1020 // without making intrusive changes to Octave.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1021 // Matlab gives up for histc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1022 // so maybe it's ok that we give up somtimes too?
18915
4cdab2973171 maint: Fix some spellings in error messages.
Rik <rik@octave.org>
parents: 18795
diff changeset
1023 error ("nargout: nargout information not available for built-in functions.");
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1024 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1025 }
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1026 else
14136
20cb178716ee Make nargin and nargout behave more like Matlab's (Bug #32700)
Iain Murray <iain@iainmurray.net>
parents: 12483
diff changeset
1027 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
1028 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1029 else if (nargin == 0)
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1030 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
1031 if (! symbol_table::at_top_level ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1032 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1033 retval = symbol_table::varval (".nargout.");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1034
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1035 if (retval.is_undefined ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1036 retval = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1037 }
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1038 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1039 error ("nargout: invalid call at top level");
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1040 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1041 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5794
diff changeset
1042 print_usage ();
4700
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1043
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1044 return retval;
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1045 }
ca3a1d687bba [project @ 2004-01-21 03:28:31 by jwe]
jwe
parents: 4645
diff changeset
1046
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1047 DEFUN (optimize_subsasgn_calls, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1048 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10832
diff changeset
1049 @deftypefn {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10832
diff changeset
1050 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\
13951
79aa00a94e9e doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents: 13785
diff changeset
1051 @deftypefnx {Built-in Function} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1052 Query or set the internal flag for subsasgn method call optimizations.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
1053 \n\
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1054 If true, Octave will attempt to eliminate the redundant copying when calling\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 17787
diff changeset
1055 the subsasgn method of a user-defined class.\n\
13951
79aa00a94e9e doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents: 13785
diff changeset
1056 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16856
diff changeset
1057 When called from inside a function with the @qcode{\"local\"} option, the\n\
20198
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19731
diff changeset
1058 variable is changed locally for the function and any subroutines it calls.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16856
diff changeset
1059 The original variable value is restored when exiting the function.\n\
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1060 @end deftypefn")
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1061 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1062 return SET_INTERNAL_VARIABLE (optimize_subsasgn_calls);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
1063 }
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1064
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1065 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
1066 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1067 if (table.is_empty ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1068 return false;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1069
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1070 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
1071 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
1072 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1073
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1074 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
1075 {
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1076 if (k != xround (k) || k <= 0)
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1077 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1078 error ("isargout: K must be a positive integer");
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1079 return false;
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1080 }
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1081 else
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1082 return (k == 1 || k <= nargout) && ! val_in_table (ignored, k);
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1083 }
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1084
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1085 DEFUN (isargout, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1086 "-*- texinfo -*-\n\
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1087 @deftypefn {Built-in Function} {} isargout (@var{k})\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11304
diff changeset
1088 Within a function, return a logical value indicating whether the argument\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1089 @var{k} will be assigned to a variable on output.\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1090 \n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1091 If the result is false, the argument has been ignored during the function\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1092 call through the use of the tilde (~) special output argument. Functions\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1093 can use @code{isargout} to avoid performing unnecessary calculations for\n\
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1094 outputs which are unwanted.\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11304
diff changeset
1095 \n\
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14573
diff changeset
1096 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11304
diff changeset
1097 false. @var{k} can also be an array, in which case the function works\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11304
diff changeset
1098 element-by-element and a logical array is returned. At the top level,\n\
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 11304
diff changeset
1099 @code{isargout} returns an error.\n\
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18915
diff changeset
1100 @seealso{nargout, varargout, nthargout}\n\
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1101 @end deftypefn")
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1102 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1103 octave_value retval;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1104
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1105 int nargin = args.length ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1106
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1107 if (nargin == 1)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1108 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1109 if (! symbol_table::at_top_level ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1110 {
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1111 int nargout1 = symbol_table::varval (".nargout.").int_value ();
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1112 if (error_state)
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1113 {
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1114 error ("isargout: internal error");
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1115 return retval;
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1116 }
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1117
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1118 Matrix ignored;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1119 octave_value tmp = symbol_table::varval (".ignored.");
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1120 if (tmp.is_defined ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1121 ignored = tmp.matrix_value ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1122
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1123 if (args(0).is_scalar_type ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1124 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1125 double k = args(0).double_value ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1126 if (! error_state)
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1127 retval = isargout1 (nargout1, ignored, k);
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1128 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1129 else if (args(0).is_numeric_type ())
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1130 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1131 const NDArray ka = args(0).array_value ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1132 if (! error_state)
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1133 {
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1134 boolNDArray r (ka.dims ());
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1135 for (octave_idx_type i = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1136 i < ka.numel () && ! error_state;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17757
diff changeset
1137 i++)
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1138 r(i) = isargout1 (nargout1, ignored, ka(i));
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1139
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1140 retval = r;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1141 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1142 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1143 else
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1144 gripe_wrong_type_arg ("isargout", args(0));
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1145 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1146 else
10847
7fa3c8e43357 change is_ignored_output to isargout
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
1147 error ("isargout: invalid call at top level");
10832
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1148 }
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1149 else
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1150 print_usage ();
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1151
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1152 return retval;
1b2fcd122c6a allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents: 10637
diff changeset
1153 }
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1154
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 %!function [x, y] = try_isargout ()
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1157 %! if (isargout (1))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1158 %! if (isargout (2))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1159 %! x = 1; y = 2;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1160 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1161 %! x = -1;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1162 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1163 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1164 %! if (isargout (2))
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1165 %! y = -2;
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1166 %! else
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1167 %! error ("no outputs requested");
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1168 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1169 %! endif
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1170 %!endfunction
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1171 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1172 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1173 %! [x, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1174 %! assert ([x, y], [1, 2]);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1175 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1176 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1177 %! [x, ~] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1178 %! assert (x, -1);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1179 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1180 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1181 %! [~, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1182 %! assert (y, -2);
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1183 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1184 %!error [~, ~] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1185 %!
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1186 %% Check to see that isargout isn't sticky:
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1187 %!test
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1188 %! [x, y] = try_isargout ();
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1189 %! 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
1190 %!
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1191 %% It should work without ():
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1192 %!test
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1193 %! [~, y] = try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1194 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1195 %!
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1196 %% It should work in function handles, anonymous functions, and cell
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1197 %% arrays of handles or anonymous functions.
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1198 %!test
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1199 %! fh = @try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1200 %! af = @() try_isargout;
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1201 %! c = {fh, af};
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1202 %! [~, y] = fh ();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1203 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1204 %! [~, y] = af ();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1205 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1206 %! [~, y] = c{1}();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1207 %! assert (y, -2);
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1208 %! [~, y] = c{2}();
1785493171ac pass lvalue_list to more subsref calls (bug #38374)
John W. Eaton <jwe@octave.org>
parents: 15582
diff changeset
1209 %! assert (y, -2);
14571
6131fead3135 ensure isargout is not sticky
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
1210 */