annotate libinterp/parse-tree/pt-eval.cc @ 23729:06b3d1d54054

allow echo state to be modified from inside functions * ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::curr_unwind_protect_frame, octave_user_code::unwind_protect_frame): Move variable and accessor function here from octave_user_function. (octave_user_script::call): Also unwind-protect and set current unwind_protect frame variable here. * pt-eval.h, pt-eval.cc (tree_evaluator::set_echo_state, tree_evaluator::maybe_set_echo_state, tree_evaluator::push_echo_state_cleanup, maybe_push_echo_state_cleanup): New functions. (tree_evaluator::push_echo_state): Call push_ech_state_cleanup and set_echo_state. (tree_evaluator::echo): Call maybe_push_echo_state_cleanup and set_echo_state.
author John W. Eaton <jwe@octave.org>
date Wed, 05 Jul 2017 08:37:45 -0400
parents b40b7243a782
children c3828bd031cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2009-2017 John W. Eaton
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
10 (at your option) any later version.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22703
diff changeset
15 GNU General Public License for more details.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21542
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
24 # include "config.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <cctype>
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <iostream>
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <fstream>
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <typeinfo>
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
34 #include "cmd-edit.h"
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
35 #include "oct-env.h"
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
36
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
37 #include "bp-table.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
38 #include "call-stack.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "defun.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20962
diff changeset
41 #include "errwarn.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "input.h"
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
43 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
44 #include "interpreter.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "ov-fcn-handle.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "ov-usr-fcn.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
47 #include "ov-re-sparse.h"
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
48 #include "ov-cx-sparse.h"
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
49 #include "profiler.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "pt-all.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "pt-eval.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
52 #include "pt-tm-const.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 #include "symtab.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 #include "unwind-prot.h"
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
55 #include "utils.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
56 #include "variables.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents: 14429
diff changeset
58 //FIXME: This should be part of tree_evaluator
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents: 14429
diff changeset
59 #include "pt-jit.h"
15310
b055fc077224 allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents: 15244
diff changeset
60
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
61 namespace octave
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
63 int tree_evaluator::dbstep_flag = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
64
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
65 size_t tree_evaluator::current_frame = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
66
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
67 bool tree_evaluator::debug_mode = false;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
69 bool tree_evaluator::quiet_breakpoint_flag = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
70
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
71 tree_evaluator::stmt_list_type tree_evaluator::statement_context
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
72 = tree_evaluator::other;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
73
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
74 bool tree_evaluator::in_loop_command = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
75
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
76 // Normal evaluator.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
78 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
79 tree_evaluator::reset (void)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
80 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
81 m_value_stack.clear ();
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
82 m_lvalue_list_stack.clear ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
83 m_nargout_stack.clear ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
84 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
85
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
86 void
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
87 tree_evaluator::visit_anon_fcn_handle (tree_anon_fcn_handle& anon_fh)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
88 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
89 // FIXME: should CMD_LIST be limited to a single expression?
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
90 // I think that is what Matlab does.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
91
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
92 tree_parameter_list *param_list = anon_fh.parameter_list ();
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
93 tree_expression *expr = anon_fh.expression ();
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
94
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
95 symbol_table::scope *af_scope = anon_fh.scope ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
96
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
97 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
98
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
99 symbol_table::scope *af_parent_scope
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
100 = anon_fh.has_parent_scope () ? symtab.current_scope () : 0;
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
101
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
102 symbol_table::scope *new_scope = af_scope ? af_scope->dup () : 0;
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
103
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
104 if (new_scope && af_parent_scope)
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
105 new_scope->inherit (af_parent_scope);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
106
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
107 tree_parameter_list *param_list_dup
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
108 = param_list ? param_list->dup (*new_scope) : 0;
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
109
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
110 tree_parameter_list *ret_list = 0;
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
111
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
112 tree_statement_list *stmt_list = 0;
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
113
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
114 if (expr)
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
115 {
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
116 tree_expression *expr_dup = expr->dup (*new_scope);
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
117 tree_statement *stmt = new tree_statement (expr_dup, 0);
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
118 stmt_list = new tree_statement_list (stmt);
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
119 }
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
120
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
121 octave_user_function *af
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
122 = new octave_user_function (new_scope, param_list_dup, ret_list,
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
123 stmt_list);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
124
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
125 new_scope->set_parent (af_parent_scope);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
126
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
127 octave_function *curr_fcn = m_call_stack.current ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
128
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
129 if (curr_fcn)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
130 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
131 // FIXME: maybe it would be better to just stash curr_fcn
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
132 // instead of individual bits of info about it?
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
133
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
134 af->stash_parent_fcn_name (curr_fcn->name ());
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
135 af->stash_dir_name (curr_fcn->dir_name ());
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
136
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
137 if (curr_fcn->is_class_method () || curr_fcn->is_class_constructor ())
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
138 af->stash_dispatch_class (curr_fcn->dispatch_class ());
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
139 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
140
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
141 af->mark_as_anonymous_function ();
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
142
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
143 // FIXME: these should probably come from ANON_FH.
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
144 // af->stash_fcn_file_name (expr.file_name ());
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
145 // af->stash_fcn_location (expr.line (), expr.column ());
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
146
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
147 octave_value ov_fcn (af);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
148
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
149 octave_value fh (octave_fcn_binder::maybe_binder (ov_fcn, this));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
150
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
151 m_value_stack.push (ovl (fh));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
152 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
154 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
155 tree_evaluator::visit_argument_list (tree_argument_list&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
156 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
157 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
158 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
159
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
160 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
161 tree_evaluator::visit_binary_expression (tree_binary_expression& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
162 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
163 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
164
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
165 tree_expression *op_lhs = expr.lhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
166 tree_expression *op_rhs = expr.rhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
167 octave_value::binary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
168
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
169 if (expr.is_eligible_for_braindead_shortcircuit ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
170 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
171 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
172 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
173 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
174
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
175 if (a.ndims () == 2 && a.rows () == 1 && a.columns () == 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
176 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
177 bool result = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
178
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
179 bool a_true = a.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
180
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
181 if (a_true)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
182 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
183 if (etype == octave_value::op_el_or)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
184 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
185 expr.matlab_style_short_circuit_warning ("|");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
186 m_value_stack.push (ovl (octave_value (true)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
187 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
188 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
189 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
190 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
191 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
192 if (etype == octave_value::op_el_and)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
193 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
194 expr.matlab_style_short_circuit_warning ("&");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
195 m_value_stack.push (ovl (octave_value (false)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
196 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
197 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
198 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
199
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
200 if (op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
201 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
202 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
203
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
204 result = b.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
205 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
206
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
207 m_value_stack.push (ovl (octave_value (result)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
208 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
209 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
210 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
211 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
212
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
213 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
214 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
215 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
216
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
217 if (a.is_defined () && op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
218 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
219 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
220
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
221 if (b.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
222 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
223 profile_data_accumulator::enter<tree_binary_expression>
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
224 block (profiler, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
225
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
226 // Note: The profiler does not catch the braindead
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
227 // short-circuit evaluation code above, but that should be
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
228 // ok. The evaluation of operands and the operator itself
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
229 // is entangled and it's not clear where to start/stop
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
230 // timing the operator to make it reasonable.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
231
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
232 val = ::do_binary_op (etype, a, b);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
233 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
234 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
235 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
236
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
237 m_value_stack.push (ovl (val));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
238 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
239
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
240 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
241 tree_evaluator::visit_boolean_expression (tree_boolean_expression& expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
242 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
243 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
244
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
245 bool result = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
246
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
247 // This evaluation is not caught by the profiler, since we can't find
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
248 // a reasonable place where to time. Note that we don't want to
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
249 // include evaluation of LHS or RHS into the timing, but this is
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
250 // entangled together with short-circuit evaluation here.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
251
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
252 tree_expression *op_lhs = expr.lhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
253
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
254 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
255 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
256 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
257
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
258 bool a_true = a.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
259
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
260 tree_boolean_expression::type etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
261
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
262 if (a_true)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
263 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
264 if (etype == tree_boolean_expression::bool_or)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
265 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
266 m_value_stack.push (ovl (octave_value (true)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
267 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
268 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
269 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
270 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
271 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
272 if (etype == tree_boolean_expression::bool_and)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
273 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
274 m_value_stack.push (ovl (octave_value (false)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
275 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
276 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
277 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
278
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
279 tree_expression *op_rhs = expr.rhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
280
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
281 if (op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
282 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
283 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
284
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
285 result = b.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
286 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
287
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
288 val = octave_value (result);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
289 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
290
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
291 m_value_stack.push (ovl (val));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
292 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
293
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
294 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
295 tree_evaluator::visit_compound_binary_expression (tree_compound_binary_expression& expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
296 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
297 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
298
23523
d2748870db4e undo part of previous change
John W. Eaton <jwe@octave.org>
parents: 23522
diff changeset
299 tree_expression *op_lhs = expr.clhs ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
300
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
301 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
302 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
303 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
304
23523
d2748870db4e undo part of previous change
John W. Eaton <jwe@octave.org>
parents: 23522
diff changeset
305 tree_expression *op_rhs = expr.crhs ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
306
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
307 if (a.is_defined () && op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
308 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
309 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
310
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
311 if (b.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
312 {
23522
d2e300f7700c fix compound binary op error introduced in c452180ab672
John W. Eaton <jwe@octave.org>
parents: 23521
diff changeset
313 octave_value::compound_binary_op etype = expr.cop_type ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
314
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
315 val = ::do_binary_op (etype, a, b);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
316 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
317 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
318 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
319
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
320 m_value_stack.push (ovl (val));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
321 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
323 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
324 tree_evaluator::visit_break_command (tree_break_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
325 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
326 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
327 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
328 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
329 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
330 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
331 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
332
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
333 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
334 do_breakpoint (cmd.is_breakpoint (true));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335
22785
9c6661004167 error if break statement is in script file separate from loop (bug #39168)
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
336 if (in_loop_command)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
337 tree_break_command::breaking = 1;
22785
9c6661004167 error if break statement is in script file separate from loop (bug #39168)
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
338 else
9c6661004167 error if break statement is in script file separate from loop (bug #39168)
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
339 error ("break must appear in a loop in the same file as loop command");
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
340 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
341
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
342 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
343 tree_evaluator::visit_colon_expression (tree_colon_expression& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
344 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
345 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
346
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
347 tree_expression *op_base = expr.base ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
348 tree_expression *op_limit = expr.limit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
349
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
350 if (! op_base || ! op_limit)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
351 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
352 m_value_stack.push (ovl (octave_value (val)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
353 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
354 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
355
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
356 octave_value ov_base = evaluate (op_base);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
357
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
358 octave_value ov_limit = evaluate (op_limit);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
359
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
360 tree_expression *op_increment = expr.increment ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
361
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23584
diff changeset
362 if (ov_base.isobject () || ov_limit.isobject ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
363 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
364 octave_value_list tmp1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
365
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
366 if (op_increment)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
367 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
368 octave_value ov_increment = evaluate (op_increment);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
369
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
370 tmp1(2) = ov_limit;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
371 tmp1(1) = ov_increment;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
372 tmp1(0) = ov_base;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
373 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
374 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
375 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
376 tmp1(1) = ov_limit;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
377 tmp1(0) = ov_base;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
378 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
379
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
380 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
381
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
382 octave_value fcn = symtab.find_function ("colon", tmp1);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
383
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
384 if (! fcn.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
385 error ("can not find overloaded colon function");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
386
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
387 octave_value_list tmp2 = feval (fcn, tmp1, 1);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
388
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
389 val = tmp2 (0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
390 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
391 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
392 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
393 octave_value ov_increment = 1.0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
394
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
395 if (op_increment)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
396 ov_increment = evaluate (op_increment);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
397
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
398 val = do_colon_op (ov_base, ov_increment, ov_limit,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
399 expr.is_for_cmd_expr ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
400 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
401
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
402 m_value_stack.push (ovl (val));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
403 }
10188
97ae300aa73a improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents: 10186
diff changeset
404
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
405 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
406 tree_evaluator::visit_continue_command (tree_continue_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
407 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
408 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
409 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
410 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
411 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
412 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
413 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
414
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
415 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
416 do_breakpoint (cmd.is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
417
22703
d43094e91ba7 Ignore continue statement when used outside of a loop (bug #48665)
Mike Miller <mtmiller@octave.org>
parents: 22407
diff changeset
418 if (in_loop_command)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
419 tree_continue_command::continuing = 1;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
420 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
422 bool
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
423 tree_evaluator::statement_printing_enabled (void)
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
424 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
425 return ! (m_silent_functions && (statement_context == function
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
426 || statement_context == script));
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
427 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
428
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
429 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
430 tree_evaluator::reset_debug_state (void)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
431 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
432 debug_mode = bp_table::have_breakpoints () || Vdebugging;
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
433
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
434 dbstep_flag = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
435 }
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
437 Matrix
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
438 tree_evaluator::ignored_fcn_outputs (void) const
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
439 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
440 Matrix retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
441
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
442 if (m_lvalue_list_stack.empty ())
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
443 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
444
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
445 const std::list<octave_lvalue> *lvalue_list = m_lvalue_list_stack.top ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
446
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
447 if (! lvalue_list)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
448 return retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
449
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
450 octave_idx_type nbh = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
451
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
452 for (const auto& lval : *lvalue_list)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
453 nbh += lval.is_black_hole ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
454
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
455 if (nbh > 0)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
456 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
457 retval.resize (1, nbh);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
458
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
459 octave_idx_type k = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
460 octave_idx_type l = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
461
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
462 for (const auto& lval : *lvalue_list)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
463 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
464 if (lval.is_black_hole ())
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
465 retval(l++) = k+1;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
466
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
467 k += lval.numel ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
468 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
469 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
470
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
471 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
472 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
473
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
474 octave_value
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
475 tree_evaluator::evaluate (tree_decl_elt *elt)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
476 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
477 // Do not allow functions to return null values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
478
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
479 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
480
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
481 return id ? evaluate (id).storable_value () : octave_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
482 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
483
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
484 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
485 tree_evaluator::initialize_undefined_parameter_list_elements
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
486 (tree_parameter_list *param_list, const std::string& warnfor,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
487 int nargout, const octave_value& val)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
488 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
489 bool warned = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
490
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
491 int count = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
492
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
493 symbol_table::scope *scope
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
494 = m_interpreter.require_current_scope ("tree_evaluator::initialize_undefined_parameter_list_elements");
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
495
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
496 octave_value tmp = scope->varval (".ignored.");
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
497 const Matrix ignored = (tmp.is_defined () ? tmp.matrix_value () : Matrix ());
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
498
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
499 octave_idx_type k = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
500
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
501 for (tree_decl_elt *elt : *param_list)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
502 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
503 if (++count > nargout)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
504 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
505
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
506 if (! elt->is_variable ())
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
507 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
508 if (! warned)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
509 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
510 warned = true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
511
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
512 while (k < ignored.numel ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
513 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
514 octave_idx_type l = ignored (k);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
515 if (l == count)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
516 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
517 warned = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
518 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
519 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
520 else if (l > count)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
521 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
522 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
523 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
524 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
525
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
526 if (warned)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
527 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
528 warning_with_id
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
529 ("Octave:undefined-return-values",
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
530 "%s: some elements in list of return values are undefined",
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
531 warnfor.c_str ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
532 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
533 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
534
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
535 octave_lvalue lval = elt->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
536
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
537 lval.assign (octave_value::op_asn_eq, val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
538 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
539 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
540 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
542 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
543 tree_evaluator::define_parameter_list_from_arg_vector
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
544 (tree_parameter_list *param_list, const octave_value_list& args)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
545 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
546 int i = -1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
547
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
548 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
549 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
550 i++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
551
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
552 octave_lvalue ref = elt->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
553
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
554 if (i < args.length ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
555 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
556 if (args(i).is_defined () && args(i).is_magic_colon ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
557 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
558 if (! eval_decl_elt (elt))
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
559 error ("no default value for argument %d", i+1);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
560 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
561 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
562 ref.define (args(i));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
563 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
564 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
565 eval_decl_elt (elt);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
566 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
567 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
569 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
570 tree_evaluator::undefine_parameter_list (tree_parameter_list *param_list)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
571 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
572 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
573 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
574 octave_lvalue ref = elt->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
575
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
576 ref.assign (octave_value::op_asn_eq, octave_value ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
577 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
578 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
579
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
580 octave_value_list
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
581 tree_evaluator::convert_parameter_list_to_const_vector
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
582 (tree_parameter_list *param_list, int nargout, const Cell& varargout)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
583 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
584 octave_idx_type vlen = varargout.numel ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
585 int len = param_list->length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
586
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
587 // Special case. Will do a shallow copy.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
588 if (len == 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
589 return varargout;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
590 else if (nargout <= len)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
591 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
592 octave_value_list retval (nargout);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
593
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
594 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
595
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
596 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
597 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
598 if (elt->is_defined ())
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
599 {
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
600 octave_value tmp = evaluate (elt);
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
601 retval(i++) = tmp;
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
602 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
603 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
604 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
605 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
606
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
607 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
608 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
609 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
610 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
611 octave_value_list retval (len + vlen);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
612
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
613 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
614
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
615 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
616 retval(i++) = evaluate (elt);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
617
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
618 for (octave_idx_type j = 0; j < vlen; j++)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
619 retval(i++) = varargout(j);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
620
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
621 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
622 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
623 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
624
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
625 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
626 tree_evaluator::eval_decl_elt (tree_decl_elt *elt)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
627 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
628 bool retval = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
629
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
630 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
631 tree_expression *expr = elt->expression ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
632
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
633 if (id && expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
634 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
635 octave_lvalue ult = id->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
636
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
637 octave_value init_val = evaluate (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
638
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
639 ult.assign (octave_value::op_asn_eq, init_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
640
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
641 retval = true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
642 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
643
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
644 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
645 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
646
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
647 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
648 tree_evaluator::switch_case_label_matches (tree_switch_case *expr,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
649 const octave_value& val)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
650 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
651 tree_expression *label = expr->case_label ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
652
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
653 octave_value label_value = evaluate (label);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
654
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
655 if (label_value.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
656 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
657 if (label_value.iscell ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
658 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
659 Cell cell (label_value.cell_value ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
660
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
661 for (octave_idx_type i = 0; i < cell.rows (); i++)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
662 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
663 for (octave_idx_type j = 0; j < cell.columns (); j++)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
664 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
665 bool match = val.is_equal (cell(i,j));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
666
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
667 if (match)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
668 return true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
669 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
670 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
671 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
672 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
673 return val.is_equal (label_value);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
674 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
675
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
676 return false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
677 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
678
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
679 void
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
680 tree_evaluator::visit_decl_command (tree_decl_command& cmd)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
681 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
682 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
683 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
684 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
685 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
686 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
687 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
688
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
689 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
690 do_breakpoint (cmd.is_breakpoint (true));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
691
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
692 tree_decl_init_list *init_list = cmd.initializer_list ();
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
693
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
694 if (init_list)
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
695 init_list->accept (*this);
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
696 }
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
697
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
698 void
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
699 tree_evaluator::visit_decl_init_list (tree_decl_init_list& lst)
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
700 {
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
701 for (tree_decl_elt *elt : lst)
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
702 elt->accept (*this);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
703 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
704
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
705 void
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
706 tree_evaluator::visit_decl_elt (tree_decl_elt& elt)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
707 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
708 tree_identifier *id = elt.ident ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
709
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
710 if (id)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
711 {
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
712 if (elt.is_global ())
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
713 id->mark_global ();
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
714 else if (elt.is_persistent ())
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23469
diff changeset
715 id->mark_persistent ();
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
716 else
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
717 error ("declaration list element not global or persistent");
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
718
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
719 octave_lvalue ult = id->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
720
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
721 if (ult.is_undefined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
722 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
723 tree_expression *expr = elt.expression ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
724
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
725 octave_value init_val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
726
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
727 if (expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
728 init_val = evaluate (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
729 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
730 init_val = Matrix ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
731
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
732 ult.assign (octave_value::op_asn_eq, init_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
733 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
734 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
735 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
736 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
737
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
738 // Decide if it's time to quit a for or while loop.
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
739 static inline bool
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
740 quit_loop_now (void)
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
741 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
742 octave_quit ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
743
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
744 // Maybe handle 'continue N' someday...
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745
23369
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
746 if (octave::tree_continue_command::continuing)
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
747 octave::tree_continue_command::continuing--;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
748
23369
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
749 bool quit = (octave::tree_return_command::returning
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
750 || octave::tree_break_command::breaking
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
751 || octave::tree_continue_command::continuing);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
752
23398
d4ef04757ead eliminate some compiler warnings
John W. Eaton <jwe@octave.org>
parents: 23369
diff changeset
753 if (octave::tree_break_command::breaking)
23369
2a6246cc4a68 * pt-eval.cc (quit_loop_now): Avoid deprecated variable warnings.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
754 octave::tree_break_command::breaking--;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
755
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
756 return quit;
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
757 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
758
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
759 namespace octave
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
760 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
761 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
762 tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
763 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
764 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
765
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
766 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
767 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
768 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
769 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
770 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
771
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
772 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
773 do_breakpoint (cmd.is_breakpoint (true));
13245
027a2186cd90 parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents: 13226
diff changeset
774
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
775 // FIXME: need to handle PARFOR loops here using cmd.in_parallel ()
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
776 // and cmd.maxproc_expr ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
777
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
778 unwind_protect frame;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
779
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
780 frame.protect_var (in_loop_command);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
781
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
782 in_loop_command = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
783
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
784 tree_expression *expr = cmd.control_expr ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
785
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
786 octave_value rhs = evaluate (expr);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
787
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
788 #if defined (HAVE_LLVM)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
789 if (tree_jit::execute (cmd, rhs))
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
790 return;
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
791 #endif
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
792
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
793 if (rhs.is_undefined ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
794 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
795
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
796 tree_expression *lhs = cmd.left_hand_side ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
797
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
798 octave_lvalue ult = lhs->lvalue (this);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
799
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
800 tree_statement_list *loop_body = cmd.body ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
801
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
802 if (rhs.is_range ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
803 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
804 Range rng = rhs.range_value ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
805
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
806 octave_idx_type steps = rng.numel ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
807
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
808 for (octave_idx_type i = 0; i < steps; i++)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
809 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
810 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
811 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
812
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
813 octave_value val (rng.elem (i));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
814
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
815 ult.assign (octave_value::op_asn_eq, val);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
816
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
817 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
818 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
819
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
820 if (quit_loop_now ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
821 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
822 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
823 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
824 else if (rhs.is_scalar_type ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
825 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
826 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
827 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
828
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
829 ult.assign (octave_value::op_asn_eq, rhs);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
830
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
831 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
832 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
833
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
834 // Maybe decrement break and continue states.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
835 quit_loop_now ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
836 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
837 else if (rhs.is_matrix_type () || rhs.iscell () || rhs.is_string ()
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
838 || rhs.isstruct ())
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
839 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
840 // A matrix or cell is reshaped to 2 dimensions and iterated by
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
841 // columns.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
842
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
843 dim_vector dv = rhs.dims ().redim (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
844
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
845 octave_idx_type nrows = dv(0);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
846 octave_idx_type steps = dv(1);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
847
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
848 octave_value arg = rhs;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
849 if (rhs.ndims () > 2)
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
850 arg = arg.reshape (dv);
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
851
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
852 if (nrows > 0 && steps > 0)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
853 {
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
854 octave_value_list idx;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
855 octave_idx_type iidx;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
856
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
857 // for row vectors, use single index to speed things up.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
858 if (nrows == 1)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
859 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
860 idx.resize (1);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
861 iidx = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
862 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
863 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
864 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
865 idx.resize (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
866 idx(0) = octave_value::magic_colon_t;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
867 iidx = 1;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
868 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
869
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
870 for (octave_idx_type i = 1; i <= steps; i++)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
871 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
872 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
873 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
874
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
875 // do_index_op expects one-based indices.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
876 idx(iidx) = i;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
877 octave_value val = arg.do_index_op (idx);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
878
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
879 ult.assign (octave_value::op_asn_eq, val);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
880
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
881 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
882 loop_body->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
883
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
884 if (quit_loop_now ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
885 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
886 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
887 }
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
888 else
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
889 {
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
890 // Handle empty cases, while still assigning to loop var.
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
891 ult.assign (octave_value::op_asn_eq, arg);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
892 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
893 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
894 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
895 error ("invalid type in for loop expression near line %d, column %d",
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
896 cmd.line (), cmd.column ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
897 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
899 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
900 tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
901 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
902 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
903
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
904 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
905 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
906 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
907 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
908 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
909
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
910 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
911 do_breakpoint (cmd.is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
912
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
913 unwind_protect frame;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
914
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
915 frame.protect_var (in_loop_command);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
916
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
917 in_loop_command = true;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
918
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
919 tree_expression *expr = cmd.control_expr ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
920
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
921 octave_value rhs = evaluate (expr);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
922
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
923 if (rhs.is_undefined ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
924 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
925
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
926 if (! rhs.isstruct ())
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
927 error ("in statement 'for [X, Y] = VAL', VAL must be a structure");
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
928
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
929 // Cycle through structure elements. First element of id_list
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
930 // is set to value and the second is set to the name of the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
931 // structure element.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
932
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
933 tree_argument_list *lhs = cmd.left_hand_side ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
934
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
935 tree_argument_list::iterator p = lhs->begin ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
936
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
937 tree_expression *elt = *p++;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
938
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
939 octave_lvalue val_ref = elt->lvalue (this);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
940
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
941 elt = *p;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
942
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
943 octave_lvalue key_ref = elt->lvalue (this);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
944
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
945 const octave_map tmp_val = rhs.map_value ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
946
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
947 tree_statement_list *loop_body = cmd.body ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
948
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
949 string_vector keys = tmp_val.keys ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
950
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
951 octave_idx_type nel = keys.numel ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
952
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
953 for (octave_idx_type i = 0; i < nel; i++)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
954 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
955 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
956 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
957
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
958 std::string key = keys[i];
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
959
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
960 const Cell val_lst = tmp_val.contents (key);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
961
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
962 octave_idx_type n = val_lst.numel ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
963
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
964 octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
965
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
966 val_ref.assign (octave_value::op_asn_eq, val);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
967 key_ref.assign (octave_value::op_asn_eq, key);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
968
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
969 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
970 loop_body->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
971
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
972 if (quit_loop_now ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
973 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
974 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
975 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
976
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
977 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
978 tree_evaluator::visit_octave_user_script (octave_user_script&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
979 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
980 // ??
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
981 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
982 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
983
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
984 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
985 tree_evaluator::visit_octave_user_function (octave_user_function&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
986 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
987 // ??
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
988 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
989 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
990
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
991 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
992 tree_evaluator::visit_octave_user_function_header (octave_user_function&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
993 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
994 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
995 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
996
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
997 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
998 tree_evaluator::visit_octave_user_function_trailer (octave_user_function&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
999 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1000 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1001 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1002
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1003 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1004 tree_evaluator::visit_function_def (tree_function_def& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1005 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1006 octave_value fcn = cmd.function ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1007
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1008 octave_function *f = fcn.function_value ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1009
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1010 if (f)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1011 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1012 std::string nm = f->name ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1013
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1014 symbol_table& symtab = m_interpreter.get_symbol_table ();
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1015
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1016 symtab.install_cmdline_function (nm, fcn);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1017
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1018 // Make sure that any variable with the same name as the new
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1019 // function is cleared.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1020
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1021 symbol_table::scope *scope = symtab.current_scope ();
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1022
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1023 if (scope)
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1024 scope->assign (nm);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1025 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1026 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
1027
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1028 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1029 tree_evaluator::visit_identifier (tree_identifier& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1030 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1031 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1032
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1033 symbol_table::symbol_reference sym = expr.symbol ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1034
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1035 octave_value val = sym->find ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1036
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1037 if (val.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1038 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1039 // GAGME -- this would be cleaner if we required
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1040 // parens to indicate function calls.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1041 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1042 // If this identifier refers to a function, we need to know
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1043 // whether it is indexed so that we can do the same thing
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1044 // for 'f' and 'f()'. If the index is present and the function
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1045 // object declares it can handle it, return the function object
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1046 // and let tree_index_expression::rvalue handle indexing.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1047 // Otherwise, arrange to call the function here, so that we don't
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1048 // return the function definition as a value.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1049
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
1050 octave_function *fcn = nullptr;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1051
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1052 if (val.is_function ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1053 fcn = val.function_value (true);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1054
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1055 int nargout = m_nargout_stack.top ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1056
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1057 if (fcn && ! (expr.is_postfix_indexed ()
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
1058 && fcn->accepts_postfix_index (expr.postfix_index ())))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1059 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
1060 retval = fcn->call (*this, nargout);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1061 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1062 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1063 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1064 if (expr.print_result () && nargout == 0
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
1065 && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1066 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1067 octave_value_list args = ovl (val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1068 args.stash_name_tags (string_vector (expr.name ()));
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1069 feval ("display", args);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1070 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1071
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1072 retval = val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1073 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1074 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1075 else if (sym->is_added_static ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1076 expr.static_workspace_error ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1077 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1078 expr.eval_undefined_error ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1079
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1080 m_value_stack.push (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1081 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1082
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1083 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1084 tree_evaluator::visit_if_clause (tree_if_clause&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1085 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1086 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1087 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1088
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1089 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1090 tree_evaluator::visit_if_command (tree_if_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1091 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1092 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1093 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1094 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1095 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1096 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1097 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1098
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1099 tree_if_command_list *lst = cmd.cmd_list ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1100
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1101 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1102 lst->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1103 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1104
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1105 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1106 tree_evaluator::visit_if_command_list (tree_if_command_list& lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1107 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1108 for (tree_if_clause *tic : lst)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1109 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1110 tree_expression *expr = tic->condition ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1111
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1112 if (statement_context == function || statement_context == script)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
1113 m_call_stack.set_location (tic->line (), tic->column ());
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1114
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1115 if (debug_mode && ! tic->is_else_clause ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1116 do_breakpoint (tic->is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1117
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1118 if (tic->is_else_clause () || is_logically_true (expr, "if"))
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1119 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1120 tree_statement_list *stmt_lst = tic->commands ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1121
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1122 if (stmt_lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1123 stmt_lst->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1124
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
1125 break;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1126 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1127 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1128 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1129 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1130
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1131 // Final step of processing an indexing error. Add the name of the
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1132 // variable being indexed, if any, then issue an error. (Will this also
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1133 // be needed by pt-lvalue, which calls subsref?)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1134
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1135 static void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1136 final_index_error (octave::index_exception& e,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1137 const octave::tree_expression *expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1138 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1139 std::string extra_message;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1140
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1141 if (expr->is_identifier ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1142 && dynamic_cast<const octave::tree_identifier *> (expr)->is_variable ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1143 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1144 std::string var = expr->name ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1145
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1146 e.set_var (var);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1147
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23684
diff changeset
1148 octave::symbol_table& symtab = octave::__get_symbol_table__ ("final_index_error");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1149
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1150 octave_value fcn = symtab.find_function (var);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1151
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1152 if (fcn.is_function ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1153 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1154 octave_function *fp = fcn.function_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1155
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1156 if (fp && fp->name () == var)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1157 extra_message = " (note: variable '" + var + "' shadows function)";
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1158 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1159 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1160
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1161 std::string msg = e.message () + extra_message;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1162
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1163 error_with_id (e.err_id (), msg.c_str ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1164 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1165
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1166 namespace octave
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1167 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1168 // Unlike Matlab, which does not allow the result of a function call
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1169 // or array indexing expression to be further indexed, Octave attempts
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1170 // to handle arbitrary index expressions. For example, Octave allows
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1171 // expressions like
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1172 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1173 // svd (rand (10))(1:5)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1174 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1175 // Although octave_value objects may contain function objects, no
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1176 // indexing operation or function call is supposed to return them
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1177 // directly. Instead, the language is supposed to only allow function
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1178 // objects to be stored as function handles (named or anonymous) or as
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1179 // inline functions. The only place a function object should appear
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1180 // directly is if the symbol stored in a tree_identifier object
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1181 // resolves to a function. This means that the only place we need to
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1182 // look for functions is in the first element of the index
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1183 // expression.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1184 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1185 // Steps:
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1186 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1187 // * Obtain the initial value from the expression component of the
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1188 // tree_index_expression object. If it is a tree_identifier object
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1189 // indexed by '(args)' and the identifier is not a variable, then
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1190 // peform a function call. Use the (optional) arguments to perform
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1191 // the function lookup so we choose the correct function or class
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1192 // method to call. Otherwise, evaluate the first expression
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1193 // without any additional arguments.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1194 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1195 // * Iterate over the remaining elements of the index expression and
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1196 // call the octave_value::subsref method. If indexing a class or
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1197 // classdef object, build up a list of indices for a call to the
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1198 // subsref method for the object. Otherwise, use the result of
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1199 // each temporary evaluation for the next index element.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1200 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1201 // * If not indexing a class or classdef object and any partial
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1202 // expression evaluation produces a class or classdef object, then
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1203 // build up a complete argument list from that point on for a final
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1204 // subsref call for that object.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1205 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1206 // Multiple partial evaluations may be required. For example,
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1207 // given a class or classdef object X, then for the expression
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1208 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1209 // x.a{end}(2:end).b
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1210 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1211 // we must evaluate x.a to obtain the size for the first {end}
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1212 // expression, then we must evaluate x.a{end} to obtain the size
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1213 // for the second (2:end) expression. Finally, the complete
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1214 // expression may be evaluated.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1215 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1216 // If X is a cell array in the above expression, and none of the
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1217 // intermediate evaluations produces a class or classdef object,
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1218 // then the evaluation is performed as the following series of
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1219 // steps
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1220 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1221 // tmp = x.a
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1222 // tmp = tmp{end}
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1223 // tmp = tmp(2:end)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1224 // result = tmp.b
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1225 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1226 // If any of the partial evaluations produces a class or classdef
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1227 // object, then the subsref method for that object is called as
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1228 // described above. For example, suppose x.a produces a classdef
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1229 // object. Then the evaluation is performed as the following
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1230 // series of steps
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1231 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1232 // base_expr = tmp = x.a
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1233 // tmp = base_expr{end}
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1234 // base_expr{end}(2:end).b
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1235 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1236 // In the last two steps, the partial value computed in the
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1237 // previous step is used to determine the value of END.
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1238
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1239 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1240 tree_evaluator::visit_index_expression (tree_index_expression& idx_expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1241 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1242 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1243
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1244 int nargout = m_nargout_stack.top ();
23458
0f4ed33886de maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1245
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1246 std::string type = idx_expr.type_tags ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1247 std::list<tree_argument_list *> args = idx_expr.arg_lists ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1248 std::list<string_vector> arg_nm = idx_expr.arg_names ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1249 std::list<tree_expression *> dyn_field = idx_expr.dyn_fields ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1250
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1251 assert (! args.empty ());
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1252
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1253 std::list<tree_argument_list *>::iterator p_args = args.begin ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1254 std::list<string_vector>::iterator p_arg_nm = arg_nm.begin ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1255 std::list<tree_expression *>::iterator p_dyn_field = dyn_field.begin ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1256
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1257 int n = args.size ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1258 int beg = 0;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1259
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1260 octave_value base_expr_val;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1261
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1262 tree_expression *expr = idx_expr.expression ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1263
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1264 if (expr->is_identifier () && type[beg] == '(')
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1265 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1266 tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1267
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1268 if (! id->is_variable ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1269 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1270 octave_value_list first_args;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1271
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1272 tree_argument_list *al = *p_args;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1273
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1274 if (al && al->length () > 0)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1275 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1276 // Function calls inside an argument list can't have
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1277 // ignored output arguments.
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1278
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1279 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1280
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1281 m_lvalue_list_stack.push (0);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1282
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1283 frame.add_method (m_lvalue_list_stack,
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1284 &value_stack<const std::list<octave_lvalue>*>::pop);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1285
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1286 string_vector anm = *p_arg_nm;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1287 first_args = al->convert_to_const_vector (this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1288 first_args.stash_name_tags (anm);
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1289 }
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1290
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1291 octave_function *fcn = nullptr;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1292
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1293 octave_value val = id->do_lookup (first_args);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1294
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1295 if (val.is_function ())
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1296 fcn = val.function_value (true);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1297
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1298 if (fcn)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1299 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1300 try
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1301 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
1302 retval = fcn->call (*this, nargout, first_args);
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1303 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1304 catch (index_exception& e)
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1305 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1306 final_index_error (e, expr);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1307 }
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1308
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1309 beg++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1310 p_args++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1311 p_arg_nm++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1312 p_dyn_field++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1313
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1314 if (n > beg)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1315 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1316 // More indices to follow. Silently ignore
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1317 // extra output values.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1318
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1319 if (retval.length () == 0)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1320 error ("indexing undefined value");
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1321 else
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1322 base_expr_val = retval(0);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1323 }
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1324 else
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1325 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1326 // No more indices, so we are done.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1327
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1328 m_value_stack.push (retval);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1329 return;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1330 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1331 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1332 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1333 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1334
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1335 if (base_expr_val.is_undefined ())
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1336 base_expr_val = evaluate (expr);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1337
23671
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23616
diff changeset
1338 bool indexing_object = base_expr_val.isobject () || base_expr_val.isjava ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1339
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1340 std::list<octave_value_list> idx;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1341
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1342 octave_value partial_expr_val = base_expr_val;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1343
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1344 for (int i = beg; i < n; i++)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1345 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1346 if (i > beg)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1347 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1348 tree_argument_list *al = *p_args;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1349
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1350 if (! indexing_object || (al && al->has_magic_end ()))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1351 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1352 // Evaluate what we have so far to find the value to
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1353 // pass to the END function.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1354
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1355 try
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1356 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1357 // Silently ignore extra output values.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1358
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1359 octave_value_list tmp_list
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1360 = base_expr_val.subsref (type.substr (beg, i-beg), idx, nargout);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1361
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1362 partial_expr_val = tmp_list.length () ? tmp_list(0) : octave_value ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1363
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1364 if (! indexing_object)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1365 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1366 base_expr_val = partial_expr_val;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1367
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1368 if (partial_expr_val.is_cs_list ())
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1369 err_indexed_cs_list ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1370
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1371 retval = partial_expr_val;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1372
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1373 beg = i;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1374 idx.clear ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1375
23671
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23616
diff changeset
1376 if (partial_expr_val.isobject () || partial_expr_val.isjava ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1377 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1378 // Found an object, so now we'll build up
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1379 // complete index list for one big subsref
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1380 // call from this point on.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1381
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1382 indexing_object = true;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1383 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1384 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1385 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1386 catch (index_exception& e)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1387 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1388 final_index_error (e, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1389 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1390 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1391 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1392
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1393 switch (type[i])
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1394 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1395 case '(':
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1396 idx.push_back (make_value_list (*p_args, *p_arg_nm, &partial_expr_val));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1397 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1398
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1399 case '{':
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1400 idx.push_back (make_value_list (*p_args, *p_arg_nm, &partial_expr_val));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1401 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1402
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1403 case '.':
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1404 idx.push_back (octave_value
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1405 (idx_expr.get_struct_index (this, p_arg_nm, p_dyn_field)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1406 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1407
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1408 default:
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1409 panic_impossible ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1410 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1411
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1412 p_args++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1413 p_arg_nm++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1414 p_dyn_field++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1415 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1416
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1417 if (! idx.empty () && (! base_expr_val.is_function ()
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1418 || base_expr_val.is_classdef_meta ()))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1419 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1420 try
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1421 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1422 retval = base_expr_val.subsref (type.substr (beg, n-beg), idx, nargout);
23684
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1423
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1424 beg = n;
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1425 idx.clear ();
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1426 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1427 catch (index_exception& e) // range problems, bad index type, etc.
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1428 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1429 final_index_error (e, expr);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1430 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1431 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1432
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1433 // This happens if... ??
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1434
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1435 octave_value val = (retval.length () ? retval(0) : octave_value ());
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1436
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1437 if (val.is_function ())
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1438 {
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1439 octave_function *fcn = val.function_value (true);
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1440
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1441 if (fcn)
23684
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1442 {
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1443 octave_value_list final_args;
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1444
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1445 if (! idx.empty ())
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1446 {
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1447 if (n - beg != 1)
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1448 error ("unexpected extra index at end of expression");
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1449
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1450 if (type[beg] != '(')
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1451 error ("invalid index type '%c' for function call",
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1452 type[beg]);
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1453
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1454 final_args = idx.front ();
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1455 }
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1456
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1457 retval = fcn->call (*this, nargout, final_args);
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1458 }
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1459 }
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1460
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1461 m_value_stack.push (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1462 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1463
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1464 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1465 tree_evaluator::visit_matrix (tree_matrix& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1466 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1467 octave_value retval = Matrix ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1468
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1469 bool all_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1470 bool all_sq_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1471 bool all_dq_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1472 bool all_empty_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1473 bool all_real_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1474 bool any_sparse_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1475 bool any_class_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1476 bool frc_str_conv = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1477
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1478 tm_const tmp (expr, this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1479
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1480 if (tmp && ! tmp.empty ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1481 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1482 dim_vector dv = tmp.dims ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1483 all_strings_p = tmp.all_strings_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1484 all_sq_strings_p = tmp.all_sq_strings_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1485 all_dq_strings_p = tmp.all_dq_strings_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1486 all_empty_p = tmp.all_empty_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1487 all_real_p = tmp.all_real_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1488 any_sparse_p = tmp.any_sparse_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1489 any_class_p = tmp.any_class_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1490 frc_str_conv = tmp.some_strings_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1491
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1492 // Try to speed up the common cases.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1493
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1494 std::string result_type = tmp.class_name ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1495
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1496 if (any_class_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1497 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1498 retval = do_class_concat (tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1499 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1500 else if (result_type == "double")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1501 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1502 if (any_sparse_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1503 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1504 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1505 retval = do_single_type_concat<SparseMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1506 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1507 retval = do_single_type_concat<SparseComplexMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1508 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1509 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1510 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1511 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1512 retval = do_single_type_concat<NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1513 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1514 retval = do_single_type_concat<ComplexNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1515 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1516 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1517 else if (result_type == "single")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1518 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1519 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1520 retval = do_single_type_concat<FloatNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1521 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1522 retval = do_single_type_concat<FloatComplexNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1523 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1524 else if (result_type == "char")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1525 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1526 char type = (all_dq_strings_p ? '"' : '\'');
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1527
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1528 if (! all_strings_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1529 warn_implicit_conversion ("Octave:num-to-str",
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1530 "numeric", result_type);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1531 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1532 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1533
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
1534 charNDArray result (dv, m_string_fill_char);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1535
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1536 single_type_concat<charNDArray> (result, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1537
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1538 retval = octave_value (result, type);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1539 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1540 else if (result_type == "logical")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1541 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1542 if (any_sparse_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1543 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1544 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1545 retval = do_single_type_concat<boolNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1546 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1547 else if (result_type == "int8")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1548 retval = do_single_type_concat<int8NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1549 else if (result_type == "int16")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1550 retval = do_single_type_concat<int16NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1551 else if (result_type == "int32")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1552 retval = do_single_type_concat<int32NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1553 else if (result_type == "int64")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1554 retval = do_single_type_concat<int64NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1555 else if (result_type == "uint8")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1556 retval = do_single_type_concat<uint8NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1557 else if (result_type == "uint16")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1558 retval = do_single_type_concat<uint16NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1559 else if (result_type == "uint32")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1560 retval = do_single_type_concat<uint32NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1561 else if (result_type == "uint64")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1562 retval = do_single_type_concat<uint64NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1563 else if (result_type == "cell")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1564 retval = do_single_type_concat<Cell> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1565 else if (result_type == "struct")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1566 retval = do_single_type_concat<octave_map> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1567 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1568 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1569 // The line below might seem crazy, since we take a copy of
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1570 // the first argument, resize it to be empty and then resize
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1571 // it to be full. This is done since it means that there is
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1572 // no recopying of data, as would happen if we used a single
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1573 // resize. It should be noted that resize operation is also
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1574 // significantly slower than the do_cat_op function, so it
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1575 // makes sense to have an empty matrix and copy all data.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1576 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1577 // We might also start with a empty octave_value using
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1578 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1579 // ctmp = octave_value_typeinfo::lookup_type
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1580 // (tmp.begin() -> begin() -> type_name());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1581 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1582 // and then directly resize. However, for some types there
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1583 // might be some additional setup needed, and so this should
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1584 // be avoided.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1585
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1586 octave_value ctmp;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1587
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1588 // Find the first non-empty object
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1589
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1590 if (any_sparse_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1591 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1592 // Start with sparse matrix to avoid issues memory issues
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1593 // with things like [ones(1,4),sprandn(1e8,4,1e-4)]
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1594 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1595 ctmp = octave_sparse_matrix ().resize (dv);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1596 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1597 ctmp = octave_sparse_complex_matrix ().resize (dv);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1598 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1599 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1600 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1601 for (tm_row_const& row : tmp)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1602 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1603 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1604
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1605 for (auto& elt : row)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1606 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1607 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1608
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1609 ctmp = elt;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1610
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1611 if (! ctmp.all_zero_dims ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1612 goto found_non_empty;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1613 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1614 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1615
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1616 ctmp = (*(tmp.begin () -> begin ()));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1617
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1618 found_non_empty:
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1619
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1620 if (! all_empty_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1621 ctmp = ctmp.resize (dim_vector (0,0)).resize (dv);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1622 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1623
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1624 // Now, extract the values from the individual elements and
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1625 // insert them in the result matrix.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1626
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1627 int dv_len = dv.ndims ();
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1628 octave_idx_type ntmp = (dv_len > 1 ? dv_len : 2);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1629 Array<octave_idx_type> ra_idx (dim_vector (ntmp, 1), 0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1630
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1631 for (tm_row_const& row : tmp)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1632 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1633 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1634
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1635 for (auto& elt : row)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1636 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1637 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1638
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1639 if (elt.isempty ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1640 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1641
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1642 ctmp = do_cat_op (ctmp, elt, ra_idx);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1643
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1644 ra_idx (1) += elt.columns ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1645 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1646
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1647 ra_idx (0) += row.rows ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1648 ra_idx (1) = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1649 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1650
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1651 retval = ctmp;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1652
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1653 if (frc_str_conv && ! retval.is_string ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1654 retval = retval.convert_to_str ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1655 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1656 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1657
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1658 m_value_stack.push (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1659 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1660
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1661 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1662 tree_evaluator::visit_cell (tree_cell& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1663 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1664 octave_value retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1665
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1666 // Function calls inside an argument list can't have ignored
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1667 // output arguments.
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1668
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1669 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1670
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1671 m_lvalue_list_stack.push (0);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1672
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1673 frame.add_method (m_lvalue_list_stack,
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1674 &value_stack<const std::list<octave_lvalue>*>::pop);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1675
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1676 octave_idx_type nr = expr.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1677 octave_idx_type nc = -1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1678
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1679 Cell val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1680
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1681 octave_idx_type i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1682
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1683 for (tree_argument_list *elt : expr)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1684 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1685 octave_value_list row = elt->convert_to_const_vector (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1686
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1687 if (nr == 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1688 // Optimize the single row case.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1689 val = row.cell_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1690 else if (nc < 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1691 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1692 nc = row.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1693
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1694 val = Cell (nr, nc);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1695 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1696 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1697 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1698 octave_idx_type this_nc = row.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1699
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1700 if (this_nc != nc)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1701 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1702 if (this_nc == 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1703 continue; // blank line
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1704 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1705 error ("number of columns must match");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1706 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1707 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1708
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1709 for (octave_idx_type j = 0; j < nc; j++)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1710 val(i,j) = row(j);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1711
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1712 i++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1713 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1714
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1715 if (i < nr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1716 val.resize (dim_vector (i, nc)); // there were blank rows
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1717
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1718 retval = val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1719
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1720 m_value_stack.push (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1721 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1722
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1723 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1724 tree_evaluator::visit_multi_assignment (tree_multi_assignment& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1725 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1726 octave_value_list val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1727
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1728 tree_expression *rhs = expr.right_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1729
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1730 if (rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1731 {
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1732 unwind_protect frame;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1733
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1734 tree_argument_list *lhs = expr.left_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1735
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1736 std::list<octave_lvalue> lvalue_list = make_lvalue_list (lhs);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1737
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1738 m_lvalue_list_stack.push (&lvalue_list);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1739
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1740 frame.add_method (m_lvalue_list_stack,
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1741 &value_stack<const std::list<octave_lvalue>*>::pop);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1742
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1743 octave_idx_type n_out = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1744
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1745 for (const auto& lval : lvalue_list)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1746 n_out += lval.numel ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1747
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1748 // The following trick is used to keep rhs_val constant.
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1749 const octave_value_list rhs_val1 = evaluate_n (rhs, n_out);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1750 const octave_value_list rhs_val = (rhs_val1.length () == 1
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1751 && rhs_val1(0).is_cs_list ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1752 ? rhs_val1(0).list_value ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1753 : rhs_val1);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1754
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1755 octave_idx_type k = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1756
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1757 octave_idx_type n = rhs_val.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1758
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1759 // To avoid copying per elements and possible optimizations, we
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1760 // postpone joining the final values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1761 std::list<octave_value_list> retval_list;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1762
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1763 tree_argument_list::iterator q = lhs->begin ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1764
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1765 for (octave_lvalue ult : lvalue_list)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1766 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1767 tree_expression *lhs_elt = *q++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1768
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1769 octave_idx_type nel = ult.numel ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1770
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1771 if (nel != 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1772 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1773 // Huge kluge so that wrapper scripts with lines like
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1774 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1775 // [varargout{1:nargout}] = fcn (args);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1776 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1777 // Will work the same as calling fcn directly when nargout
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1778 // is 0 and fcn produces more than one output even when
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1779 // nargout is 0. This only works if varargout has not yet
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1780 // been defined. See also bug #43813.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1781
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1782 if (lvalue_list.size () == 1 && nel == 0 && n > 0
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1783 && ! ult.is_black_hole () && ult.is_undefined ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1784 && ult.index_type () == "{" && ult.index_is_empty ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1785 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1786 // Convert undefined lvalue with empty index to a cell
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1787 // array with a single value and indexed by 1 to
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1788 // handle a single output.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1789
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1790 nel = 1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1791
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1792 ult.define (Cell (1, 1));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1793
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1794 ult.clear_index ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1795 std::list<octave_value_list> idx;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1796 idx.push_back (octave_value_list (octave_value (1)));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1797 ult.set_index ("{", idx);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1798 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1799
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1800 if (k + nel > n)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1801 error ("some elements undefined in return list");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1802
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1803 // This element of the return list expects a
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1804 // comma-separated list of values. Slicing avoids
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1805 // copying.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1806
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1807 octave_value_list ovl = rhs_val.slice (k, nel);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1808
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1809 ult.assign (octave_value::op_asn_eq, octave_value (ovl));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1810
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1811 retval_list.push_back (ovl);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1812
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1813 k += nel;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1814 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1815 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1816 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1817 if (k < n)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1818 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1819 ult.assign (octave_value::op_asn_eq, rhs_val(k));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1820
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1821 if (ult.is_black_hole ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1822 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1823 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1824 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1825 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1826 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1827 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1828 retval_list.push_back (rhs_val(k));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1829
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1830 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1831 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1832 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1833 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1834 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1835 // This can happen for a function like
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1836 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1837 // function varargout = f ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1838 // varargout{1} = nargout;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1839 // endfunction
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1840 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1841 // called with
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1842 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1843 // [a, ~] = f ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1844 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1845 // Then the list of of RHS values will contain one
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1846 // element but we are iterating over the list of all
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1847 // RHS values. We shouldn't complain that a value we
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1848 // don't need is missing from the list.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1849
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1850 if (! ult.is_black_hole ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1851 error ("element number %d undefined in return list", k+1);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1852
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1853 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1854 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1855 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1856 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1857
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
1858 if (expr.print_result () && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1859 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1860 // We clear any index here so that we can get
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1861 // the new value of the referenced object below,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1862 // instead of the indexed value (which should be
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1863 // the same as the right hand side value).
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1864
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1865 ult.clear_index ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1866
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1867 octave_value lhs_val = ult.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1868
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1869 octave_value_list args = ovl (lhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1870 args.stash_name_tags (string_vector (lhs_elt->name ()));
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1871 feval ("display", args);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1872 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1873 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1874
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1875 // Concatenate return values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1876 val = retval_list;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1877 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1878
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1879 m_value_stack.push (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1880 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
1881
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1882 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1883 tree_evaluator::visit_no_op_command (tree_no_op_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1884 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1885 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1886 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1887 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1888 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1889 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1890 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1891
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1892 if (debug_mode && cmd.is_end_of_fcn_or_script ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1893 do_breakpoint (cmd.is_breakpoint (true), true);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1894 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1895
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1896 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1897 tree_evaluator::visit_constant (tree_constant& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1898 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1899 int nargout = m_nargout_stack.top ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1900
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1901 if (nargout > 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1902 error ("invalid number of output arguments for constant expression");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1903
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1904 m_value_stack.push (ovl (expr.value ()));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1905 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1906
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1907 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1908 tree_evaluator::visit_fcn_handle (tree_fcn_handle& expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1909 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1910 std::string nm = expr.name ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1911
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1912 octave_value fh = make_fcn_handle (nm);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1913
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1914 m_value_stack.push (ovl (fh));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1915 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1916
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1917 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1918 tree_evaluator::visit_funcall (tree_funcall& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1919 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1920 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1921
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1922 octave_value fcn = expr.function ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1923
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1924 octave_value_list args = expr.arguments ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1925
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1926 int nargout = m_nargout_stack.top ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1927
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1928 retval = feval (fcn.function_value (), args, nargout);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1929
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1930 if (retval.length () == 1 && retval(0).is_function ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1931 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1932 // The return object is a function. We may need to re-index it
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1933 // using the same logic as for identifier. This is primarily
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1934 // used for superclass references in classdef.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1935
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1936 octave_value val = retval(0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1937 octave_function *f = val.function_value (true);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1938
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1939 if (f && ! (expr.is_postfix_indexed ()
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
1940 && f->accepts_postfix_index (expr.postfix_index ())))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1941 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
1942 retval = f->call (*this, nargout);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1943 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1944 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1945
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1946 m_value_stack.push (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1947 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1948
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1949 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1950 tree_evaluator::visit_parameter_list (tree_parameter_list&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1951 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1952 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1953 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1954
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1955 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1956 tree_evaluator::visit_postfix_expression (tree_postfix_expression& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1957 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1958 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1959
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1960 tree_expression *op = expr.operand ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1961
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1962 if (op)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1963 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1964 octave_value::unary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1965
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1966 if (etype == octave_value::op_incr || etype == octave_value::op_decr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1967 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1968 octave_lvalue ref = op->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1969
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1970 val = ref.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1971
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1972 profile_data_accumulator::enter<tree_postfix_expression>
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1973 block (profiler, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1974
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1975 ref.do_unary_op (etype);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1976 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1977 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1978 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1979 octave_value op_val = evaluate (op);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1980
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1981 if (op_val.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1982 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1983 profile_data_accumulator::enter<tree_postfix_expression>
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1984 block (profiler, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1985
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1986 val = ::do_unary_op (etype, op_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1987 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1988 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1989 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1990
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1991 m_value_stack.push (ovl (val));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1992 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1993
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1994 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1995 tree_evaluator::visit_prefix_expression (tree_prefix_expression& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1996 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1997 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1998
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1999 tree_expression *op = expr.operand ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2000
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2001 if (op)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2002 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2003 octave_value::unary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2004
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2005 if (etype == octave_value::op_incr || etype == octave_value::op_decr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2006 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2007 octave_lvalue op_ref = op->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2008
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2009 profile_data_accumulator::enter<tree_prefix_expression>
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2010 block (profiler, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2011
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2012 op_ref.do_unary_op (etype);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2013
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2014 val = op_ref.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2015 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2016 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2017 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2018 octave_value op_val = evaluate (op);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2019
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2020 if (op_val.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2021 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2022 profile_data_accumulator::enter<tree_prefix_expression>
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2023 block (profiler, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2024
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2025 // Attempt to do the operation in-place if it is unshared
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2026 // (a temporary expression).
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2027 if (op_val.get_count () == 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2028 val = op_val.do_non_const_unary_op (etype);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2029 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2030 val = ::do_unary_op (etype, op_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2031 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2032 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2033 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2034
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2035 m_value_stack.push (ovl (val));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2036 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2037
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2038 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2039 tree_evaluator::visit_return_command (tree_return_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2040 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2041 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2042 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2043 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2044 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2045 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2046 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2047
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2048 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2049 do_breakpoint (cmd.is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2050
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2051 // Act like dbcont.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2052
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2053 if (Vdebugging && m_call_stack.current_frame () == current_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2054 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2055 Vdebugging = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2056
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2057 reset_debug_state ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2058 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2059 else if (statement_context == function || statement_context == script
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2060 || in_loop_command)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2061 tree_return_command::returning = 1;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2062 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2063
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2064 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2065 tree_evaluator::visit_return_list (tree_return_list&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2066 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2067 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2068 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2069
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2070 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2071 tree_evaluator::visit_simple_assignment (tree_simple_assignment& expr)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2072 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2073 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2074
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2075 tree_expression *rhs = expr.right_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2076
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2077 if (rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2078 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2079 octave_value rhs_val = evaluate (rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2080
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2081 if (rhs_val.is_undefined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2082 error ("value on right hand side of assignment is undefined");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2083
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2084 if (rhs_val.is_cs_list ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2085 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2086 const octave_value_list lst = rhs_val.list_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2087
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2088 if (lst.empty ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2089 error ("invalid number of elements on RHS of assignment");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2090
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2091 rhs_val = lst(0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2092 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2093
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2094 tree_expression *lhs = expr.left_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2095
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2096 try
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2097 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2098 unwind_protect frame;
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2099
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2100 octave_lvalue ult = lhs->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2101
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2102 std::list<octave_lvalue> lvalue_list;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2103 lvalue_list.push_back (ult);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2104
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2105 m_lvalue_list_stack.push (&lvalue_list);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2106
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2107 frame.add_method (m_lvalue_list_stack,
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2108 &value_stack<const std::list<octave_lvalue>*>::pop);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2109
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2110 if (ult.numel () != 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2111 err_nonbraced_cs_list_assignment ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2112
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2113 octave_value::assign_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2114
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2115 ult.assign (etype, rhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2116
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2117 if (etype == octave_value::op_asn_eq)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2118 val = rhs_val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2119 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2120 val = ult.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2121
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2122 if (expr.print_result () && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2123 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2124 // We clear any index here so that we can
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2125 // get the new value of the referenced
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2126 // object below, instead of the indexed
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2127 // value (which should be the same as the
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2128 // right hand side value).
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2129
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2130 ult.clear_index ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2131
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2132 octave_value lhs_val = ult.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2133
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2134 octave_value_list args = ovl (lhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2135 args.stash_name_tags (string_vector (lhs->name ()));
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2136 feval ("display", args);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2137 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2138 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2139 catch (index_exception& e)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2140 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2141 e.set_var (lhs->name ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2142 std::string msg = e.message ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2143 error_with_id (e.err_id (), msg.c_str ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2144 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2145 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2146
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2147 m_value_stack.push (ovl (val));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2148 }
8662
af72c8137d64 improve looping over arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 8658
diff changeset
2149
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2150 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2151 tree_evaluator::visit_statement (tree_statement& stmt)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2152 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2153 tree_command *cmd = stmt.command ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2154 tree_expression *expr = stmt.expression ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2155
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2156 if (cmd || expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2157 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2158 if (statement_context == function || statement_context == script)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2159 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2160 // Skip commands issued at a debug> prompt to avoid disturbing
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2161 // the state of the program we are debugging.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2162
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2163 if (Vtrack_line_num)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2164 m_call_stack.set_location (stmt.line (), stmt.column ());
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2165 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2166
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2167 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2168 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2169 if (cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2170 cmd->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2171 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2172 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2173 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2174 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2175 size_t line = stmt.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2176 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2177 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2178 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2179
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2180 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2181 do_breakpoint (expr->is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2182
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2183 // FIXME: maybe all of this should be packaged in
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2184 // one virtual function that returns a flag saying whether
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2185 // or not the expression will take care of binding ans and
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2186 // printing the result.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2187
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2188 // FIXME: it seems that we should just have to
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2189 // evaluate the expression and that should take care of
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2190 // everything, binding ans as necessary?
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2191
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2192 bool do_bind_ans = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2193
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2194 if (expr->is_identifier ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2195 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2196 tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2197
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2198 do_bind_ans = (! id->is_variable ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2199 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2200 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2201 do_bind_ans = (! expr->is_assignment_expression ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2202
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2203 octave_value tmp_result = evaluate (expr, 0);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2204
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2205 if (do_bind_ans && tmp_result.is_defined ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2206 bind_ans (tmp_result, expr->print_result ()
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2207 && statement_printing_enabled ());
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2208
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2209 // if (tmp_result.is_defined ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2210 // result_values(0) = tmp_result;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2211 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2212 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2213 catch (const std::bad_alloc&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2214 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2215 // FIXME: We want to use error_with_id here so that give users
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2216 // control over this error message but error_with_id will
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2217 // require some memory allocations. Is there anything we can
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2218 // do to make those more likely to succeed?
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2219
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2220 error_with_id ("Octave:bad-alloc",
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2221 "out of memory or dimension too large for Octave's index type");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2222 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2223 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2224 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2225
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2226 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2227 tree_evaluator::visit_statement_list (tree_statement_list& lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2228 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2229 // FIXME: commented out along with else clause below.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2230 // static octave_value_list empty_list;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2231
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2232 tree_statement_list::iterator p = lst.begin ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2233
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2234 if (p != lst.end ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2235 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2236 while (true)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2237 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2238 tree_statement *elt = *p++;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2239
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2240 if (! elt)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2241 error ("invalid statement found in statement list!");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2242
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2243 octave_quit ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2244
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2245 elt->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2246
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2247 if (tree_break_command::breaking
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2248 || tree_continue_command::continuing)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2249 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2250
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2251 if (tree_return_command::returning)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2252 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2253
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2254 if (p == lst.end ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2255 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2256 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2257 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2258 // Clear previous values before next statement is
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2259 // evaluated so that we aren't holding an extra
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2260 // reference to a value that may be used next. For
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2261 // example, in code like this:
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2262 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2263 // X = rand (N); # refcount for X should be 1
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2264 // # after this statement
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2265 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2266 // X(idx) = val; # no extra copy of X should be
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2267 // # needed, but we will be faked
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2268 // # out if retval is not cleared
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2269 // # between statements here
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2270
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2271 // result_values = empty_list;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2272 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2273 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2274 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2275 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2276
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2277 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2278 tree_evaluator::visit_switch_case (tree_switch_case&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2279 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2280 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2281 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2282
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2283 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2284 tree_evaluator::visit_switch_case_list (tree_switch_case_list&)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2285 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2286 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2287 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2288
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2289 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2290 tree_evaluator::visit_switch_command (tree_switch_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2291 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2292 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2293 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2294 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2295 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2296 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2297 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2298
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2299 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2300 do_breakpoint (cmd.is_breakpoint (true));
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2301
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2302 tree_expression *expr = cmd.switch_value ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2303
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2304 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2305 error ("missing value in switch command near line %d, column %d",
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2306 cmd.line (), cmd.column ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2307
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2308 octave_value val = evaluate (expr);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2309
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2310 tree_switch_case_list *lst = cmd.case_list ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2311
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2312 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2313 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
2314 for (tree_switch_case *t : *lst)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2315 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2316 if (t->is_default_case () || switch_case_label_matches (t, val))
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2317 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2318 tree_statement_list *stmt_lst = t->commands ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2319
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2320 if (stmt_lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2321 stmt_lst->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2322
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2323 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2324 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2325 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2326 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2327 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2328
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2329 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2330 tree_evaluator::visit_try_catch_command (tree_try_catch_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2331 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2332 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2333 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2334 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2335 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2336 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2337 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2338
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2339 bool execution_error = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2340
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2341 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2342 // unwind frame before catch block
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2343 unwind_protect frame;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2344
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2345 frame.protect_var (buffer_error_messages);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2346 frame.protect_var (Vdebug_on_error);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2347 frame.protect_var (Vdebug_on_warning);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2348
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2349 buffer_error_messages++;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2350 Vdebug_on_error = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2351 Vdebug_on_warning = false;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2352
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2353 // The catch code is *not* added to unwind_protect stack;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2354 // it doesn't need to be run on interrupts.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2355
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2356 tree_statement_list *try_code = cmd.body ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2357
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2358 if (try_code)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2359 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2360 try
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2361 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2362 in_try_catch++;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2363 try_code->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2364 in_try_catch--;
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2365 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2366 catch (const execution_exception&)
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2367 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2368 interpreter::recover_from_exception ();
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
2369
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2370 in_try_catch--; // must be restored before "catch" block
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2371 execution_error = true;
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2372 }
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2373 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2374 // Unwind to let the user print any messages from
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2375 // errors that occurred in the body of the try_catch statement,
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2376 // or throw further errors.
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2377 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2378
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2379 if (execution_error)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2380 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2381 tree_statement_list *catch_code = cmd.cleanup ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2382 if (catch_code)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2383 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2384 tree_identifier *expr_id = cmd.identifier ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2385 octave_lvalue ult;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2386
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2387 if (expr_id)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2388 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2389 ult = expr_id->lvalue (this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2390
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2391 octave_scalar_map err;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2392
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2393 err.assign ("message", last_error_message ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2394 err.assign ("identifier", last_error_id ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2395 err.assign ("stack", last_error_stack ());
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2396
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2397 ult.assign (octave_value::op_asn_eq, err);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2398 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2399
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2400 // perform actual "catch" block
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2401 if (catch_code)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2402 catch_code->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2403 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2404 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2405 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2406
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2407 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2408 tree_evaluator::do_unwind_protect_cleanup_code (tree_statement_list *list)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2409 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2410 unwind_protect frame;
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2411
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2412 frame.protect_var (octave_interrupt_state);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2413 octave_interrupt_state = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2414
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2415 // We want to preserve the last location info for possible
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2416 // backtracking.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2417
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2418 frame.add_method (m_call_stack, &call_stack::set_line,
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2419 m_call_stack.current_line ());
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2420 frame.add_method (m_call_stack, &call_stack::set_column,
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2421 m_call_stack.current_column ());
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2422
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2423 // Similarly, if we have seen a return or break statement, allow all
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2424 // the cleanup code to run before returning or handling the break.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2425 // We don't have to worry about continue statements because they can
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2426 // only occur in loops.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2427
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2428 frame.protect_var (tree_return_command::returning);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2429 tree_return_command::returning = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2430
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2431 frame.protect_var (tree_break_command::breaking);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2432 tree_break_command::breaking = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2433
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2434 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2435 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2436 if (list)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2437 list->accept (*this);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2438 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2439 catch (const execution_exception&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2440 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2441 interpreter::recover_from_exception ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2442
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2443 if (tree_break_command::breaking || tree_return_command::returning)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2444 frame.discard (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2445 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2446 frame.run (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2447
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2448 frame.discard (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2449
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2450 throw;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2451 }
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2452
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2453 // The unwind_protects are popped off the stack in the reverse of
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2454 // the order they are pushed on.
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2455
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2456 // FIXME: these statements say that if we see a break or
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2457 // return statement in the cleanup block, that we want to use the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2458 // new value of the breaking or returning flag instead of restoring
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2459 // the previous value. Is that the right thing to do? I think so.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2460 // Consider the case of
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2461 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2462 // function foo ()
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2463 // unwind_protect
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2464 // fprintf (stderr, "1: this should always be executed\n");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2465 // break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2466 // fprintf (stderr, "1: this should never be executed\n");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2467 // unwind_protect_cleanup
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2468 // fprintf (stderr, "2: this should always be executed\n");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2469 // return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2470 // fprintf (stderr, "2: this should never be executed\n");
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2471 // end_unwind_protect
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2472 // endfunction
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2473 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2474 // If we reset the value of the breaking flag, both the returning
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2475 // flag and the breaking flag will be set, and we shouldn't have
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2476 // both. So, use the most recent one. If there is no return or
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2477 // break in the cleanup block, the values should be reset to
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2478 // whatever they were when the cleanup block was entered.
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2479
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2480 if (tree_break_command::breaking || tree_return_command::returning)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2481 frame.discard (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2482 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2483 frame.run (2);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2484 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2485
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2486 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2487 tree_evaluator::visit_unwind_protect_command (tree_unwind_protect_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2488 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2489 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2490 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2491 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2492 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2493 m_echo_file_pos = line + 1;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2494 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2495
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2496 tree_statement_list *cleanup_code = cmd.cleanup ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2497
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2498 tree_statement_list *unwind_protect_code = cmd.body ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2499
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2500 if (unwind_protect_code)
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2501 {
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2502 try
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2503 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2504 unwind_protect_code->accept (*this);
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2505 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2506 catch (const execution_exception&)
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2507 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2508 // FIXME: Maybe we should be able to temporarily set the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2509 // interpreter's exception handling state to something "safe"
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2510 // while the cleanup block runs instead of just resetting it
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2511 // here?
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2512 interpreter::recover_from_exception ();
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2513
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2514 // Run the cleanup code on exceptions, so that it is run even
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2515 // in case of interrupt or out-of-memory.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2516 do_unwind_protect_cleanup_code (cleanup_code);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2517
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2518 // If an error occurs inside the cleanup code, a new
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2519 // exception will be thrown instead of the original.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2520 throw;
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2521 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2522 catch (const interrupt_exception&)
23612
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2523 {
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2524 // The comments above apply here as well.
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2525 interpreter::recover_from_exception ();
23612
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2526 do_unwind_protect_cleanup_code (cleanup_code);
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2527 throw;
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2528 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2529
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2530 // Also execute the unwind_protect_cleanump code if the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2531 // unwind_protect block runs without error.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2532 do_unwind_protect_cleanup_code (cleanup_code);
21922
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2533 }
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2534 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2535
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2536 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2537 tree_evaluator::visit_while_command (tree_while_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2538 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2539 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2540
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2541 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2542 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2543 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2544 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2545 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2546
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2547 #if defined (HAVE_LLVM)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2548 if (tree_jit::execute (cmd))
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2549 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2550 #endif
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9378
diff changeset
2551
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2552 unwind_protect frame;
10210
752f349052a2 ensure correct backtraces after error in unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 10194
diff changeset
2553
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2554 frame.protect_var (in_loop_command);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2555
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2556 in_loop_command = true;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2557
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2558 tree_expression *expr = cmd.condition ();
20824
8848e35e5ef8 better handling of exceptions in unwind-protect blocks
John W. Eaton <jwe@octave.org>
parents: 20784
diff changeset
2559
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2560 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2561 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2562
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2563 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2564 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2565 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2566 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2567
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2568 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2569 do_breakpoint (cmd.is_breakpoint (true));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2570
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2571 if (is_logically_true (expr, "while"))
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2572 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2573 tree_statement_list *loop_body = cmd.body ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2574
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2575 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2576 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2577
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2578 if (quit_loop_now ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2579 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2580 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2581 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2582 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2583 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2584 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2585
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2586 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2587 tree_evaluator::visit_do_until_command (tree_do_until_command& cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2588 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2589 size_t line = cmd.line ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2590
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2591 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2592 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2593 echo_code (line);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2594 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2595 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2596
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
2597 #if defined (HAVE_LLVM)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2598 if (tree_jit::execute (cmd))
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2599 return;
15023
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2600 #endif
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2601
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2602 unwind_protect frame;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2603
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2604 frame.protect_var (in_loop_command);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2605
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2606 in_loop_command = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2607
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2608 tree_expression *expr = cmd.condition ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2609 int until_line = cmd.line ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2610 int until_column = cmd.column ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2611
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2612 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2613 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2614
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2615 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2616 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2617 if (m_echo_state)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2618 m_echo_file_pos = line;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2619
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2620 tree_statement_list *loop_body = cmd.body ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2621
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2622 if (loop_body)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2623 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2624
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2625 if (quit_loop_now ())
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2626 break;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2627
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2628 if (debug_mode)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2629 do_breakpoint (cmd.is_breakpoint (true));
18325
2a8243d8327a jit compiler: Add support for the do_until statement
LYH <lyh.kernel@gmail.com>
parents: 18270
diff changeset
2630
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2631 m_call_stack.set_location (until_line, until_column);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2632
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2633 if (is_logically_true (expr, "do-until"))
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2634 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2635 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2636 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2637
23702
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2638 void tree_evaluator::bind_ans (const octave_value& val, bool print)
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2639 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2640 static std::string ans = "ans";
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2641
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2642 if (val.is_defined ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2643 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2644 if (val.is_cs_list ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2645 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2646 octave_value_list lst = val.list_value ();
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2647
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2648 for (octave_idx_type i = 0; i < lst.length (); i++)
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2649 bind_ans (lst(i), print);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2650 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2651 else
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2652 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2653 symbol_table::scope *scope
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2654 = m_interpreter.require_current_scope ("tree_evaluator::bind_ans");
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2655
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2656 scope->force_assign (ans, val);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2657
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2658 if (print)
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2659 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2660 octave_value_list args = ovl (val);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2661 args.stash_name_tags (string_vector (ans));
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2662 feval ("display", args);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2663 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2664 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2665 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2666 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2667
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2668 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2669 tree_evaluator::do_breakpoint (tree_statement& stmt) const
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2670 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2671 do_breakpoint (stmt.is_breakpoint (true), stmt.is_end_of_fcn_or_script ());
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2672 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
2673
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2674 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2675 tree_evaluator::do_breakpoint (bool is_breakpoint,
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2676 bool is_end_of_fcn_or_script) const
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2677 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2678 bool break_on_this_statement = false;
21542
7ba48ff6ce83 Record correct line number with "until" command (bug #43249)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21301
diff changeset
2679
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2680 if (octave_debug_on_interrupt_state)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2681 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2682 break_on_this_statement = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2683
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2684 octave_debug_on_interrupt_state = false;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2685
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2686 current_frame = m_call_stack.current_frame ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2687 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2688 else if (is_breakpoint)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2689 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2690 break_on_this_statement = true;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2691
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2692 dbstep_flag = 0;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2693
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2694 current_frame = m_call_stack.current_frame ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2695 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2696 else if (dbstep_flag > 0)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2697 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2698 if (m_call_stack.current_frame () == current_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2699 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2700 if (dbstep_flag == 1 || is_end_of_fcn_or_script)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2701 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2702 // We get here if we are doing a "dbstep" or a "dbstep N" and the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2703 // count has reached 1 so that we must stop and return to debug
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2704 // prompt. Alternatively, "dbstep N" has been used but the end
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2705 // of the frame has been reached so we stop at the last line and
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2706 // return to prompt.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2707
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2708 break_on_this_statement = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2709
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2710 dbstep_flag = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2711 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2712 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2713 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2714 // Executing "dbstep N". Decrease N by one and continue.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2715
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2716 dbstep_flag--;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2717 }
15574
d20cbfec6df7 Fix off-by-1 error when executing 'dbstep N'
Rik <rik@octave.org>
parents: 15469
diff changeset
2718
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2719 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2720 else if (dbstep_flag == 1
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2721 && m_call_stack.current_frame () < current_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2722 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2723 // We stepped out from the end of a function.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2724
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2725 current_frame = m_call_stack.current_frame ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2726
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2727 break_on_this_statement = true;
15574
d20cbfec6df7 Fix off-by-1 error when executing 'dbstep N'
Rik <rik@octave.org>
parents: 15469
diff changeset
2728
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2729 dbstep_flag = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2730 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2731 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2732 else if (dbstep_flag == -1)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2733 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2734 // We get here if we are doing a "dbstep in".
16396
c6a13c1900fc make "dbstep out" and "dbstep" after "dbstep in" work properly
John W. Eaton <jwe@octave.org>
parents: 16354
diff changeset
2735
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2736 break_on_this_statement = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2737
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2738 dbstep_flag = 0;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2739
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2740 current_frame = m_call_stack.current_frame ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2741 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2742 else if (dbstep_flag == -2)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2743 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2744 // We get here if we are doing a "dbstep out". Check for end of
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2745 // function and whether the current frame is the same as the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2746 // cached value because we want to step out from the frame where
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2747 // "dbstep out" was evaluated, not from any functions called from
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2748 // that frame.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2749
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2750 if (is_end_of_fcn_or_script
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2751 && m_call_stack.current_frame () == current_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2752 dbstep_flag = -1;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2753 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2754
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2755 if (break_on_this_statement)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2756 do_keyboard ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2757
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2758 }
10219
979fb2606c4f new tree_evaluator::do_keyoard function
Ryan Rusaw <rrusaw@gmail.com>
parents: 10210
diff changeset
2759
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2760 // ARGS is currently unused, but since the do_keyboard function in
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2761 // input.cc accepts an argument list, we preserve it here so that the
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2762 // interface won't have to change if we decide to use it in the future.
10219
979fb2606c4f new tree_evaluator::do_keyoard function
Ryan Rusaw <rrusaw@gmail.com>
parents: 10210
diff changeset
2763
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2764 octave_value
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2765 tree_evaluator::do_keyboard (const octave_value_list& args) const
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2766 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2767 return ::do_keyboard (args);
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2768 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2769
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2770 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2771 tree_evaluator::is_logically_true (tree_expression *expr,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2772 const char *warn_for)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2773 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2774 bool expr_value = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2775
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2776 octave_value t1 = evaluate (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2777
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2778 if (t1.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2779 return t1.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2780 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2781 error ("%s: undefined value used in conditional expression", warn_for);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2782
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2783 return expr_value;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2784 }
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2785
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2786 octave_value_list
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2787 tree_evaluator::make_value_list (tree_argument_list *args,
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2788 const string_vector& arg_nm,
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2789 const octave_value *object, bool rvalue)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2790 {
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2791 octave_value_list retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2792
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2793 if (args)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2794 {
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2795 // Function calls inside an argument list can't have ignored
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2796 // output arguments.
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2797
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2798 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2799
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2800 m_lvalue_list_stack.push (0);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2801
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2802 frame.add_method (m_lvalue_list_stack,
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2803 &value_stack<const std::list<octave_lvalue>*>::pop);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2804
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2805 if (rvalue && object && args->has_magic_end ()
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2806 && object->is_undefined ())
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2807 err_invalid_inquiry_subscript ();
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2808
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2809 retval = args->convert_to_const_vector (this, object);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2810 }
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2811
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2812 octave_idx_type n = retval.length ();
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2813
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2814 if (n > 0)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2815 retval.stash_name_tags (arg_nm);
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2816
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2817 return retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2818 }
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2819
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2820 std::list<octave_lvalue>
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2821 tree_evaluator::make_lvalue_list (tree_argument_list *lhs)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2822 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2823 std::list<octave_lvalue> retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2824
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2825 for (tree_expression *elt : *lhs)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2826 retval.push_back (elt->lvalue (this));
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2827
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2828 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2829 }
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2830
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2831 octave_value
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2832 tree_evaluator::max_recursion_depth (const octave_value_list& args,
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2833 int nargout)
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2834 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2835 return set_internal_variable (m_max_recursion_depth, args, nargout,
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2836 "max_recursion_depth", 0);
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2837 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2838
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2839 octave_value
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2840 tree_evaluator::silent_functions (const octave_value_list& args, int nargout)
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2841 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2842 return set_internal_variable (m_silent_functions, args, nargout,
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2843 "silent_functions");
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2844 }
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
2845
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2846 octave_value
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2847 tree_evaluator::string_fill_char (const octave_value_list& args, int nargout)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2848 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2849 return set_internal_variable (m_string_fill_char, args, nargout,
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2850 "string_fill_char");
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2851 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2852
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2853 void
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2854 tree_evaluator::push_echo_state (unwind_protect& frame, int type,
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2855 const std::string& file_name,
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2856 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2857 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2858 push_echo_state_cleanup (frame);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2859
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2860 set_echo_state (type, file_name, pos);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2861 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2862
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2863 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2864 tree_evaluator::set_echo_state (int type, const std::string& file_name,
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2865 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2866 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2867 m_echo_state = echo_this_file (file_name, type);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2868 m_echo_file_name = file_name;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2869 m_echo_file_pos = pos;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2870 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2871
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2872 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2873 tree_evaluator::maybe_set_echo_state (void)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2874 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2875 octave_function *caller = m_call_stack.caller ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2876
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2877 if (caller && caller->is_user_code ())
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2878 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2879 octave_user_code *fcn = dynamic_cast<octave_user_code *> (caller);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2880
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2881 int type = fcn->is_user_function () ? ECHO_FUNCTIONS : ECHO_SCRIPTS;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2882
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2883 std::string file_name = fcn->fcn_file_name ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2884
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2885 size_t pos = m_call_stack.current_line ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2886
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2887 set_echo_state (type, file_name, pos);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2888 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2889 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2890
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2891 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2892 tree_evaluator::push_echo_state_cleanup (unwind_protect& frame)
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2893 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2894 frame.add_method (*this, &tree_evaluator::set_echo_state,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2895 m_echo_state);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2896
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2897 frame.add_method (*this, &tree_evaluator::set_echo_file_name,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2898 m_echo_file_name);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2899
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2900 frame.add_method (*this, &tree_evaluator::set_echo_file_pos,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2901 m_echo_file_pos);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2902 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2903
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2904 bool tree_evaluator::maybe_push_echo_state_cleanup (void)
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
2905 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2906 // This function is expected to be called from ECHO, which would be
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2907 // the top of the call stack. If the caller of ECHO is a
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2908 // user-defined fucntion or script, then set up unwind-protect
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2909 // elements to restore echo state.
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2910
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2911 octave_function *caller = m_call_stack.caller ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2912
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2913 if (caller && caller->is_user_code ())
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2914 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2915 octave_user_code *fcn = dynamic_cast<octave_user_code *> (caller);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2916
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2917 unwind_protect *frame = fcn->unwind_protect_frame ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2918
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2919 if (frame)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2920 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2921 push_echo_state_cleanup (*frame);
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2922 return true;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2923 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2924 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2925
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2926 return false;
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
2927 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2928
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2929
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2930 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2931 tree_evaluator::echo (const octave_value_list& args, int)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2932 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2933 bool cleanup_pushed = maybe_push_echo_state_cleanup ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2934
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2935 string_vector argv = args.make_argv ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2936
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2937 switch (args.length ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2938 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2939 case 0:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2940 if ((m_echo & ECHO_SCRIPTS) || (m_echo & ECHO_FUNCTIONS))
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2941 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2942 m_echo = ECHO_OFF;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2943 m_echo_files.clear ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2944 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2945 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2946 m_echo = ECHO_SCRIPTS;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2947 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2948
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2949 case 1:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2950 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2951 std::string arg0 = argv[0];
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2952
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2953 if (arg0 == "on")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2954 m_echo = ECHO_SCRIPTS;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2955 else if (arg0 == "off")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2956 m_echo = ECHO_OFF;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2957 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2958 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2959 std::string file = fcn_file_in_path (arg0);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2960 file = sys::env::make_absolute (file);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2961
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2962 if (file.empty ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2963 error ("echo: no such file %s", arg0.c_str ());
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2964
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2965 if (m_echo & ECHO_ALL)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2966 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2967 // Echo is enabled for all functions, so turn it off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2968 // for this one.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2969
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2970 m_echo_files[file] = false;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2971 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2972 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2973 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2974 // Echo may be enabled for specific functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2975
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2976 auto p = m_echo_files.find (file);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2977
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2978 if (p == m_echo_files.end ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2979 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2980 // Not this one, so enable it.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2981
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2982 m_echo |= ECHO_FUNCTIONS;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2983 m_echo_files[file] = true;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2984 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2985 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2986 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2987 // This one is already in the list. Flip the
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2988 // status for it.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2989
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2990 p->second = ! p->second;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2991 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2992 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2993 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2994 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2995 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2996
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2997 case 2:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2998 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2999 std::string arg0 = argv[0];
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3000 std::string arg1 = argv[1];
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3001
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3002 if (arg1 == "on" || arg1 == "off")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3003 std::swap (arg0, arg1);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3004
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3005 if (arg0 == "on")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3006 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3007 if (arg1 == "all")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3008 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3009 m_echo = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_ALL);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3010 m_echo_files.clear ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3011 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3012 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3013 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3014 std::string file = fcn_file_in_path (arg1);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3015 file = sys::env::make_absolute (file);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3016
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3017 if (file.empty ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3018 error ("echo: no such file %s", arg1.c_str ());
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3019
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3020 m_echo |= ECHO_FUNCTIONS;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3021 m_echo_files[file] = true;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3022 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3023 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3024 else if (arg0 == "off")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3025 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3026 if (arg1 == "all")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3027 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3028 m_echo = ECHO_OFF;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3029 m_echo_files.clear ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3030 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3031 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3032 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3033 std::string file = fcn_file_in_path (arg1);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3034 file = sys::env::make_absolute (file);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3035
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3036 if (file.empty ())
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3037 error ("echo: no such file %s", arg1.c_str ());
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3038
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3039 m_echo_files[file] = false;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3040 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3041 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3042 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3043 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3044 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3045 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3046
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3047 default:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3048 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3049 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3050 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3051
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3052 if (cleanup_pushed)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3053 maybe_set_echo_state ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3054
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3055 return ovl ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3056 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3057
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3058 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3059 tree_evaluator::PS4 (const octave_value_list& args, int nargout)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3060 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3061 return set_internal_variable (m_PS4, args, nargout, "PS4");
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3062 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3063
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3064 bool tree_evaluator::echo_this_file (const std::string& file, int type) const
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3065 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3066 if ((type & m_echo) == ECHO_SCRIPTS)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3067 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3068 // Asking about scripts and echo is enabled for them.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3069 return true;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3070 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3071
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3072 if ((type & m_echo) == ECHO_FUNCTIONS)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3073 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3074 // Asking about functions and echo is enabled for functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3075 // Now, which ones?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3076
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3077 auto p = m_echo_files.find (file);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3078
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3079 if (m_echo & ECHO_ALL)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3080 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3081 // Return true ulness echo was turned off for a specific
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3082 // file.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3083
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3084 return (p == m_echo_files.end () || p->second);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3085 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3086 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3087 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3088 // Return true if echo is specifically enabled for this file.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3089
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3090 return p != m_echo_files.end () && p->second;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3091 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3092 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3093
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3094 return false;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3095 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3096
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3097 void tree_evaluator::echo_code (size_t line)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3098 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3099 std::string prefix = command_editor::decode_prompt_string (m_PS4);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3100
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3101 octave_function *curr_fcn = m_call_stack.current ();
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3102
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3103 if (curr_fcn && curr_fcn->is_user_code ())
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3104 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3105 octave_user_code *code = dynamic_cast<octave_user_code *> (curr_fcn);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3106
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3107 size_t num_lines = line - m_echo_file_pos + 1;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3108
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3109 std::deque<std::string> lines
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3110 = code->get_code_lines (m_echo_file_pos, num_lines);
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3111
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3112 for (auto& elt : lines)
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3113 octave_stdout << prefix << elt << std::endl;
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3114 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3115 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3116 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3117
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3118 DEFMETHOD (max_recursion_depth, interp, args, nargout,
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3119 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3120 @deftypefn {} {@var{val} =} max_recursion_depth ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3121 @deftypefnx {} {@var{old_val} =} max_recursion_depth (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3122 @deftypefnx {} {} max_recursion_depth (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3123 Query or set the internal limit on the number of times a function may
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3124 be called recursively.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3125
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3126 If the limit is exceeded, an error message is printed and control returns to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3127 the top level.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3128
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3129 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3130 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3131 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3132 @end deftypefn */)
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3133 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3134 octave::tree_evaluator& tw = interp.get_evaluator ();
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3135
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3136 return tw.max_recursion_depth (args, nargout);
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3137 }
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3138
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3139 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3140 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3141 %! orig_val = max_recursion_depth ();
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3142 %! old_val = max_recursion_depth (2*orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3143 %! assert (orig_val, old_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3144 %! assert (max_recursion_depth (), 2*orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3145 %! max_recursion_depth (orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3146 %! assert (max_recursion_depth (), orig_val);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3147
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3148 %!error (max_recursion_depth (1, 2))
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3149 */
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3150
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3151 DEFMETHOD (silent_functions, interp, args, nargout,
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3152 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3153 @deftypefn {} {@var{val} =} silent_functions ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3154 @deftypefnx {} {@var{old_val} =} silent_functions (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3155 @deftypefnx {} {} silent_functions (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3156 Query or set the internal variable that controls whether internal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3157 output from a function is suppressed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3158
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3159 If this option is disabled, Octave will display the results produced by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3160 evaluating expressions within a function body that are not terminated with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3161 a semicolon.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3162
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3163 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3164 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3165 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3166 @end deftypefn */)
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3167 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3168 octave::tree_evaluator& tw = interp.get_evaluator ();
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3169
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3170 return tw.silent_functions (args, nargout);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3171 }
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3172
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3173 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3174 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3175 %! orig_val = silent_functions ();
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3176 %! old_val = silent_functions (! orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3177 %! assert (orig_val, old_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3178 %! assert (silent_functions (), ! orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3179 %! silent_functions (orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3180 %! assert (silent_functions (), orig_val);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3181
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3182 %!error (silent_functions (1, 2))
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3183 */
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3184
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3185 DEFMETHOD (string_fill_char, interp, args, nargout,
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3186 doc: /* -*- texinfo -*-
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3187 @deftypefn {} {@var{val} =} string_fill_char ()
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3188 @deftypefnx {} {@var{old_val} =} string_fill_char (@var{new_val})
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3189 @deftypefnx {} {} string_fill_char (@var{new_val}, "local")
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3190 Query or set the internal variable used to pad all rows of a character
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3191 matrix to the same length.
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3192
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3193 The value must be a single character and the default is @qcode{" "} (a
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3194 single space). For example:
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3195
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3196 @example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3197 @group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3198 string_fill_char ("X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3199 [ "these"; "are"; "strings" ]
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3200 @result{} "theseXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3201 "areXXXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3202 "strings"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3203 @end group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3204 @end example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3205
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3206 When called from inside a function with the @qcode{"local"} option, the
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3207 variable is changed locally for the function and any subroutines it calls.
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3208 The original variable value is restored when exiting the function.
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3209 @end deftypefn */)
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3210 {
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3211 octave::tree_evaluator& tw = interp.get_evaluator ();
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3212
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3213 return tw.string_fill_char (args, nargout);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3214 }
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3215
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3216 /*
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3217 ## string_fill_char() function call must be outside of %!test block
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3218 ## due to the way a %!test block is wrapped inside a function
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3219 %!shared orig_val, old_val
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3220 %! orig_val = string_fill_char ();
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3221 %! old_val = string_fill_char ("X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3222 %!test
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3223 %! assert (orig_val, old_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3224 %! assert (string_fill_char (), "X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3225 %! assert (["these"; "are"; "strings"], ["theseXX"; "areXXXX"; "strings"]);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3226 %! string_fill_char (orig_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3227 %! assert (string_fill_char (), orig_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3228
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3229 %!assert ( [ [], {1} ], {1} )
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3230
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3231 %!error (string_fill_char (1, 2))
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3232 */
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3233
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3234 DEFMETHOD (PS4, interp, args, nargout,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3235 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3236 @deftypefn {} {@var{val} =} PS4 ()
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3237 @deftypefnx {} {@var{old_val} =} PS4 (@var{new_val})
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3238 @deftypefnx {} {} PS4 (@var{new_val}, "local")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3239 Query or set the character string used to prefix output produced
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3240 when echoing commands is enabled.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3241
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3242 The default value is @qcode{"+ "}.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3243 @xref{Diary and Echo Commands}, for a description of echoing commands.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3244
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3245 When called from inside a function with the @qcode{"local"} option, the
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3246 variable is changed locally for the function and any subroutines it calls.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3247 The original variable value is restored when exiting the function.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3248 @seealso{echo, PS1, PS2}
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3249 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3250 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3251 octave::tree_evaluator& tw = interp.get_evaluator ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3252
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3253 return tw.PS4 (args, nargout);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3254 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3255
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3256 DEFMETHOD (echo, interp, args, nargout,
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3257 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3258 @deftypefn {} {} echo
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3259 @deftypefnx {} {} echo on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3260 @deftypefnx {} {} echo off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3261 @deftypefnx {} {} echo on all
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3262 @deftypefnx {} {} echo off all
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3263 @deftypefnx {} {} echo @var{function} on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3264 @deftypefnx {} {} echo @var{function} off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3265 Control whether commands are displayed as they are executed.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3266
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3267 Valid options are:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3268
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3269 @table @code
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3270 @item on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3271 Enable echoing of commands as they are executed in script files.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3272
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3273 @item off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3274 Disable echoing of commands as they are executed in script files.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3275
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3276 @item on all
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3277 Enable echoing of commands as they are executed in script files and
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3278 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3279
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3280 @item off all
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3281 Disable echoing of commands as they are executed in script files and
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3282 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3283
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3284 @item @var{function} on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3285 Enable echoing of commands as they are executed in the named function.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3286
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3287 @item @var{function} off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3288 Disable echoing of commands as they are executed in the named function.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3289 @end table
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3290
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3291 @noindent
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3292 With no arguments, @code{echo} toggles the current echo state.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3293
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3294 @seealso{PS4}
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3295 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3296 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3297 octave::tree_evaluator& tw = interp.get_evaluator ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3298
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3299 return tw.echo (args, nargout);
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3300 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3301
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3302 /*
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3303 %!error echo ([])
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3304 %!error echo (0)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3305 %!error echo ("")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3306 %!error echo ("Octave")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3307 %!error echo ("off", "invalid")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3308 %!error echo ("on", "invalid")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3309 %!error echo ("on", "all", "all")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3310 */