annotate libinterp/parse-tree/pt-eval.cc @ 24855:41f80b9af274

prevent stack overflow crash on deeply nested function calls (bug #47620) * call-stack.h, call-stack.cc (call_stack::m_max_stack_depth): New member variable. (call_stack::max_stack_depth): New function. (Fmax_stack_depth): New function. (call_stack::push): Error if call_stack size exceeds m_max_stack_depth. * pt-eval.cc (Fmax_recursion_depth): Add @seealso to doc string. * expr.txi: Document max_stack_depth.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Mar 2018 17:14:52 -0500
parents 3695c2cd69b8
children 6652d3823428
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24361
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24361
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24361
diff changeset
19 <https://www.gnu.org/licenses/>.
8658
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 {
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
81 m_result_type = RT_UNDEFINED;
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
82 m_expr_result_value = octave_value ();
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
83 m_expr_result_value_list = octave_value_list ();
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
84 m_lvalue_list_stack.clear ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
85 m_nargout_stack.clear ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
86 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
87
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
88 void
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
89 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
90 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
91 // 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
92 // I think that is what Matlab does.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
93
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
94 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
95 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
96
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
97 symbol_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
98
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
99 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
100
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
101 symbol_scope af_parent_scope;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
102 if (anon_fh.has_parent_scope ())
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
103 af_parent_scope = symtab.current_scope ();
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
104
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
105 symbol_scope new_scope;
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
106 if (af_scope)
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
107 new_scope = af_scope.dup ();
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
108
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
109 if (new_scope && af_parent_scope)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
110 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
111
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
112 tree_parameter_list *param_list_dup
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
113 = param_list ? param_list->dup (new_scope) : nullptr;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
114
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
115 tree_parameter_list *ret_list = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
116
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
117 tree_statement_list *stmt_list = nullptr;
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
118
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
119 if (expr)
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
120 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
121 tree_expression *expr_dup = expr->dup (new_scope);
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
122 tree_statement *stmt = new tree_statement (expr_dup, nullptr);
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
123 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
124 }
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
125
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
126 octave_user_function *af
23600
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
127 = 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
128 stmt_list);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
129
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
130 new_scope.set_parent (af_parent_scope);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
131
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
132 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
133
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
134 if (curr_fcn)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
135 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
136 // 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
137 // instead of individual bits of info about it?
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
138
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
139 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
140 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
141
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
142 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
143 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
144 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
145
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
146 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
147
db947ba52118 explicitly limit anonymous functions to a single expression
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
148 // 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
149 // 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
150 // 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
151
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
152 octave_value ov_fcn (af);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
153
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
154 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
155
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
156 push_result (fh);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
157 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
159 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
160 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
161 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
162 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
163 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
164
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
165 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
166 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
167 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
168 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
169
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
170 tree_expression *op_lhs = expr.lhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
171 tree_expression *op_rhs = expr.rhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
172 octave_value::binary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
173
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
174 if (expr.is_eligible_for_braindead_shortcircuit ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
175 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
176 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
177 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
178 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
179
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
180 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
181 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
182 bool result = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
183
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
184 bool a_true = a.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
185
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
186 if (a_true)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
187 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
188 if (etype == octave_value::op_el_or)
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 expr.matlab_style_short_circuit_warning ("|");
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
191 push_result (octave_value (true));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
192 return;
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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
195 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
196 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
197 if (etype == octave_value::op_el_and)
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 expr.matlab_style_short_circuit_warning ("&");
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
200 push_result (octave_value (false));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
201 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
202 }
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
205 if (op_rhs)
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 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
208
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
209 result = b.is_true ();
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
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
212 push_result (octave_value (result));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
213 return;
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 }
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
218 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
219 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
220 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
221
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
222 if (a.is_defined () && op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
223 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
224 octave_value b = evaluate (op_rhs);
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 if (b.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
227 {
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
228 profiler::enter<tree_binary_expression>
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
229 block (m_profiler, expr);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
230
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
231 // Note: The profiler does not catch the braindead
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
232 // 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
233 // 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
234 // 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
235 // timing the operator to make it reasonable.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
236
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
237 type_info& ti = m_interpreter.get_type_info ();
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
238
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
239 val = ::do_binary_op (ti, etype, a, b);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
240 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
241 }
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
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
244 push_result (val);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
245 }
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 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
248 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
249 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
250 octave_value val;
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 bool result = false;
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 // 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
255 // 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
256 // 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
257 // entangled together with short-circuit evaluation here.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
258
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
259 tree_expression *op_lhs = expr.lhs ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
260
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
261 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
262 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
263 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
264
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
265 bool a_true = a.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
266
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
267 tree_boolean_expression::type etype = expr.op_type ();
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 if (a_true)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
270 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
271 if (etype == tree_boolean_expression::bool_or)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
272 {
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
273 push_result (octave_value (true));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
274 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
275 }
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 else
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 if (etype == tree_boolean_expression::bool_and)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
280 {
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
281 push_result (octave_value (false));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
282 return;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
283 }
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
286 tree_expression *op_rhs = expr.rhs ();
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 if (op_rhs)
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 octave_value b = evaluate (op_rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
291
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
292 result = b.is_true ();
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
295 val = octave_value (result);
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
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
298 push_result (val);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
299 }
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 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
302 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
303 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
304 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
305
23523
d2748870db4e undo part of previous change
John W. Eaton <jwe@octave.org>
parents: 23522
diff changeset
306 tree_expression *op_lhs = expr.clhs ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
307
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
308 if (op_lhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
309 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
310 octave_value a = evaluate (op_lhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
311
23523
d2748870db4e undo part of previous change
John W. Eaton <jwe@octave.org>
parents: 23522
diff changeset
312 tree_expression *op_rhs = expr.crhs ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
313
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
314 if (a.is_defined () && op_rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
315 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
316 octave_value b = evaluate (op_rhs);
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 if (b.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
319 {
23522
d2e300f7700c fix compound binary op error introduced in c452180ab672
John W. Eaton <jwe@octave.org>
parents: 23521
diff changeset
320 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
321
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
322 type_info& ti = m_interpreter.get_type_info ();
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
323
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
324 val = ::do_binary_op (ti, etype, a, b);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
325 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
326 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
327 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
328
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
329 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
330 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
332 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
333 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
334 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
335 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
336 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
337 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
338 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
339 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
340 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
341
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
342 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
343 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
344
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
345 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
346 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
347 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
348 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
349 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
350
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
351 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
352 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
353 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
354 octave_value val;
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 tree_expression *op_base = expr.base ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
357 tree_expression *op_limit = expr.limit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
358
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
359 if (! op_base || ! op_limit)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
360 {
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
361 push_result (octave_value (val));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
362 return;
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
365 octave_value ov_base = evaluate (op_base);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
366
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
367 octave_value ov_limit = evaluate (op_limit);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
368
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
369 tree_expression *op_increment = expr.increment ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
370
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23584
diff changeset
371 if (ov_base.isobject () || ov_limit.isobject ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
372 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
373 octave_value_list tmp1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
374
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
375 if (op_increment)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
376 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
377 octave_value ov_increment = evaluate (op_increment);
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 tmp1(2) = ov_limit;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
380 tmp1(1) = ov_increment;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
381 tmp1(0) = ov_base;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
382 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
383 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
384 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
385 tmp1(1) = ov_limit;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
386 tmp1(0) = ov_base;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
387 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
388
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
389 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
390
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
391 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
392
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
393 if (! fcn.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
394 error ("can not find overloaded colon function");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
395
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
396 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
397
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
398 val = tmp2 (0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
399 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
400 else
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 octave_value ov_increment = 1.0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
403
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
404 if (op_increment)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
405 ov_increment = evaluate (op_increment);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
406
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
407 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
408 expr.is_for_cmd_expr ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
409 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
410
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
411 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
412 }
10188
97ae300aa73a improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents: 10186
diff changeset
413
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
414 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
415 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
416 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
417 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
418 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
419 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
420 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
421 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
422 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
423
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
424 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
425 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
426
22703
d43094e91ba7 Ignore continue statement when used outside of a loop (bug #48665)
Mike Miller <mtmiller@octave.org>
parents: 22407
diff changeset
427 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
428 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
429 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
431 bool
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
432 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
433 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
434 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
435 || 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
436 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
437
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
438 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
439 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
440 {
24738
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24722
diff changeset
441 bp_table& bptab = __get_bp_table__ ("tree_evaluator::reset_debug_state");
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24722
diff changeset
442
3695c2cd69b8 don't use singleton pattern for bp_table
John W. Eaton <jwe@octave.org>
parents: 24722
diff changeset
443 debug_mode = bptab.have_breakpoints () || Vdebugging;
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
444
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
445 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
446 }
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
447
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
448 Matrix
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
449 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
450 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
451 Matrix retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
452
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
453 const std::list<octave_lvalue> *lvalues = lvalue_list ();
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
454
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
455 if (! lvalues)
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
456 return retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
457
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
458 octave_idx_type nbh = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
459
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
460 for (const auto& lval : *lvalues)
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
461 nbh += lval.is_black_hole ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
462
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
463 if (nbh > 0)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
464 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
465 retval.resize (1, nbh);
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 octave_idx_type k = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
468 octave_idx_type l = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
469
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
470 for (const auto& lval : *lvalues)
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
471 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
472 if (lval.is_black_hole ())
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
473 retval(l++) = k+1;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
474
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
475 k += lval.numel ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
476 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
477 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
478
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
479 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
480 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
481
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
482 bool
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
483 tree_evaluator::isargout (int nargout, int iout) const
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
484 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
485 const std::list<octave_lvalue> *lvalues = lvalue_list ();
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
486
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
487 if (iout >= std::max (nargout, 1))
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
488 return false;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
489 else if (lvalues)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
490 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
491 int k = 0;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
492 for (const auto& lval : *lvalues)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
493 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
494 if (k == iout)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
495 return ! lval.is_black_hole ();
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
496 k += lval.numel ();
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
497 if (k > iout)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
498 break;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
499 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
500
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
501 return true;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
502 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
503 else
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
504 return true;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
505 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
506
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
507 void
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
508 tree_evaluator::isargout (int nargout, int nout, bool *isargout) const
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
509 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
510 const std::list<octave_lvalue> *lvalues = lvalue_list ();
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
511
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
512 if (lvalues)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
513 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
514 int k = 0;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
515 for (const auto& lval : *lvalues)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
516 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
517 if (lval.is_black_hole ())
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
518 isargout[k++] = false;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
519 else
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
520 {
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
521 int l = std::min (k + lval.numel (),
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
522 static_cast<octave_idx_type> (nout));
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
523 while (k < l)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
524 isargout[k++] = true;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
525 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
526 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
527 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
528 else
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
529 for (int i = 0; i < nout; i++)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
530 isargout[i] = true;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
531
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
532 for (int i = std::max (nargout, 1); i < nout; i++)
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
533 isargout[i] = false;
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
534 }
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
535
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
536 octave_value
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
537 tree_evaluator::evaluate (tree_decl_elt *elt)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
538 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
539 // Do not allow functions to return null values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
540
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
541 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
542
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
543 return id ? evaluate (id).storable_value () : octave_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
544 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
545
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
546 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
547 tree_evaluator::define_parameter_list_from_arg_vector
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
548 (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
549 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
550 int i = -1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
551
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
552 for (tree_decl_elt *elt : *param_list)
23435
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 i++;
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 octave_lvalue ref = elt->lvalue (this);
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 (i < args.length ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
559 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
560 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
561 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
562 if (! eval_decl_elt (elt))
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
563 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
564 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
565 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
566 ref.define (args(i));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
567 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
568 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
569 eval_decl_elt (elt);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
570 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
571 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
573 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
574 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
575 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
576 for (tree_decl_elt *elt : *param_list)
23435
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 octave_lvalue ref = elt->lvalue (this);
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 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
581 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
582 }
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_value_list
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
585 tree_evaluator::convert_return_list_to_const_vector
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
586 (tree_parameter_list *ret_list, int nargout, const Cell& varargout)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
587 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
588 octave_idx_type vlen = varargout.numel ();
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
589 int len = ret_list->length ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
590
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
591 // Special case. Will do a shallow copy.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
592 if (len == 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
593 return varargout;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
594 else if (nargout <= len)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
595 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
596 symbol_scope scope = get_current_scope ();
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
597
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
598 symbol_record::context_id context = scope.current_context ();
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
599
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
600 octave_value_list retval (nargout);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
601
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
602 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
603
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
604 for (tree_decl_elt *elt : *ret_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
605 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
606 if (elt->is_defined (context))
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
607 {
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
608 octave_value tmp = evaluate (elt);
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
609 retval(i) = tmp;
23602
214cb58ccc1c use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents: 23600
diff changeset
610 }
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
611
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
612 i++;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
613 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
614
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
615 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
616 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
617 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
618 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
619 octave_value_list retval (len + vlen);
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 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
622
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
623 for (tree_decl_elt *elt : *ret_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
624 retval(i++) = evaluate (elt);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
625
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
626 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
627 retval(i++) = varargout(j);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
628
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
629 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
630 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
631 }
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 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
634 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
635 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
636 bool retval = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
637
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
638 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
639 tree_expression *expr = elt->expression ();
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 if (id && expr)
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 octave_lvalue ult = id->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
644
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
645 octave_value init_val = evaluate (expr);
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 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
648
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
649 retval = true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
650 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
651
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
652 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
653 }
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 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
656 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
657 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
658 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
659 tree_expression *label = expr->case_label ();
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 octave_value label_value = evaluate (label);
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 if (label_value.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
664 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
665 if (label_value.iscell ())
23435
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 Cell cell (label_value.cell_value ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
668
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
669 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
670 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
671 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
672 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
673 bool match = val.is_equal (cell(i,j));
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 if (match)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
676 return true;
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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
680 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
681 return val.is_equal (label_value);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
682 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
683
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
684 return false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
685 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
686
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
687 symbol_scope
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
688 tree_evaluator::get_current_scope (void)
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
689 {
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
690 symbol_table& symtab = m_interpreter.get_symbol_table ();
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
691
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
692 return symtab.current_scope ();
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
693 }
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
694
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
695 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
696 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
697 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
698 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
699 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
700 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
701 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
702 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
703 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
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 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
706 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
707
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
708 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
709
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
710 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
711 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
712 }
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
713
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
714 void
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
715 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
716 {
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
717 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
718 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
719 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
721 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
722 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
723 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
724 tree_identifier *id = elt.ident ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
725
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
726 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
727 {
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
728 if (elt.is_global ())
24352
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
729 {
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
730 symbol_table& symtab = m_interpreter.get_symbol_table ();
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
731
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
732 symbol_record global_sym = symtab.find_global_symbol (id->name ());
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
733
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
734 id->link_to_global (symtab.global_scope (), global_sym);
24352
bff8e3884a88 restructure global variable handling in symbol table
John W. Eaton <jwe@octave.org>
parents: 24349
diff changeset
735 }
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
736 else if (elt.is_persistent ())
23470
a41fdb801db6 use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents: 23469
diff changeset
737 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
738 else
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
739 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
740
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
741 octave_lvalue ult = id->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
742
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
743 if (ult.is_undefined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
744 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
745 tree_expression *expr = elt.expression ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
746
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
747 octave_value init_val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
748
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
749 if (expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
750 init_val = evaluate (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
751 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
752 init_val = Matrix ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
753
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
754 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
755 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
756 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
757 }
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
758
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
759 // Decide if it's time to quit a for or while loop.
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
760 static inline bool
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
761 quit_loop_now (void)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
762 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
763 octave_quit ();
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
764
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
765 // Maybe handle 'continue N' someday...
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
766
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
767 if (octave::tree_continue_command::continuing)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
768 octave::tree_continue_command::continuing--;
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
769
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
770 bool quit = (octave::tree_return_command::returning
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
771 || octave::tree_break_command::breaking
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
772 || octave::tree_continue_command::continuing);
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
773
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
774 if (octave::tree_break_command::breaking)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
775 octave::tree_break_command::breaking--;
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
776
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
777 return quit;
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
778 }
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
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 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
781 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
782 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
783 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
784
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
785 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
786 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
787 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
788 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
789 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
790
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
791 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
792 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
793
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
794 // 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
795 // and cmd.maxproc_expr ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
796
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
797 unwind_protect frame;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
798
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
799 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
800
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
801 in_loop_command = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
802
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
803 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
804
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
805 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
806
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
807 #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
808 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
809 return;
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
810 #endif
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
811
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
812 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
813 return;
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 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
816
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
817 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
818
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
819 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
820
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
821 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
822 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
823 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
824
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
825 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
826
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
827 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
828 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
829 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
830 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
831
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
832 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
833
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
834 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
835
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
836 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
837 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
838
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
839 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
840 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
841 }
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 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
844 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
845 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
846 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
847
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
848 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
849
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
850 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
851 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
853 // 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
854 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
855 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
856 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
857 || 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
858 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
859 // 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
860 // columns.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
861
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
862 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
863
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
864 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
865 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
866
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
867 octave_value arg = rhs;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
868 if (rhs.ndims () > 2)
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
869 arg = arg.reshape (dv);
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
870
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
871 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
872 {
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
873 octave_value_list idx;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
874 octave_idx_type iidx;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
875
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
876 // 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
877 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
878 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
879 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
880 iidx = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
881 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
882 else
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 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
885 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
886 iidx = 1;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
887 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
888
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
889 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
890 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
891 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
892 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
893
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
894 // 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
895 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
896 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
897
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
898 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
899
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
900 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
901 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
902
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
903 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
904 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
905 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
906 }
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
907 else
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
908 {
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
909 // 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
910 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
911 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
912 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
913 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
914 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
915 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
916 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
917
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
918 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
919 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
920 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
921 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
922
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
923 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
924 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
925 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
926 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
927 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
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 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
930 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
931
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
932 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
933
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
934 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
935
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
936 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
937
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
938 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
939
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
940 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
941
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
942 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
943 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
944
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
945 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
946 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
947
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
948 // 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
949 // 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
950 // structure element.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
951
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
952 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
953
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
954 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
955
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
956 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
957
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
958 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
959
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
960 elt = *p;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
961
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
962 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
963
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
964 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
965
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
966 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
967
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
968 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
969
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
970 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
971
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
972 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
973 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
974 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
975 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
976
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
977 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
978
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
979 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
980
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
981 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
982
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
983 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
984
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
985 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
986 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
987
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
988 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
989 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
990
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
991 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
992 break;
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 }
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 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
997 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
998 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
999 // ??
22196
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_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
1005 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1006 // ??
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1007 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1008 }
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 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1011 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
1012 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1013 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1014 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1015
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1016 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1017 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
1018 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1019 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1020 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1021
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1022 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1023 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
1024 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1025 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
1026
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1027 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
1028
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1029 if (f)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1030 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1031 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
1032
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1033 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
1034
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
1035 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
1036
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1037 // 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
1038 // 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
1039
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1040 symbol_scope scope = symtab.current_scope ();
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1041
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23604
diff changeset
1042 if (scope)
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1043 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
1044 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1045 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
1046
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1047 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1048 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
1049 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1050 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1051
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1052 symbol_scope scope = get_current_scope ();
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1053
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1054 symbol_record::context_id context = scope.current_context ();
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
1055
24270
bc3819b7cca1 don't use symbol_table:: nesting for symbol_record, symbol_scope, or fcn_info
John W. Eaton <jwe@octave.org>
parents: 24075
diff changeset
1056 symbol_record sym = expr.symbol ();
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1057
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
1058 octave_value val = sym.find (context);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1059
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1060 if (val.is_defined ())
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 // GAGME -- this would be cleaner if we required
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1063 // parens to indicate function calls.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1064 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1065 // 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
1066 // 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
1067 // 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
1068 // 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
1069 // and let tree_index_expression::rvalue handle indexing.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1070 // 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
1071 // return the function definition as a value.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1072
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
1073 octave_function *fcn = nullptr;
23435
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 if (val.is_function ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1076 fcn = val.function_value (true);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1077
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1078 int nargout = m_nargout_stack.top ();
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 if (fcn && ! (expr.is_postfix_indexed ()
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
1081 && fcn->accepts_postfix_index (expr.postfix_index ())))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1082 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
1083 retval = fcn->call (*this, nargout);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1084 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1085 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1086 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1087 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
1088 && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1089 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1090 octave_value_list args = ovl (val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1091 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
1092 feval ("display", args);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1093 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1094
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1095 push_result (val);
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1096 return;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1097 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1098 }
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1099 else if (sym.is_added_static ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1100 expr.static_workspace_error ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1101 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1102 expr.eval_undefined_error ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1103
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1104 push_result (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1105 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1106
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1107 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1108 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
1109 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1110 panic_impossible ();
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1113 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1114 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
1115 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1116 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
1117 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1118 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
1119 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
1120 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
1121 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1122
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1123 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
1124
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1125 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1126 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
1127 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1128
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1129 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1130 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
1131 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1132 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
1133 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1134 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
1135
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1136 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
1137 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
1138
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1139 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
1140 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
1141
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1142 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
1143 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1144 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
1145
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1146 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
1147 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
1148
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
1149 break;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1150 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1151 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1152 }
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1153
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1154 // Final step of processing an indexing error. Add the name of the
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1155 // variable being indexed, if any, then issue an error. (Will this also
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1156 // be needed by pt-lvalue, which calls subsref?)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1157
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1158 static void
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1159 final_index_error (octave::index_exception& e,
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1160 const octave::tree_expression *expr)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1161 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1162 std::string extra_message;
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1163
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1164 // FIXME: make this a member function for direct access to symbol
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1165 // table and scope?
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1166
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1167 octave::symbol_scope scope
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1168 = octave::__require_current_scope__ ("final_index_error");
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1169
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1170 octave::symbol_record::context_id context = scope.current_context ();
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1171
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1172 if (expr->is_identifier ()
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1173 && dynamic_cast<const octave::tree_identifier *> (expr)->is_variable (context))
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1174 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1175 std::string var = expr->name ();
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1176
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1177 e.set_var (var);
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1178
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1179 octave::symbol_table& symtab = octave::__get_symbol_table__ ("final_index_error");
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1180
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1181 octave_value fcn = symtab.find_function (var);
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1182
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1183 if (fcn.is_function ())
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1184 {
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1185 octave_function *fp = fcn.function_value ();
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1186
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1187 if (fp && fp->name () == var)
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1188 extra_message = " (note: variable '" + var + "' shadows function)";
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1189 }
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1190 }
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1191
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1192 std::string msg = e.message () + extra_message;
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1193
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1194 error_with_id (e.err_id (), msg.c_str ());
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1195 }
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
1196
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1197 // 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
1198 // 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
1199 // 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
1200 // expressions like
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1201 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1202 // svd (rand (10))(1:5)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1203 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1204 // 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
1205 // 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
1206 // 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
1207 // 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
1208 // 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
1209 // 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
1210 // 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
1211 // 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
1212 // expression.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1213 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1214 // Steps:
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 // * 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
1217 // 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
1218 // 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
1219 // 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
1220 // 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
1221 // 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
1222 // without any additional arguments.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1223 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1224 // * 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
1225 // 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
1226 // 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
1227 // 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
1228 // 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
1229 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1230 // * 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
1231 // 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
1232 // 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
1233 // subsref call for that object.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1234 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1235 // 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
1236 // 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
1237 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1238 // 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
1239 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1240 // 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
1241 // 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
1242 // 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
1243 // expression may be evaluated.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1244 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1245 // 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
1246 // 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
1247 // 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
1248 // steps
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1249 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1250 // tmp = x.a
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1251 // tmp = tmp{end}
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1252 // tmp = tmp(2:end)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1253 // result = tmp.b
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1254 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1255 // 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
1256 // 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
1257 // 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
1258 // 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
1259 // series of steps
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1260 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1261 // base_expr = tmp = x.a
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1262 // tmp = base_expr{end}
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1263 // 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
1264 //
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1265 // 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
1266 // 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
1267
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1268 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1269 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
1270 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1271 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1272
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1273 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
1274
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1275 std::string type = idx_expr.type_tags ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1276 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
1277 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
1278 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
1279
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1280 assert (! args.empty ());
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1281
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1282 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
1283 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
1284 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
1285
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1286 int n = args.size ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1287 int beg = 0;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1288
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1289 octave_value base_expr_val;
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 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
1292
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1293 if (expr->is_identifier () && type[beg] == '(')
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1294 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1295 tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1296
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1297 symbol_scope scope = get_current_scope ();
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1298
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
1299 symbol_record::context_id context = scope.current_context ();
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
1300
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
1301 if (! id->is_variable (context))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1302 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1303 octave_value_list first_args;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1304
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1305 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
1306
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1307 if (al && al->length () > 0)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1308 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1309 // 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
1310 // ignored output arguments.
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1311
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1312 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1313
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
1314 m_lvalue_list_stack.push (nullptr);
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1315
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1316 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
1317 &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
1318
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1319 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
1320 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
1321 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
1322 }
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 octave_function *fcn = nullptr;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1325
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
1326 octave_value val = id->do_lookup (context, first_args);
23521
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 if (val.is_function ())
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1329 fcn = val.function_value (true);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1330
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1331 if (fcn)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1332 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1333 try
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1334 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
1335 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
1336 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1337 catch (index_exception& e)
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1338 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1339 final_index_error (e, expr);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1340 }
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1341
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1342 beg++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1343 p_args++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1344 p_arg_nm++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1345 p_dyn_field++;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1346
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1347 if (n > beg)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1348 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1349 // 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
1350 // extra output values.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1351
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1352 if (retval.length () == 0)
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1353 error ("indexing undefined value");
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1354 else
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1355 base_expr_val = retval(0);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1356 }
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1357 else
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1358 {
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1359 // 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
1360
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1361 push_result (retval);
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1362 return;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1363 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1364 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1365 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1366 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1367
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1368 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
1369 base_expr_val = evaluate (expr);
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1370
23781
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1371 // If we are indexing an object or looking at something like
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1372 //
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1373 // classname.static_function (args, ...);
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1374 //
23844
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1375 // then we'll just build a complete index list for one big subsref
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1376 // call. If the expression we are indexing is a classname then
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1377 // base_expr_val will be an octave_classdef_meta object. If we have
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1378 // files in a +packagename folder, they will also be an
23838
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23795
diff changeset
1379 // octave_classdef_meta object, but we don't want to index them.
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23795
diff changeset
1380
23844
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1381 bool indexing_object = (base_expr_val.isobject ()
23838
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23795
diff changeset
1382 || base_expr_val.isjava ()
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23795
diff changeset
1383 || (base_expr_val.is_classdef_meta ()
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23795
diff changeset
1384 && ! base_expr_val.is_package ()));
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1385
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1386 std::list<octave_value_list> idx;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1387
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1388 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
1389
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1390 for (int i = beg; i < n; i++)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1391 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1392 if (i > beg)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1393 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1394 tree_argument_list *al = *p_args;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1395
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1396 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
1397 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1398 // 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
1399 // pass to the END function.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1400
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1401 try
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1402 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1403 // Silently ignore extra output values.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1404
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1405 octave_value_list tmp_list
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1406 = base_expr_val.subsref (type.substr (beg, i-beg),
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1407 idx, nargout);
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1408
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1409 partial_expr_val
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1410 = tmp_list.length () ? tmp_list(0) : octave_value ();
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1411
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1412 if (! indexing_object)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1413 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1414 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
1415
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1416 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
1417 err_indexed_cs_list ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1418
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1419 retval = partial_expr_val;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1420
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1421 beg = i;
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1422 idx.clear ();
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1423
23781
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1424 if (partial_expr_val.isobject ()
24075
3645139bd28f allow meta.class.fromName to work again (bug #51935)
Piotr Held <pjheld@gmail.com>
parents: 24037
diff changeset
1425 || partial_expr_val.isjava ()
3645139bd28f allow meta.class.fromName to work again (bug #51935)
Piotr Held <pjheld@gmail.com>
parents: 24037
diff changeset
1426 || (partial_expr_val.is_classdef_meta ()
3645139bd28f allow meta.class.fromName to work again (bug #51935)
Piotr Held <pjheld@gmail.com>
parents: 24037
diff changeset
1427 && ! partial_expr_val.is_package ()))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1428 {
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1429 // 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
1430 // 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
1431 // call from this point on.
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1432
23781
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1433 // FIXME: is is also possible to have a
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1434 // static method call buried somewhere in
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1435 // the depths of a complex indexing
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1436 // expression so that we would also need to
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1437 // check for an octave_classdef_meta object
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1438 // here?
d891b6a16a4d * pt-eval.cc: Expand on comment introduced in previous change.
John W. Eaton <jwe@octave.org>
parents: 23780
diff changeset
1439
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1440 indexing_object = true;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1441 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1442 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1443 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
1444 catch (index_exception& e)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1445 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1446 final_index_error (e, expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1447 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1448 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1449 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1450
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1451 switch (type[i])
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1452 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1453 case '(':
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1454 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
1455 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1456
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1457 case '{':
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1458 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
1459 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1460
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1461 case '.':
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1462 idx.push_back (octave_value
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1463 (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
1464 break;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1465
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1466 default:
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1467 panic_impossible ();
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1470 p_args++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1471 p_arg_nm++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1472 p_dyn_field++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1473 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1474
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1475
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1476 // If ! idx.empty () that means we still have stuff to index otherwise
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1477 // they would have been dealt with and idx would have been emptied.
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1478 if (! idx.empty ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1479 {
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1480 // This is for +package and other classdef_meta objects
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1481 if (! base_expr_val.is_function ()
23844
ca4535a6ee9f * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 23843
diff changeset
1482 || base_expr_val.is_classdef_meta ())
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1483 {
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1484 try
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1485 {
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1486 retval = base_expr_val.subsref (type.substr (beg, n-beg),
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1487 idx, nargout);
23871
5352f632859b Fix (once more) pkg.fcn with no arguments (bug #51715).
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
1488 beg = n;
5352f632859b Fix (once more) pkg.fcn with no arguments (bug #51715).
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
1489 idx.clear ();
23876
b6e756d8f485 maint: eliminate TAB characters from source files
John W. Eaton <jwe@octave.org>
parents: 23872
diff changeset
1490 }
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1491 catch (octave::index_exception& e)
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1492 {
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1493 final_index_error (e, expr);
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1494 }
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1495 }
23872
9b39ec2e0952 revert unintended change to pt-eval.cc made in d56c18dc1373
John W. Eaton <jwe@octave.org>
parents: 23871
diff changeset
1496 else
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1497 {
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1498 // FIXME: we want this to only be a superclass constructor
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1499 // call Should we actually make a check for this or are all
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1500 // other types of calls already dealt with?
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1501
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1502 octave_function *fcn = base_expr_val.function_value ();
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1503
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1504 if (fcn)
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1505 {
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1506 try
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1507 {
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1508 retval = fcn->call (*this, nargout, idx);
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1509 }
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1510 catch (octave::index_exception& e)
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1511 {
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1512 final_index_error (e, expr);
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1513 }
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1514 }
23521
551fa3879615 improve compatibility and simplify evaluation of index expressions
John W. Eaton <jwe@octave.org>
parents: 23514
diff changeset
1515 }
23435
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
23842
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1518 // FIXME: when can the following happen? In what case does indexing
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1519 // result in a value that is a function? Classdef method calls?
ff893e26aeeb make calling parent class constructors work again (bug #51534)
Piotr Held <pjheld@gmail.com>
parents: 23838
diff changeset
1520 // Something else?
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1521
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1522 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
1523
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1524 if (val.is_function ())
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1525 {
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1526 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
1527
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1528 if (fcn)
23684
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1529 {
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1530 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
1531
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1532 if (! idx.empty ())
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1533 {
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1534 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
1535 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
1536
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1537 if (type[beg] != '(')
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1538 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
1539 type[beg]);
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1540
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1541 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
1542 }
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1543
c84328c2a6c7 handle remaining args (if any) in index expression (bug #51295)
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
1544 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
1545 }
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1546 }
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23671
diff changeset
1547
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1548 push_result (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1549 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1550
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1551 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1552 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
1553 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1554 octave_value retval = Matrix ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1555
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1556 bool all_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1557 bool all_sq_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1558 bool all_dq_strings_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1559 bool all_empty_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1560 bool all_real_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1561 bool any_sparse_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1562 bool any_class_p = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1563 bool frc_str_conv = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1564
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1565 tm_const tmp (expr, this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1566
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1567 if (tmp && ! tmp.empty ())
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 dim_vector dv = tmp.dims ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1570 all_strings_p = tmp.all_strings_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1571 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
1572 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
1573 all_empty_p = tmp.all_empty_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1574 all_real_p = tmp.all_real_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1575 any_sparse_p = tmp.any_sparse_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1576 any_class_p = tmp.any_class_p ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1577 frc_str_conv = tmp.some_strings_p ();
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 // Try to speed up the common cases.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1580
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1581 std::string result_type = tmp.class_name ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1582
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1583 if (any_class_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1584 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1585 retval = do_class_concat (tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1586 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1587 else if (result_type == "double")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1588 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1589 if (any_sparse_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1590 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1591 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1592 retval = do_single_type_concat<SparseMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1593 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1594 retval = do_single_type_concat<SparseComplexMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1595 }
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 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1598 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1599 retval = do_single_type_concat<NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1600 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1601 retval = do_single_type_concat<ComplexNDArray> (dv, 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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1604 else if (result_type == "single")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1605 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1606 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1607 retval = do_single_type_concat<FloatNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1608 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1609 retval = do_single_type_concat<FloatComplexNDArray> (dv, tmp);
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 else if (result_type == "char")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1612 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1613 char type = (all_dq_strings_p ? '"' : '\'');
23435
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 if (! all_strings_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1616 warn_implicit_conversion ("Octave:num-to-str",
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1617 "numeric", result_type);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1618 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1619 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
1620
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
1621 charNDArray result (dv, m_string_fill_char);
23435
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 single_type_concat<charNDArray> (result, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1624
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1625 retval = octave_value (result, type);
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 else if (result_type == "logical")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1628 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1629 if (any_sparse_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1630 retval = do_single_type_concat<SparseBoolMatrix> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1631 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1632 retval = do_single_type_concat<boolNDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1633 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1634 else if (result_type == "int8")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1635 retval = do_single_type_concat<int8NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1636 else if (result_type == "int16")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1637 retval = do_single_type_concat<int16NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1638 else if (result_type == "int32")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1639 retval = do_single_type_concat<int32NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1640 else if (result_type == "int64")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1641 retval = do_single_type_concat<int64NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1642 else if (result_type == "uint8")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1643 retval = do_single_type_concat<uint8NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1644 else if (result_type == "uint16")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1645 retval = do_single_type_concat<uint16NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1646 else if (result_type == "uint32")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1647 retval = do_single_type_concat<uint32NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1648 else if (result_type == "uint64")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1649 retval = do_single_type_concat<uint64NDArray> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1650 else if (result_type == "cell")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1651 retval = do_single_type_concat<Cell> (dv, tmp);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1652 else if (result_type == "struct")
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1653 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
1654 else
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 // 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
1657 // 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
1658 // 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
1659 // 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
1660 // 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
1661 // 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
1662 // 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
1663 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1664 // 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
1665 //
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1666 // ctmp = octave::type_info::lookup_type
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1667 // (tmp.begin() -> begin() -> type_name());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1668 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1669 // 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
1670 // 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
1671 // be avoided.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1672
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1673 octave_value ctmp;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1674
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1675 // Find the first non-empty object
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1676
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1677 if (any_sparse_p)
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 // 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
1680 // 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
1681 if (all_real_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1682 ctmp = octave_sparse_matrix ().resize (dv);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1683 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1684 ctmp = octave_sparse_complex_matrix ().resize (dv);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1685 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1686 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1687 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1688 for (tm_row_const& row : tmp)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1689 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1690 octave_quit ();
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 for (auto& elt : row)
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 octave_quit ();
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 ctmp = elt;
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 if (! ctmp.all_zero_dims ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1699 goto found_non_empty;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1700 }
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1703 ctmp = (*(tmp.begin () -> begin ()));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1704
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1705 found_non_empty:
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 if (! all_empty_p)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1708 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
1709 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1710
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1711 // 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
1712 // insert them in the result matrix.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1713
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
1714 type_info& ti = m_interpreter.get_type_info ();
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
1715
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1716 int dv_len = dv.ndims ();
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1717 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
1718 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
1719
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1720 for (tm_row_const& row : tmp)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1721 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1722 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1723
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1724 for (auto& elt : row)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1725 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1726 octave_quit ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1727
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1728 if (elt.isempty ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1729 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1730
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
1731 ctmp = do_cat_op (ti, ctmp, elt, ra_idx);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1732
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1733 ra_idx (1) += elt.columns ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1734 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1735
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1736 ra_idx (0) += row.rows ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1737 ra_idx (1) = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1738 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1739
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1740 retval = ctmp;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1741
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1742 if (frc_str_conv && ! retval.is_string ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1743 retval = retval.convert_to_str ();
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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1746
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1747 push_result (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1748 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1749
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1750 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1751 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
1752 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1753 octave_value retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1754
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1755 // 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
1756 // output arguments.
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1757
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1758 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1759
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
1760 m_lvalue_list_stack.push (nullptr);
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1761
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
1762 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
1763 &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
1764
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1765 octave_idx_type nr = expr.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1766 octave_idx_type nc = -1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1767
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1768 Cell val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1769
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1770 octave_idx_type i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1771
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1772 for (tree_argument_list *elt : expr)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1773 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1774 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
1775
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1776 if (nr == 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1777 // Optimize the single row case.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1778 val = row.cell_value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1779 else if (nc < 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1780 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1781 nc = row.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1782
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1783 val = Cell (nr, nc);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1784 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1785 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1786 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1787 octave_idx_type this_nc = row.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1788
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1789 if (this_nc != nc)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1790 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1791 if (this_nc == 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1792 continue; // blank line
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1793 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1794 error ("number of columns must match");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1795 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1796 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1797
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1798 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
1799 val(i,j) = row(j);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1800
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1801 i++;
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1804 if (i < nr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1805 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
1806
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1807 retval = val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1808
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1809 push_result (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1810 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1811
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1812 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1813 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
1814 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1815 octave_value_list val;
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 tree_expression *rhs = expr.right_hand_side ();
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 if (rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1820 {
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1821 unwind_protect frame;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1822
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1823 tree_argument_list *lhs = expr.left_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1824
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1825 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
1826
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1827 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
1828
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
1829 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
1830 &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
1831
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1832 octave_idx_type n_out = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1833
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1834 for (const auto& lval : lvalue_list)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1835 n_out += lval.numel ();
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 // 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
1838 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
1839 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
1840 && rhs_val1(0).is_cs_list ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1841 ? rhs_val1(0).list_value ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1842 : rhs_val1);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1843
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1844 octave_idx_type k = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1845
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1846 octave_idx_type n = rhs_val.length ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1847
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1848 // 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
1849 // postpone joining the final values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1850 std::list<octave_value_list> retval_list;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1851
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1852 tree_argument_list::iterator q = lhs->begin ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1853
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1854 for (octave_lvalue ult : lvalue_list)
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 tree_expression *lhs_elt = *q++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1857
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1858 octave_idx_type nel = ult.numel ();
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 if (nel != 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1861 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1862 // 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
1863 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1864 // [varargout{1:nargout}] = fcn (args);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1865 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1866 // 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
1867 // 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
1868 // 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
1869 // been defined. See also bug #43813.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1870
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1871 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
1872 && ! ult.is_black_hole () && ult.is_undefined ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1873 && ult.index_type () == "{" && ult.index_is_empty ())
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 // 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
1876 // 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
1877 // handle a single output.
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 nel = 1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1880
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1881 ult.define (Cell (1, 1));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1882
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1883 ult.clear_index ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1884 std::list<octave_value_list> idx;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1885 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
1886 ult.set_index ("{", idx);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1887 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1888
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1889 if (k + nel > n)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1890 error ("some elements undefined in return list");
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1891
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1892 // This element of the return list expects a
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1893 // comma-separated list of values. Slicing avoids
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1894 // copying.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1895
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1896 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
1897
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1898 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
1899
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1900 retval_list.push_back (ovl);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1901
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1902 k += nel;
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 else
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 if (k < n)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1907 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1908 if (ult.is_black_hole ())
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 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1911 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1912 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1913 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1914 {
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1915 octave_value tmp = rhs_val(k);
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1917 if (tmp.is_undefined ())
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1918 error ("element number %d undefined in return list",
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1919 k+1);
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1920
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1921 ult.assign (octave_value::op_asn_eq, tmp);
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1922
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1923 retval_list.push_back (tmp);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1924
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1925 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1926 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1927 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1928 else
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 // This can happen for a function like
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 // function varargout = f ()
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1933 // varargout{1} = nargout;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1934 // endfunction
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 // called with
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1937 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1938 // [a, ~] = f ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1939 //
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1940 // 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
1941 // 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
1942 // 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
1943 // don't need is missing from the list.
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 if (! ult.is_black_hole ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1946 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
1947
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1948 k++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1949 continue;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1950 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1951 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1952
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
1953 if (expr.print_result () && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1954 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1955 // 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
1956 // the new value of the referenced object below,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1957 // instead of the indexed value (which should be
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1958 // the same as the right hand side value).
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 ult.clear_index ();
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 octave_value lhs_val = ult.value ();
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_list args = ovl (lhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1965 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
1966 feval ("display", args);
23435
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 }
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 // Concatenate return values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1971 val = retval_list;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1972 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1973
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1974 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1975 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
1976
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1977 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1978 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
1979 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1980 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
1981 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1982 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
1983 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
1984 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
1985 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1986
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1987 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
1988 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
1989 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1990
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1991 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1992 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
1993 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1994 int nargout = m_nargout_stack.top ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1995
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1996 if (nargout > 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1997 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
1998
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
1999 push_result (expr.value ());
23435
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
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2002 void
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2003 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
2004 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2005 std::string nm = expr.name ();
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_value fh = make_fcn_handle (nm);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2008
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2009 push_result (fh);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2010 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2011
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2012 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2013 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
2014 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2015 octave_value_list retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2016
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2017 octave_value fcn = expr.function ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2018
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2019 octave_value_list args = expr.arguments ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2020
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2021 int nargout = m_nargout_stack.top ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2022
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2023 retval = feval (fcn.function_value (), args, nargout);
23435
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 if (retval.length () == 1 && retval(0).is_function ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2026 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2027 // 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
2028 // 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
2029 // used for superclass references in classdef.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2030
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2031 octave_value val = retval(0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2032 octave_function *f = val.function_value (true);
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 if (f && ! (expr.is_postfix_indexed ()
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
2035 && f->accepts_postfix_index (expr.postfix_index ())))
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2036 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23523
diff changeset
2037 retval = f->call (*this, nargout);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2038 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2039 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2040
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2041 push_result (retval);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2042 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2043
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2044 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2045 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
2046 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2047 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2048 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2049
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2050 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2051 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
2052 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2053 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2054
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2055 tree_expression *op = expr.operand ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2056
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2057 if (op)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2058 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2059 octave_value::unary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2060
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2061 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
2062 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2063 octave_lvalue ref = op->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2064
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2065 val = ref.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2066
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2067 profiler::enter<tree_postfix_expression> block (m_profiler, expr);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2068
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2069 ref.do_unary_op (etype);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2070 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2071 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2072 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2073 octave_value op_val = evaluate (op);
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 if (op_val.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2076 {
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2077 profiler::enter<tree_postfix_expression>
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2078 block (m_profiler, expr);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2079
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2080 type_info& ti = m_interpreter.get_type_info ();
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2081
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2082 val = ::do_unary_op (ti, etype, op_val);
23435
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 }
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
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2087 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2088 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2089
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2090 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2091 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
2092 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2093 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2094
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2095 tree_expression *op = expr.operand ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2096
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2097 if (op)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2098 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2099 octave_value::unary_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2100
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2101 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
2102 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2103 octave_lvalue op_ref = op->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2104
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2105 profiler::enter<tree_prefix_expression> block (m_profiler, expr);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2106
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2107 op_ref.do_unary_op (etype);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2108
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2109 val = op_ref.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2110 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2111 else
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 op_val = evaluate (op);
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 if (op_val.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2116 {
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2117 profiler::enter<tree_prefix_expression>
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23729
diff changeset
2118 block (m_profiler, expr);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2119
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2120 // 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
2121 // (a temporary expression).
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2122 if (op_val.get_count () == 1)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2123 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
2124 else
24565
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2125 {
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2126 type_info& ti = m_interpreter.get_type_info ();
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2127
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2128 val = ::do_unary_op (ti, etype, op_val);
dbec1e04f499 accept type_info obj as arg to binary_op, unary_op, and cat_op functions
John W. Eaton <jwe@octave.org>
parents: 24564
diff changeset
2129 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2130 }
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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2133
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2134 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2135 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2136
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2137 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2138 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
2139 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2140 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
2141 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2142 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
2143 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
2144 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
2145 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2146
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2147 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
2148 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
2149
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2150 // 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
2151
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2152 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
2153 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2154 Vdebugging = false;
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 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
2157 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2158 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
2159 || 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
2160 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
2161 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2162
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2163 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2164 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
2165 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2166 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2167 }
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 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2170 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
2171 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2172 octave_value val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2173
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2174 tree_expression *rhs = expr.right_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2175
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2176 if (rhs)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2177 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2178 octave_value rhs_val = evaluate (rhs);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2179
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2180 if (rhs_val.is_undefined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2181 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
2182
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2183 if (rhs_val.is_cs_list ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2184 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2185 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
2186
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2187 if (lst.empty ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2188 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
2189
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2190 rhs_val = lst(0);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2191 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2192
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2193 tree_expression *lhs = expr.left_hand_side ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2194
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2195 try
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2196 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2197 unwind_protect frame;
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2198
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2199 octave_lvalue ult = lhs->lvalue (this);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2200
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2201 std::list<octave_lvalue> lvalue_list;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2202 lvalue_list.push_back (ult);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2203
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2204 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
2205
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2206 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
2207 &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
2208
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2209 if (ult.numel () != 1)
24690
2ce26c4cb323 More descriptive error message for assignment to empty structure (bug #36003).
Joe Winegarden <joewino19@gmail.com>
parents: 24583
diff changeset
2210 err_invalid_structure_assignment ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2211
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2212 octave_value::assign_op etype = expr.op_type ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2213
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2214 ult.assign (etype, rhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2215
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2216 if (etype == octave_value::op_asn_eq)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2217 val = rhs_val;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2218 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2219 val = ult.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2220
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2221 if (expr.print_result () && statement_printing_enabled ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2222 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2223 // 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
2224 // get the new value of the referenced
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2225 // object below, instead of the indexed
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2226 // value (which should be the same as the
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2227 // right hand side value).
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2228
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2229 ult.clear_index ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2230
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2231 octave_value lhs_val = ult.value ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2232
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2233 octave_value_list args = ovl (lhs_val);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2234 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
2235 feval ("display", args);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2236 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2237 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2238 catch (index_exception& e)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2239 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2240 e.set_var (lhs->name ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2241 std::string msg = e.message ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2242 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
2243 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2244 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2245
24563
8f2c479eb125 eliminate unnecessary value stack in evaluator
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2246 push_result (val);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2247 }
8662
af72c8137d64 improve looping over arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 8658
diff changeset
2248
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2249 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2250 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
2251 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2252 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
2253 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
2254
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2255 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
2256 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2257 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
2258 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2259 // 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
2260 // 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
2261
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2262 if (Vtrack_line_num)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2263 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
2264 }
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 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2267 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2268 if (cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2269 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
2270 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2271 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2272 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
2273 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2274 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
2275 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
2276 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
2277 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2278
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2279 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
2280 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
2281
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2282 // 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
2283 // 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
2284 // 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
2285 // 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
2286
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2287 // 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
2288 // 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
2289 // 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
2290
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2291 octave_value tmp_result = evaluate (expr, 0);
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2292
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2293 if (tmp_result.is_defined ())
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2294 {
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2295 bool do_bind_ans = false;
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2296
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2297 if (expr->is_identifier ())
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2298 {
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2299 symbol_scope scope = get_current_scope ();
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2300
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2301 symbol_record::context_id context
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2302 = scope.current_context ();
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2303
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2304 tree_identifier *id
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2305 = dynamic_cast<tree_identifier *> (expr);
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2306
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2307 do_bind_ans = (! id->is_variable (context));
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2308 }
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2309 else
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2310 do_bind_ans = (! expr->is_assignment_expression ());
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2311
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2312 if (do_bind_ans)
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2313 bind_ans (tmp_result, expr->print_result ()
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2314 && statement_printing_enabled ());
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2315 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2316 }
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 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
2319 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2320 // 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
2321 // 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
2322 // 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
2323 // 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
2324
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2325 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
2326 "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
2327 }
24583
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2328 catch (const octave::interrupt_exception&)
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2329 {
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2330 // If we are debugging, then continue with next statement.
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2331 // Otherwise, jump out of here.
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2332
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2333 if (debug_mode)
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2334 interpreter::recover_from_exception ();
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2335 else
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2336 throw;
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2337 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2338 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2339 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2340
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2341 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2342 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
2343 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2344 // 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
2345 // 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
2346
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2347 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
2348
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2349 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
2350 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2351 while (true)
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 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
2354
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2355 if (! elt)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2356 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
2357
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2358 octave_quit ();
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 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
2361
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2362 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
2363 || 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
2364 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2365
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2366 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
2367 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2368
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2369 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
2370 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2371 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2372 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2373 // 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
2374 // 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
2375 // 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
2376 // 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
2377 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2378 // 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
2379 // # 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
2380 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2381 // 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
2382 // # 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
2383 // # 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
2384 // # 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
2385
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2386 // 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
2387 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2388 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2389 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2390 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2391
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2392 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2393 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
2394 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2395 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2396 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2397
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2398 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2399 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
2400 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2401 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2402 }
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 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2405 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
2406 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2407 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
2408 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2409 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
2410 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
2411 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
2412 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2413
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2414 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
2415 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
2416
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2417 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
2418
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2419 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2420 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
2421 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
2422
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2423 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
2424
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2425 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
2426
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2427 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2428 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
2429 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
2430 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2431 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
2432 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2433 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
2434
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2435 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
2436 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
2437
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2438 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2439 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2440 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2441 }
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2444 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2445 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
2446 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2447 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
2448 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2449 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
2450 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
2451 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
2452 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2453
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2454 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
2455
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2456 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2457 // 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
2458 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
2459
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2460 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
2461 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
2462 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
2463
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2464 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
2465 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
2466 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
2467
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2468 // 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
2469 // 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
2470
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2471 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
2472
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2473 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
2474 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2475 try
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2476 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2477 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
2478 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
2479 in_try_catch--;
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2480 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2481 catch (const execution_exception&)
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2482 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2483 interpreter::recover_from_exception ();
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
2484
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2485 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
2486 execution_error = true;
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2487 }
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2488 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2489 // 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
2490 // 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
2491 // or throw further errors.
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2492 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2493
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2494 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
2495 {
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 *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
2497 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
2498 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2499 tree_identifier *expr_id = cmd.identifier ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2500
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2501 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
2502 {
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24352
diff changeset
2503 octave_lvalue 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
2504
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2505 octave_scalar_map err;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2506
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2507 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
2508 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
2509 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
2510
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2511 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
2512 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
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 // 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
2515 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
2516 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
2517 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2518 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2519 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2520
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2521 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2522 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
2523 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2524 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
2525
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2526 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
2527 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
2528
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2529 // 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
2530 // backtracking.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2531
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2532 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
2533 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
2534 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
2535 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
2536
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2537 // 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
2538 // 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
2539 // 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
2540 // 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
2541
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2542 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
2543 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
2544
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2545 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
2546 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
2547
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2548 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2549 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2550 if (list)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2551 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
2552 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2553 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
2554 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2555 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
2556
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2557 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
2558 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
2559 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2560 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
2561
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2562 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
2563
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2564 throw;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2565 }
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
2566
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2567 // 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
2568 // 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
2569
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2570 // 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
2571 // 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
2572 // 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
2573 // 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
2574 // 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
2575 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2576 // function foo ()
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2577 // unwind_protect
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2578 // 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
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 // 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
2581 // 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
2582 // 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
2583 // return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2584 // 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
2585 // 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
2586 // endfunction
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2587 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2588 // 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
2589 // 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
2590 // 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
2591 // 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
2592 // 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
2593
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2594 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
2595 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
2596 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2597 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
2598 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2599
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2600 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2601 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
2602 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2603 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
2604 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2605 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
2606 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
2607 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
2608 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2609
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2610 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
2611
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2612 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
2613
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2614 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
2615 {
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2616 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
2617 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2618 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
2619 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2620 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
2621 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2622 // 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
2623 // 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
2624 // 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
2625 // here?
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2626 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
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 // 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
2629 // 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
2630 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
2631
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2632 // 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
2633 // 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
2634 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
2635 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2636 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
2637 {
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2638 // 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
2639 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
2640 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
2641 throw;
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
2642 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2643
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2644 // 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
2645 // 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
2646 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
2647 }
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
2648 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2649
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2650 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2651 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
2652 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2653 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
2654
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2655 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
2656 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2657 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
2658 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2659 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2660
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2661 #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
2662 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
2663 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2664 #endif
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9378
diff changeset
2665
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2666 unwind_protect frame;
10210
752f349052a2 ensure correct backtraces after error in unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 10194
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 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
2669
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2670 in_loop_command = true;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2671
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2672 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
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 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2675 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2676
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2677 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2678 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2679 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
2680 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
2681
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2682 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
2683 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
2684
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2685 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
2686 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2687 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
2688
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2689 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
2690 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2691
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2692 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
2693 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2694 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2695 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2696 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2697 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2698 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
2699
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2700 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2701 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
2702 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2703 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
2704
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2705 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
2706 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2707 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
2708 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2709 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2710
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
2711 #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
2712 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
2713 return;
15023
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2714 #endif
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
2715
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2716 unwind_protect frame;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2717
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2718 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
2719
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2720 in_loop_command = true;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2721
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2722 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
2723 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
2724 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
2725
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2726 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2727 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
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 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2730 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2731 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
2732 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
2733
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2734 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
2735
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2736 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
2737 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2738
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2739 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
2740 break;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2741
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2742 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
2743 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
2744
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2745 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
2746
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2747 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
2748 break;
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 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2751
23702
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2752 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
2753 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2754 static std::string ans = "ans";
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2755
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2756 if (val.is_defined ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2757 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2758 if (val.is_cs_list ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2759 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2760 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
2761
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2762 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
2763 bind_ans (lst(i), print);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2764 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2765 else
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2766 {
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
2767 symbol_scope scope = get_current_scope ();
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
2768
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
2769 scope.force_assign (ans, val);
23702
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2770
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2771 if (print)
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2772 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2773 octave_value_list args = ovl (val);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2774 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
2775 feval ("display", args);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2776 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2777 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2778 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2779 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
2780
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2781 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2782 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
2783 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2784 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
2785 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
2786
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2787 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2788 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
2789 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
2790 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2791 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
2792
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2793 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
2794 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2795 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
2796
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2797 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
2798
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2799 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
2800 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2801 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
2802 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2803 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
2804
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2805 dbstep_flag = 0;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2806
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2807 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
2808 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2809 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
2810 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2811 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
2812 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2813 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
2814 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2815 // 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
2816 // 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
2817 // 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
2818 // 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
2819 // return to prompt.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2820
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2821 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
2822
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2823 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
2824 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2825 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2826 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2827 // 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
2828
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2829 dbstep_flag--;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2830 }
15574
d20cbfec6df7 Fix off-by-1 error when executing 'dbstep N'
Rik <rik@octave.org>
parents: 15469
diff changeset
2831
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2832 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2833 else if (dbstep_flag == 1
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2834 && 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
2835 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2836 // 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
2837
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2838 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
2839
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2840 break_on_this_statement = true;
15574
d20cbfec6df7 Fix off-by-1 error when executing 'dbstep N'
Rik <rik@octave.org>
parents: 15469
diff changeset
2841
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2842 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
2843 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2844 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2845 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
2846 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2847 // 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
2848
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2849 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
2850
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2851 dbstep_flag = 0;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2852
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2853 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
2854 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2855 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
2856 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2857 // 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
2858 // 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
2859 // 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
2860 // "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
2861 // that frame.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2862
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2863 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
2864 && 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
2865 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
2866 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2867
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2868 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
2869 do_keyboard ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2870
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2871 }
10219
979fb2606c4f new tree_evaluator::do_keyoard function
Ryan Rusaw <rrusaw@gmail.com>
parents: 10210
diff changeset
2872
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2873 // 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
2874 // 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
2875 // 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
2876
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2877 octave_value
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2878 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
2879 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2880 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
2881 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2882
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2883 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2884 tree_evaluator::is_logically_true (tree_expression *expr,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2885 const char *warn_for)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2886 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2887 bool expr_value = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2888
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2889 octave_value t1 = evaluate (expr);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2890
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2891 if (t1.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2892 return t1.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2893 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2894 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
2895
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2896 return expr_value;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2897 }
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2898
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2899 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
2900 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
2901 const string_vector& arg_nm,
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2902 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
2903 {
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2904 octave_value_list retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2905
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2906 if (args)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2907 {
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2908 // 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
2909 // output arguments.
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2910
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2911 unwind_protect frame;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2912
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23781
diff changeset
2913 m_lvalue_list_stack.push (nullptr);
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2914
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2915 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
2916 &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
2917
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2918 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
2919 && object->is_undefined ())
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2920 err_invalid_inquiry_subscript ();
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2921
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2922 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
2923 }
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2924
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2925 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
2926
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2927 if (n > 0)
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2928 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
2929
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2930 return retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2931 }
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
2932
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2933 std::list<octave_lvalue>
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2934 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
2935 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2936 std::list<octave_lvalue> retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2937
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2938 for (tree_expression *elt : *lhs)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2939 retval.push_back (elt->lvalue (this));
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2940
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2941 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
2942 }
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2943
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2944 octave_value
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2945 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
2946 int nargout)
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2947 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2948 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
2949 "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
2950 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2951
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2952 octave_value
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2953 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
2954 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2955 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
2956 "silent_functions");
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
2957 }
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
2958
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2959 octave_value
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2960 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
2961 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2962 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
2963 "string_fill_char");
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2964 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2965
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2966 void
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2967 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
2968 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
2969 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2970 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2971 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
2972
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2973 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
2974 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2975
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2976 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2977 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
2978 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2979 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2980 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
2981 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
2982 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
2983 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2984
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2985 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2986 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
2987 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2988 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
2989
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2990 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
2991 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2992 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
2993
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2994 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
2995
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2996 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
2997
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
2998 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
2999
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3000 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
3001 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3002 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3003
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3004 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3005 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
3006 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3007 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
3008 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
3009
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3010 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
3011 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
3012
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3013 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
3014 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
3015 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3016
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3017 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
3018 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3019 // 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
3020 // 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
3021 // 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
3022 // 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
3023
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3024 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
3025
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3026 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
3027 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3028 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
3029
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3030 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
3031
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3032 if (frame)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3033 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3034 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
3035 return true;
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3036 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3037 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3038
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3039 return false;
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3040 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3041
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3042
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3043 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3044 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
3045 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3046 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
3047
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3048 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
3049
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3050 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
3051 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3052 case 0:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3053 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
3054 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3055 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
3056 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
3057 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3058 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3059 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
3060 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3061
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3062 case 1:
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 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
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 (arg0 == "on")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3067 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
3068 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
3069 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
3070 else
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 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
3073 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
3074
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3075 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
3076 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
3077
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3078 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
3079 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3080 // 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
3081 // 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
3082
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3083 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
3084 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3085 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3086 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3087 // 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
3088
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3089 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
3090
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3091 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
3092 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3093 // 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
3094
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3095 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
3096 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
3097 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3098 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3099 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3100 // 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
3101 // 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
3102
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3103 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
3104 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3105 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3106 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3107 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3108 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3109
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3110 case 2:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3111 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3112 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
3113 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
3114
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3115 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
3116 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
3117
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3118 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
3119 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3120 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
3121 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3122 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
3123 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
3124 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3125 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3126 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3127 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
3128 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
3129
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3130 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
3131 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
3132
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3133 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
3134 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
3135 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3136 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3137 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
3138 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3139 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
3140 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3141 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
3142 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
3143 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3144 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3145 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3146 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
3147 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
3148
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3149 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
3150 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
3151
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3152 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
3153 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3154 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3155 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3156 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3157 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3158 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3159
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3160 default:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3161 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3162 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3163 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3164
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3165 if (cleanup_pushed)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3166 maybe_set_echo_state ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3167
23913
062ce545b21e mark octave_value from octave_value_list constructor explicit
John W. Eaton <jwe@octave.org>
parents: 23876
diff changeset
3168 return octave_value ();
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3169 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3170
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3171 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3172 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
3173 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3174 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
3175 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3176
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3177 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
3178 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3179 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
3180 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3181 // 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
3182 return true;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3183 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3184
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3185 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
3186 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3187 // 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
3188 // 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
3189
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3190 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
3191
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3192 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
3193 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3194 // 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
3195 // file.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3196
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3197 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
3198 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3199 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3200 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3201 // 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
3202
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3203 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
3204 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3205 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3206
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3207 return false;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3208 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3209
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3210 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
3211 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3212 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
3213
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3214 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
3215
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3216 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
3217 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3218 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
3219
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3220 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
3221
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3222 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
3223 = 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
3224
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3225 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
3226 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
3227 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3228 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3229 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3230
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3231 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
3232 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
3233 @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
3234 @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
3235 @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
3236 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
3237 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
3238
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3239 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
3240 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
3241
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3242 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
3243 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
3244 The original variable value is restored when exiting the function.
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24738
diff changeset
3245
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24738
diff changeset
3246 @seealso{max_stack_depth}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3247 @end deftypefn */)
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3248 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3249 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
3250
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3251 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
3252 }
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3253
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3254 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3255 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3256 %! 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
3257 %! 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
3258 %! 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
3259 %! 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
3260 %! 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
3261 %! 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
3262
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3263 %!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
3264 */
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3265
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3266 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
3267 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
3268 @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
3269 @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
3270 @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
3271 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
3272 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
3273
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3274 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
3275 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
3276 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
3277
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3278 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
3279 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
3280 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
3281 @end deftypefn */)
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3282 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3283 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
3284
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3285 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
3286 }
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3287
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3288 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3289 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3290 %! orig_val = silent_functions ();
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3291 %! 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
3292 %! 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
3293 %! 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
3294 %! silent_functions (orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3295 %! 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
3296
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3297 %!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
3298 */
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3299
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3300 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
3301 doc: /* -*- texinfo -*-
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3302 @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
3303 @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
3304 @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
3305 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
3306 matrix to the same length.
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3307
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3308 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
3309 single space). For example:
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3310
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3311 @example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3312 @group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3313 string_fill_char ("X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3314 [ "these"; "are"; "strings" ]
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3315 @result{} "theseXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3316 "areXXXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3317 "strings"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3318 @end group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3319 @end example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3320
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3321 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
3322 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
3323 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
3324 @end deftypefn */)
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3325 {
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3326 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
3327
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3328 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
3329 }
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3330
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3331 /*
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3332 ## 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
3333 ## 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
3334 %!shared orig_val, old_val
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3335 %! orig_val = string_fill_char ();
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3336 %! 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
3337 %!test
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3338 %! assert (orig_val, old_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3339 %! assert (string_fill_char (), "X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3340 %! 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
3341 %! string_fill_char (orig_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3342 %! 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
3343
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3344 %!assert ( [ [], {1} ], {1} )
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3345
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3346 %!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
3347 */
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3348
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3349 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
3350 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3351 @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
3352 @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
3353 @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
3354 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
3355 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
3356
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3357 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
3358 @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
3359
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3360 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
3361 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
3362 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
3363 @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
3364 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3365 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3366 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
3367
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3368 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
3369 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3370
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3371 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
3372 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3373 @deftypefn {} {} echo
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3374 @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
3375 @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
3376 @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
3377 @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
3378 @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
3379 @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
3380 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
3381
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3382 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
3383
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3384 @table @code
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3385 @item on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3386 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
3387
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3388 @item off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3389 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
3390
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3391 @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
3392 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
3393 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3394
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3395 @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
3396 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
3397 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3398
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3399 @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
3400 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
3401
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3402 @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
3403 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
3404 @end table
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3405
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3406 @noindent
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3407 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
3408
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3409 @seealso{PS4}
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3410 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3411 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3412 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
3413
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3414 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
3415 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3416
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3417 /*
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3418 %!error echo ([])
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3419 %!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
3420 %!error echo ("")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3421 %!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
3422 %!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
3423 %!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
3424 %!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
3425 */