annotate src/ov-usr-fcn.cc @ 10315:57a59eae83cc

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