annotate libinterp/parse-tree/pt-eval.cc @ 27761:223981108144

fix stack frame location info when using debugger (bug #57315) * pt-eval.cc (tree_evaluator::visit_statement, tree_evaluator::visit_if_command_list): Set current location in call stack when when in debug repl or when current frame is different from debug frame instead of when m_statement_context is SC_FUNCTION or SC_SCRIPT.
author John W. Eaton <jwe@octave.org>
date Fri, 29 Nov 2019 15:42:34 -0600
parents 6388a240de87
children d8c53771645c
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
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26179
diff changeset
3 Copyright (C) 2009-2019 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>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25407
diff changeset
30 #include <list>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25407
diff changeset
31 #include <string>
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
33 #include "cmd-edit.h"
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
34 #include "file-ops.h"
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
35 #include "file-stat.h"
27100
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
36 #include "lo-ieee.h"
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
37 #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
38
23137
334119c390b3 move bp_table class to separate file
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
39 #include "bp-table.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
40 #include "call-stack.h"
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
41 #include "cdef-manager.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "defun.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #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
44 #include "errwarn.h"
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
45 #include "event-manager.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include "input.h"
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
47 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
48 #include "interpreter.h"
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
49 #include "octave.h"
26769
2f847e3e8d6b split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents: 26718
diff changeset
50 #include "ov-classdef.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 #include "ov-fcn-handle.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 #include "ov-usr-fcn.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
53 #include "ov-re-sparse.h"
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
54 #include "ov-cx-sparse.h"
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
55 #include "parse.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
56 #include "profiler.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 #include "pt-all.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
58 #include "pt-anon-scopes.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 #include "pt-eval.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
60 #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
61 #include "symtab.h"
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 #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
63 #include "utils.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
64 #include "variables.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
14899
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents: 14429
diff changeset
66 //FIXME: This should be part of tree_evaluator
f25d2224fa02 Initial JIT support
Max Brister <max@2bass.com>
parents: 14429
diff changeset
67 #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
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 namespace octave
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
71 // Normal evaluator.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
73 class quit_debug_exception
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
74 {
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
75 public:
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
76
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
77 quit_debug_exception (bool all = false) : m_all (all) { }
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
78
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
79 quit_debug_exception (const quit_debug_exception&) = default;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
80
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
81 quit_debug_exception& operator = (const quit_debug_exception&) = default;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
82
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
83 ~quit_debug_exception (void) = default;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
84
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
85 bool all (void) const { return m_all; }
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
86
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
87 private:
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
88
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
89 bool m_all;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
90 };
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
91
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
92 class debugger
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
93 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
94 public:
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
95
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
96 enum execution_mode
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
97 {
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
98 EX_NORMAL = 0,
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
99 EX_CONTINUE = 1,
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
100 EX_QUIT = 2,
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
101 EX_QUIT_ALL = 3
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
102 };
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
103
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
104 debugger (interpreter& interp, size_t level)
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
105 : m_interpreter (interp), m_level (level), m_debug_frame (0),
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
106 m_execution_mode (EX_NORMAL), m_in_debug_repl (false)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
107 { }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
108
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
109 void repl (const std::string& prompt = "debug> ");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
110
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
111 bool in_debug_repl (void) const { return m_in_debug_repl; }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
112
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
113 void dbcont (void)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
114 {
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
115 m_execution_mode = EX_CONTINUE;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
116 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
117
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
118 void dbquit (bool all = false)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
119 {
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
120 if (all)
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
121 m_execution_mode = EX_QUIT_ALL;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
122 else
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
123 m_execution_mode = EX_QUIT;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
124 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
125
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
126 bool quitting_debugger (void) const;
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
127
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
128 private:
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
129
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
130 interpreter& m_interpreter;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
131
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
132 size_t m_level;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
133 size_t m_debug_frame;
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
134 execution_mode m_execution_mode;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
135 bool m_in_debug_repl;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
136 };
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
137
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
138 void debugger::repl (const std::string& prompt_arg)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
139 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
140 unwind_protect frame;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
141
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
142 frame.protect_var (m_in_debug_repl);
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
143 frame.protect_var (m_execution_mode);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
144
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
145 m_in_debug_repl = true;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
146
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
147 tree_evaluator& tw = m_interpreter.get_evaluator ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
148
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
149 bool silent = tw.quiet_breakpoint_flag (false);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
150
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
151 frame.add_method (tw, &tree_evaluator::restore_frame,
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
152 tw.current_call_stack_frame_number ());
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
153
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
154 tw.goto_frame (tw.debug_frame ());
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
155
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
156 octave_user_code *caller = tw.current_user_code ();
27392
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
157 std::string fcn_file_nm, fcn_nm;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
158
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
159 if (caller)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
160 {
27392
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
161 fcn_file_nm = caller->fcn_file_name ();
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
162 fcn_nm = fcn_file_nm.empty () ? caller->name () : fcn_file_nm;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
163 }
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
164
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
165 int curr_debug_line = tw.current_line ();
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
166
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
167 std::ostringstream buf;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
168
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
169 input_system& input_sys = m_interpreter.get_input_system ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
170
27392
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
171 if (! fcn_nm.empty ())
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
172 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
173 if (input_sys.gud_mode ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
174 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
175 static char ctrl_z = 'Z' & 0x1f;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
176
27392
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
177 buf << ctrl_z << ctrl_z << fcn_nm << ':' << curr_debug_line;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
178 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
179 else
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
180 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
181 // FIXME: we should come up with a clean way to detect
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
182 // that we are stopped on the no-op command that marks the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
183 // end of a function or script.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
184
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
185 if (! silent)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
186 {
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
187 stack_frame *frm = tw.current_user_frame ();
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
188
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
189 frm->display_stopped_in_message (buf);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
190 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
191
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
192 event_manager& evmgr = m_interpreter.get_event_manager ();
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
193
27392
820a87b87c01 clean up use of interpreter in qt_interpreter_events::enter_debugger_event
John W. Eaton <jwe@octave.org>
parents: 27374
diff changeset
194 evmgr.enter_debugger_event (fcn_nm, fcn_file_nm, curr_debug_line);
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
195
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
196 evmgr.set_workspace ();
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
197
27441
a36cb488fc97 avoid shadowed variable warning introduced in previous change (bug #56948)
John W. Eaton <jwe@octave.org>
parents: 27440
diff changeset
198 frame.add ([&evmgr, fcn_nm, curr_debug_line] (void) {
27440
d5fc84964eb9 * pt-eval.cc (debugger::repl): Use evmgr as event_manager variable name.
John W. Eaton <jwe@octave.org>
parents: 27428
diff changeset
199 evmgr.execute_in_debugger_event (fcn_nm,
d5fc84964eb9 * pt-eval.cc (debugger::repl): Use evmgr as event_manager variable name.
John W. Eaton <jwe@octave.org>
parents: 27428
diff changeset
200 curr_debug_line);
27441
a36cb488fc97 avoid shadowed variable warning introduced in previous change (bug #56948)
John W. Eaton <jwe@octave.org>
parents: 27440
diff changeset
201 });
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
202
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
203 if (! silent)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
204 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
205 std::string line_buf;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
206
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
207 if (caller)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
208 line_buf = caller->get_code_line (curr_debug_line);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
209
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
210 if (! line_buf.empty ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
211 buf << curr_debug_line << ": " << line_buf;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
212 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
213 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
214 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
215
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
216 if (silent)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
217 command_editor::erase_empty_line (true);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
218
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
219 std::string stopped_in_msg = buf.str ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
220
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
221 if (! stopped_in_msg.empty ())
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
222 std::cerr << stopped_in_msg << std::endl;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
223
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
224 std::string tmp_prompt = prompt_arg;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
225 if (m_level > 0)
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
226 tmp_prompt = "[" + std::to_string (m_level) + "]" + prompt_arg;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
227
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
228 frame.add_method (input_sys, &input_system::set_PS1, input_sys.PS1 ());
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
229 input_sys.PS1 (tmp_prompt);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
230
27301
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
231 if (! m_interpreter.interactive ())
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
232 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
233
27301
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
234 frame.add_method (m_interpreter, &interpreter::interactive,
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
235 m_interpreter.interactive ());
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
236
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
237 m_interpreter.interactive (true);
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
238
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
239 // FIXME: should debugging be possible in an embedded
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
240 // interpreter?
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
241
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
242 application *app = application::app ();
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
243
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
244 if (app)
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
245 {
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
246 frame.add_method (app, &application::forced_interactive,
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
247 app->forced_interactive ());
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
248
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
249 app->forced_interactive (true);
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27290
diff changeset
250 }
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
251 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
252
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
253 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
254
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
255 input_reader reader (m_interpreter);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
256
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
257 push_parser debug_parser (m_interpreter);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
258
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
259 #else
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
260
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
261 parser debug_parser (m_interpreter);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
262
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
263 #endif
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
264
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
265 error_system& es = m_interpreter.get_error_system ();
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
266
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
267 while (m_in_debug_repl)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
268 {
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
269 if (m_execution_mode == EX_CONTINUE || tw.dbstep_flag ())
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
270 break;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
271
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
272 if (quitting_debugger ())
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
273 break;
27240
336c640c481b make "dbquit all" work and fix dbquit compatibility (bug #56616)
John W. Eaton <jwe@octave.org>
parents: 27234
diff changeset
274
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
275 try
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
276 {
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
277 debug_parser.reset ();
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
278
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
279 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
280
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
281 int retval = 0;
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
282
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
283 std::string prompt
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
284 = command_editor::decode_prompt_string (tmp_prompt);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
285
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
286 do
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
287 {
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
288 bool eof = false;
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
289 std::string input_line = reader.get_input (prompt, eof);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
290
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
291 if (eof)
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
292 {
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
293 retval = EOF;
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
294 break;
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
295 }
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
296
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
297 retval = debug_parser.run (input_line, false);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
298
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
299 prompt = command_editor::decode_prompt_string (input_sys.PS2 ());
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
300 }
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
301 while (retval < 0);
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
302
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
303 #else
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
304
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
305 int retval = debug_parser.run ();
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
306
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
307 #endif
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
308 if (command_editor::interrupt (false))
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
309 {
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
310 // Break regardless of m_execution_mode value.
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
311
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
312 quitting_debugger ();
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
313
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
314 break;
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
315 }
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
316 else
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
317 {
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
318 if (retval == 0)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
319 {
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
320 std::shared_ptr<tree_statement_list> stmt_list
27533
0abe70896e34 use push parser in debug repl if enabled
John W. Eaton <jwe@octave.org>
parents: 27519
diff changeset
321 = debug_parser.statement_list ();
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
322
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
323 stmt_list->accept (tw);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
324
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
325 if (octave_completion_matches_called)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
326 octave_completion_matches_called = false;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
327
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
328 // FIXME: the following statement is here because
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
329 // the last command may have been a dbup, dbdown, or
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
330 // dbstep command that changed the current debug
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
331 // frame. If so, we need to reset the current frame
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
332 // for the call stack. But is this right way to do
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
333 // this job? What if the statement list was
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
334 // something like "dbup; dbstack"? Will the call to
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
335 // dbstack use the right frame? If not, how can we
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
336 // fix this problem?
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
337 tw.goto_frame (tw.debug_frame ());
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
338 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
339
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
340 octave_quit ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
341 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
342 }
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
343 catch (const execution_exception& ee)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
344 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
345 es.save_exception (ee);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
346 es.display_exception (ee, std::cerr);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
347
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
348 // Ignore errors when in debugging mode;
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
349 m_interpreter.recover_from_exception ();
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
350 }
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
351 catch (const quit_debug_exception& qde)
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
352 {
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
353 if (qde.all ())
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
354 throw;
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
355
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
356 // Continue in this debug level.
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
357 }
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
358 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
359 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
360
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
361 bool debugger::quitting_debugger (void) const
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
362 {
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
363 if (m_execution_mode == EX_QUIT)
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
364 {
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
365 // If there is no enclosing debug level or the top-level
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
366 // repl is not active, handle dbquit the same as dbcont.
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
367
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
368 if (m_level > 0 || m_interpreter.in_top_level_repl ())
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
369 throw quit_debug_exception ();
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
370 else
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
371 return true;
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
372 }
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
373
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
374 if (m_execution_mode == EX_QUIT_ALL)
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
375 {
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
376 // If the top-level repl is not active, handle "dbquit all"
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
377 // the same as dbcont.
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
378
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
379 if (m_interpreter.in_top_level_repl ())
27402
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
380 throw quit_debug_exception (true);
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
381 else
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
382 return true;
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
383 }
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
384
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
385 return false;
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
386 }
84d11fcb2f91 also check debugger execution mode after command editor interrupt
John W. Eaton <jwe@octave.org>
parents: 27392
diff changeset
387
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
388 bool tree_evaluator::at_top_level (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
389 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
390 return m_call_stack.at_top_level ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
391 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
392
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
393 void tree_evaluator::eval (std::shared_ptr<tree_statement_list>& stmt_list,
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
394 bool interactive)
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
395 {
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
396 try
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
397 {
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
398 stmt_list->accept (*this);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
399
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
400 octave_quit ();
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
401
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
402 if (! interactive)
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
403 {
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
404 bool quit = (m_returning || m_breaking);
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
405
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
406 if (m_returning)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
407 m_returning = 0;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
408
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
409 if (m_breaking)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
410 m_breaking--;
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
411
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
412 if (quit)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
413 return;
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
414 }
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
415
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
416 if (octave_completion_matches_called)
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
417 octave_completion_matches_called = false;
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
418 }
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
419 catch (const quit_debug_exception&)
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
420 {
27519
804e5d42b728 move reader and parser from evaluator repl to interpreter main_loop
John W. Eaton <jwe@octave.org>
parents: 27514
diff changeset
421 m_interpreter.recover_from_exception ();
25404
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
422 }
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
423 }
e37d857716c3 move core of interpreter::main_loop to evaluator
John W. Eaton <jwe@octave.org>
parents: 25403
diff changeset
424
27015
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
425 std::string
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
426 tree_evaluator::mfilename (const std::string& opt) const
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
427 {
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
428 std::string fname;
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
429
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
430 octave_user_code *fcn = m_call_stack.current_user_code ();
27015
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
431
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
432 if (fcn)
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
433 {
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
434 fname = fcn->fcn_file_name ();
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
435
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
436 if (fname.empty ())
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
437 fname = fcn->name ();
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
438 }
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
439
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
440 if (opt == "fullpathext")
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
441 return fname;
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
442
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
443 size_t dpos = fname.rfind (sys::file_ops::dir_sep_char ());
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
444 size_t epos = fname.rfind ('.');
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
445
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
446 if (epos <= dpos+1)
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
447 epos = std::string::npos;
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
448
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
449 if (epos != std::string::npos)
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
450 fname = fname.substr (0, epos);
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
451
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
452 if (opt == "fullpath")
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
453 return fname;
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
454
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
455 if (dpos != std::string::npos)
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
456 fname = fname.substr (dpos+1);
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
457
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
458 return fname;
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
459 }
4d9e1a832a55 move core of mfilename function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27014
diff changeset
460
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
461 octave_value_list
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
462 tree_evaluator::eval_string (const std::string& eval_str, bool silent,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
463 int& parse_status, int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
464 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
465 octave_value_list retval;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
466
26512
4d6392c879d7 avoid double free of lexer on exit (bug #55347)
John W. Eaton <jwe@octave.org>
parents: 26509
diff changeset
467 parser eval_parser (eval_str, m_interpreter);
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
468
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
469 do
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
470 {
26512
4d6392c879d7 avoid double free of lexer on exit (bug #55347)
John W. Eaton <jwe@octave.org>
parents: 26509
diff changeset
471 eval_parser.reset ();
4d6392c879d7 avoid double free of lexer on exit (bug #55347)
John W. Eaton <jwe@octave.org>
parents: 26509
diff changeset
472
26662
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
473 // If we are looking at
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
474 //
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
475 // val = eval ("code");
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
476 //
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
477 // then don't allow code to be parsed as a command.
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
478
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
479 if (nargout > 0)
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
480 eval_parser.disallow_command_syntax ();
05fc703b419a update handling of command-style function call syntax in eval
John W. Eaton <jwe@octave.org>
parents: 26661
diff changeset
481
26512
4d6392c879d7 avoid double free of lexer on exit (bug #55347)
John W. Eaton <jwe@octave.org>
parents: 26509
diff changeset
482 parse_status = eval_parser.run ();
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
483
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
484 if (parse_status == 0)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
485 {
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
486 std::shared_ptr<tree_statement_list> stmt_list
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
487 = eval_parser.statement_list ();
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
488
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
489 if (stmt_list)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
490 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
491 tree_statement *stmt = nullptr;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
492
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
493 if (stmt_list->length () == 1
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
494 && (stmt = stmt_list->front ())
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
495 && stmt->is_expression ())
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
496 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
497 tree_expression *expr = stmt->expression ();
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
498
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
499 if (silent)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
500 expr->set_print_flag (false);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
501
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
502 retval = expr->evaluate_n (*this, nargout);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
503
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
504 bool do_bind_ans = false;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
505
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
506 if (expr->is_identifier ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
507 do_bind_ans = ! is_variable (expr);
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
508 else
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
509 do_bind_ans = ! expr->is_assignment_expression ();
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
510
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
511 if (do_bind_ans && ! retval.empty ())
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
512 bind_ans (retval(0), expr->print_result ());
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
513
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
514 if (nargout == 0)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
515 retval = octave_value_list ();
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
516 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
517 else if (nargout == 0)
27504
7a31b25e3252 use shared_ptr for storing classdef and statement_list objects in parser
John W. Eaton <jwe@octave.org>
parents: 27480
diff changeset
518 stmt_list->accept (*this);
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
519 else
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
520 error ("eval: invalid use of statement list");
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
521
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
522 if (returning () || breaking () || continuing ())
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
523 break;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
524 }
27510
5438a82a18fb declare base_parser class data protected
John W. Eaton <jwe@octave.org>
parents: 27509
diff changeset
525 else if (eval_parser.at_end_of_input ())
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
526 break;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
527 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
528 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
529 while (parse_status == 0);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
530
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
531 return retval;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
532 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
533
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
534 octave_value tree_evaluator::eval_string (const std::string& eval_str,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
535 bool silent, int& parse_status)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
536 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
537 octave_value retval;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
538
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
539 octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
540
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
541 if (! tmp.empty ())
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
542 retval = tmp(0);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
543
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
544 return retval;
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
545 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
546
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
547 octave_value_list tree_evaluator::eval_string (const octave_value& arg,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
548 bool silent, int& parse_status,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
549 int nargout)
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
550 {
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
551 std::string s = arg.xstring_value ("eval: expecting string argument");
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
552
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
553 return eval_string (s, silent, parse_status, nargout);
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
554 }
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
555
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
556 octave_value_list tree_evaluator::eval (const std::string& try_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
557 int nargout)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
558 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
559 int parse_status = 0;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
560
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
561 return eval_string (try_code, nargout > 0, parse_status, nargout);
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
562 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
563
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
564 octave_value_list tree_evaluator::eval (const std::string& try_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
565 const std::string& catch_code,
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
566 int nargout)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
567 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
568 octave_value_list retval;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
569
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
570 error_system& es = m_interpreter.get_error_system ();
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
571
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
572 int parse_status = 0;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
573
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
574 bool execution_error = false;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
575
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
576 octave_value_list tmp;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
577
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
578 try
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
579 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
580 tmp = eval_string (try_code, nargout > 0, parse_status, nargout);
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
581 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
582 catch (const execution_exception& ee)
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
583 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
584 es.save_exception (ee);
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
585 m_interpreter.recover_from_exception ();
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
586
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
587 execution_error = true;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
588 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
589
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
590 if (parse_status != 0 || execution_error)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
591 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
592 tmp = eval_string (catch_code, nargout > 0, parse_status, nargout);
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
593
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
594 retval = (nargout > 0) ? tmp : octave_value_list ();
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
595 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
596 else
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
597 {
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
598 if (nargout > 0)
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
599 retval = tmp;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
600
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
601 // FIXME: we should really be rethrowing whatever
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
602 // exception occurred, not just throwing an
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
603 // execution exception.
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
604 if (execution_error)
27480
63b417917f5e remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents: 27474
diff changeset
605 throw execution_exception ();
27019
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
606 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
607
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
608 return retval;
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
609 }
6cb675912f2b move core of eval function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
610
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
611 octave_value_list tree_evaluator::evalin (const std::string& context,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
612 const std::string& try_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
613 int nargout)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
614 {
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
615 unwind_action act ([this] (size_t frm)
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
616 {
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
617 m_call_stack.restore_frame (frm);
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
618 }, m_call_stack.current_frame ());
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
619
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
620 if (context == "caller")
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
621 m_call_stack.goto_caller_frame ();
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
622 else if (context == "base")
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
623 m_call_stack.goto_base_frame ();
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
624 else
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
625 error ("evalin: CONTEXT must be \"caller\" or \"base\"");
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
626
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
627 int parse_status = 0;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
628
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
629 return eval_string (try_code, nargout > 0, parse_status, nargout);
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
630 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
631
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
632 octave_value_list tree_evaluator::evalin (const std::string& context,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
633 const std::string& try_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
634 const std::string& catch_code,
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
635 int nargout)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
636 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
637 octave_value_list retval;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
638
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
639 unwind_action act1 ([this] (size_t frm)
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
640 {
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
641 m_call_stack.restore_frame (frm);
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
642 }, m_call_stack.current_frame ());
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
643
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
644 if (context == "caller")
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
645 m_call_stack.goto_caller_frame ();
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
646 else if (context == "base")
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
647 m_call_stack.goto_base_frame ();
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
648 else
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
649 error ("evalin: CONTEXT must be \"caller\" or \"base\"");
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
650
27160
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
651 error_system& es = m_interpreter.get_error_system ();
6b0c61a5a0f0 move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents: 27123
diff changeset
652
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
653 int parse_status = 0;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
654
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
655 bool execution_error = false;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
656
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
657 octave_value_list tmp;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
658
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
659 try
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
660 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
661 tmp = eval_string (try_code, nargout > 0, parse_status, nargout);
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
662 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
663 catch (const execution_exception& ee)
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
664 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
665 es.save_exception (ee);
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
666 m_interpreter.recover_from_exception ();
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
667
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
668 execution_error = true;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
669 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
670
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
671 if (parse_status != 0 || execution_error)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
672 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
673 tmp = eval_string (catch_code, nargout > 0, parse_status, nargout);
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
674
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
675 retval = (nargout > 0) ? tmp : octave_value_list ();
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
676 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
677 else
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
678 {
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
679 if (nargout > 0)
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
680 retval = tmp;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
681
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
682 // FIXME: we should really be rethrowing whatever
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
683 // exception occurred, not just throwing an
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
684 // execution exception.
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
685 if (execution_error)
27480
63b417917f5e remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents: 27474
diff changeset
686 throw execution_exception ();
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
687 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
688
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
689 return retval;
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
690 }
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
691
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
692 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
693 tree_evaluator::visit_anon_fcn_handle (tree_anon_fcn_handle&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
694 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
695 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
696 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
697
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
698 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
699 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
700 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
701 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
702 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
703
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
704 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
705 tree_evaluator::visit_binary_expression (tree_binary_expression&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
706 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
707 panic_impossible ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
708 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
709
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
710 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
711 tree_evaluator::visit_boolean_expression (tree_boolean_expression&)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
712 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
713 panic_impossible ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
714 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
715
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
716 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
717 tree_evaluator::visit_compound_binary_expression (tree_compound_binary_expression&)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
718 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
719 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
720 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
721
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
722 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
723 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
724 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
725 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
726 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
727 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
728 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
729 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
730 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
731
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
732 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
733 do_breakpoint (cmd.is_active_breakpoint (*this));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
734
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
735 if (m_in_loop_command)
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
736 m_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
737 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
738 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
739 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
740
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
741 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
742 tree_evaluator::visit_colon_expression (tree_colon_expression&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
743 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
744 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
745 }
10188
97ae300aa73a improve implementation of break, continue, and return commands
John W. Eaton <jwe@octave.org>
parents: 10186
diff changeset
746
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
747 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
748 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
749 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
750 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
751 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
752 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
753 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
754 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
755 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
756
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
757 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
758 do_breakpoint (cmd.is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
759
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
760 if (m_in_loop_command)
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
761 m_continuing = 1;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
762 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
763
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
764 bool
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
765 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
766 {
25401
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
767 return ! (m_silent_functions && (m_statement_context == SC_FUNCTION
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
768 || m_statement_context == SC_SCRIPT));
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
769 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
770
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
771 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
772 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
773 {
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
774 m_debug_mode = (m_bp_table.have_breakpoints () || m_dbstep_flag != 0
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
775 || in_debug_repl ());
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
776 }
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
777
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
778 void
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
779 tree_evaluator::reset_debug_state (bool mode)
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
780 {
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
781 m_debug_mode = mode;
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
782 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
783
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
784 void
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
785 tree_evaluator::enter_debugger (const std::string& prompt)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
786 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
787 unwind_protect frame;
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
788
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
789 frame.add_fcn (command_history::ignore_entries,
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
790 command_history::ignoring_entries ());
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
791
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
792 command_history::ignore_entries (false);
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
793
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27100
diff changeset
794 frame.add_method (m_call_stack, &call_stack::restore_frame,
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
795 m_call_stack.current_frame ());
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
796
27286
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
797 // Don't allow errors or warnings at the debug prompt to push us
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
798 // into deeper levels of debugging.
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
799
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
800 error_system& es = m_interpreter.get_error_system ();
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
801
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
802 frame.add_method (es, &error_system::set_debug_on_error,
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
803 es.debug_on_error ());
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
804
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
805 frame.add_method (es, &error_system::set_debug_on_warning,
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
806 es.debug_on_warning ());
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
807
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
808 es.debug_on_error (false);
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
809 es.debug_on_warning (false);
52542cfcc7dc always disable debug_on_error and debug_on_warning at debug prompt (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27282
diff changeset
810
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
811 // Go up to the nearest user code frame.
27289
9dcbc0a449af correctly set debug_frame when using "keyboard" (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27286
diff changeset
812
9dcbc0a449af correctly set debug_frame when using "keyboard" (bug #56625)
John W. Eaton <jwe@octave.org>
parents: 27286
diff changeset
813 m_debug_frame = m_call_stack.dbupdown (0);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
814
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
815 // FIXME: probably we just want to print one line, not the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
816 // entire statement, which might span many lines...
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
817 //
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
818 // tree_print_code tpc (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
819 // stmt.accept (tpc);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
820
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
821 debugger *dbgr = new debugger (m_interpreter, m_debugger_stack.size ());
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
822
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
823 m_debugger_stack.push (dbgr);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
824
27222
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
825 frame.add ([this] (void)
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
826 {
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
827 delete m_debugger_stack.top ();
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
828 m_debugger_stack.pop ();
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
829 });
f5b967060442 ensure debuger_stack is popped when exiting a debug level (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27212
diff changeset
830
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
831 dbgr->repl (prompt);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
832 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
833
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
834 void
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
835 tree_evaluator::keyboard (const std::string& prompt)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
836 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
837 enter_debugger (prompt);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
838 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
839
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
840 void
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
841 tree_evaluator::dbupdown (int n, bool verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
842 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
843 m_debug_frame = m_call_stack.dbupdown (n, verbose);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
844 }
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
845
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
846 Matrix
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
847 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
848 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
849 Matrix retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
850
27370
a2d3fa82b730 don't use stack to save and restore lvalue list value in evaluator (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27369
diff changeset
851 const std::list<octave_lvalue> *lvalues = m_lvalue_list;
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
852
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
853 if (! lvalues)
23482
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
854 return retval;
c9937e865768 make isargout work again for nested function calls
John W. Eaton <jwe@octave.org>
parents: 23481
diff changeset
855
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
856 octave_idx_type nbh = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
857
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
858 for (const auto& lval : *lvalues)
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
859 nbh += lval.is_black_hole ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
860
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
861 if (nbh > 0)
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
862 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
863 retval.resize (1, nbh);
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
864
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
865 octave_idx_type k = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
866 octave_idx_type l = 0;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
867
24349
4ced2bfd737e deprecate defun_isargout functions
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
868 for (const auto& lval : *lvalues)
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
869 {
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
870 if (lval.is_black_hole ())
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
871 retval(l++) = k+1;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
872
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
873 k += lval.numel ();
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
874 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
875 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
876
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
877 return retval;
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
878 }
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
879
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
880 octave_value
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
881 tree_evaluator::evaluate (tree_decl_elt *elt)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
882 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
883 // Do not allow functions to return null values.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
884
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
885 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
886
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
887 return id ? id->evaluate (*this).storable_value () : octave_value ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
888 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
889
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
890 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
891 tree_evaluator::is_variable (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
892 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
893 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
894
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
895 return frame.is_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
896 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
897
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
898 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
899 tree_evaluator::is_local_variable (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
900 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
901 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
902
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
903 return frame.is_local_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
904 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
905
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
906 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
907 tree_evaluator::is_variable (const tree_expression *expr) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
908 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
909 if (expr->is_identifier ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
910 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
911 const tree_identifier *id
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
912 = dynamic_cast<const tree_identifier *> (expr);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
913
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
914 if (id->is_black_hole ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
915 return false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
916
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
917 return is_variable (id->symbol ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
918 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
919
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
920 return false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
921 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
922
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
923 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
924 tree_evaluator::is_defined (const tree_expression *expr) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
925 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
926 if (expr->is_identifier ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
927 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
928 const tree_identifier *id
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
929 = dynamic_cast<const tree_identifier *> (expr);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
930
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
931 return is_defined (id->symbol ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
932 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
933
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
934 return false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
935 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
936
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
937 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
938 tree_evaluator::is_variable (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
939 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
940 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
941
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
942 return frame.is_variable (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
943 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
944
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
945 bool
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
946 tree_evaluator::is_defined (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
947 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
948 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
949
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
950 return frame.is_defined (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
951 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
952
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
953 bool tree_evaluator::is_global (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
954 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
955 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
956
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
957 return frame.is_global (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
958 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
959
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
960 octave_value
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
961 tree_evaluator::varval (const symbol_record& sym) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
962 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
963 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
964
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
965 return frame.varval (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
966 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
967
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
968 octave_value
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
969 tree_evaluator::varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
970 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
971 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
972
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
973 return frame.varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
974 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
975
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
976 void tree_evaluator::install_variable (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
977 const octave_value& value,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
978 bool global)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
979 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
980 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
981
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
982 return frame.install_variable (name, value, global);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
983 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
984
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
985 octave_value
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
986 tree_evaluator::global_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
987 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
988 return m_call_stack.global_varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
989 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
990
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
991 octave_value&
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
992 tree_evaluator::global_varref (const std::string& name)
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
993 {
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
994 return m_call_stack.global_varref (name);
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
995 }
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
996
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
997 void
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
998 tree_evaluator::global_assign (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
999 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1000 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1001 m_call_stack.global_varref (name) = val;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1002 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1003
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1004 octave_value
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1005 tree_evaluator::top_level_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1006 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1007 return m_call_stack.get_top_level_value (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1008 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1009
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1010 void
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1011 tree_evaluator::top_level_assign (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1012 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1013 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1014 m_call_stack.set_top_level_value (name, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1015 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1016
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1017 void
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1018 tree_evaluator::assign (const std::string& name, const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1019 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1020 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1021
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1022 frame.assign (name, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1023 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1024
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1025 void
27014
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1026 tree_evaluator::assignin (const std::string& context,
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1027 const std::string& name, const octave_value& val)
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1028 {
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1029 // FIXME: Can this be done without an unwind-protect frame, simply
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1030 // by geting a reference to the caller or base stack frame and
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1031 // calling assign on that?
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1032
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1033 unwind_action act ([this] (size_t frm)
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1034 {
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1035 m_call_stack.restore_frame (frm);
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1036 }, m_call_stack.current_frame ());
27014
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1037
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1038 if (context == "caller")
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1039 m_call_stack.goto_caller_frame ();
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1040 else if (context == "base")
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1041 m_call_stack.goto_base_frame ();
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1042 else
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1043 error ("assignin: CONTEXT must be \"caller\" or \"base\"");
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1044
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1045 if (valid_identifier (name))
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1046 {
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1047 // Put the check here so that we don't slow down assignments
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1048 // generally. Any that go through Octave's parser should have
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1049 // already been checked.
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1050
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1051 if (iskeyword (name))
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1052 error ("assignin: invalid assignment to keyword '%s'",
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1053 name.c_str ());
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1054
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1055 assign (name, val);
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1056 }
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1057 else
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1058 error ("assignin: invalid variable name '%s'", name.c_str ());
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1059 }
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1060
daab1b311a98 move core of assignin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
1061 void
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1062 tree_evaluator::source_file (const std::string& file_name,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1063 const std::string& context,
27507
2d537a089e5d eliminate warn_for argument for source_file and parse_fcn_file functions
John W. Eaton <jwe@octave.org>
parents: 27504
diff changeset
1064 bool verbose, bool require_file)
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1065 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1066 // Map from absolute name of script file to recursion level. We
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1067 // use a map instead of simply placing a limit on recursion in the
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1068 // source_file function so that two mutually recursive scripts
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1069 // written as
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1070 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1071 // foo1.m:
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1072 // ------
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1073 // foo2
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1074 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1075 // foo2.m:
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1076 // ------
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1077 // foo1
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1078 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1079 // and called with
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1080 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1081 // foo1
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1082 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1083 // (for example) will behave the same if they are written as
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1084 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1085 // foo1.m:
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1086 // ------
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1087 // source ("foo2.m")
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1088 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1089 // foo2.m:
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1090 // ------
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1091 // source ("foo1.m")
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1092 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1093 // and called with
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1094 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1095 // source ("foo1.m")
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1096 //
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1097 // (for example).
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1098
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1099 static std::map<std::string, int> source_call_depth;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1100
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1101 std::string file_full_name
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1102 = sys::file_ops::tilde_expand (file_name);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1103
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1104 size_t pos
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1105 = file_full_name.find_last_of (sys::file_ops::dir_sep_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1106
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1107 std::string dir_name = file_full_name.substr (0, pos);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1108
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1109 file_full_name = sys::env::make_absolute (file_full_name);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1110
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1111 unwind_protect frame;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1112
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1113 if (source_call_depth.find (file_full_name) == source_call_depth.end ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1114 source_call_depth[file_full_name] = -1;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1115
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1116 frame.protect_var (source_call_depth[file_full_name]);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1117
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1118 source_call_depth[file_full_name]++;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1119
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1120 if (source_call_depth[file_full_name] >= max_recursion_depth ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1121 error ("max_recursion_depth exceeded");
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1122
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1123 if (! context.empty ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1124 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1125 frame.add_method (m_call_stack, &call_stack::restore_frame,
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1126 m_call_stack.current_frame ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1127
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1128 if (context == "caller")
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1129 m_call_stack.goto_caller_frame ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1130 else if (context == "base")
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1131 m_call_stack.goto_base_frame ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1132 else
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1133 error ("source: context must be \"caller\" or \"base\"");
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1134 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1135
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1136 // Find symbol name that would be in symbol_table, if it were loaded.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1137 size_t dir_end
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1138 = file_name.find_last_of (sys::file_ops::dir_sep_chars ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1139 dir_end = (dir_end == std::string::npos) ? 0 : dir_end + 1;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1140
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1141 size_t extension = file_name.find_last_of ('.');
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1142 if (extension == std::string::npos)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1143 extension = file_name.length ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1144
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1145 std::string symbol = file_name.substr (dir_end, extension - dir_end);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1146 std::string full_name = sys::canonicalize_file_name (file_name);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1147
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1148 // Check if this file is already loaded (or in the path)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1149 symbol_table& symtab = m_interpreter.get_symbol_table ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1150 octave_value ov_code = symtab.fcn_table_find (symbol);
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1151
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1152 // For compatibility with Matlab, accept both scripts and
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1153 // functions.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1154
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1155 if (ov_code.is_user_code ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1156 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1157 octave_user_code *code = ov_code.user_code_value ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1158
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1159 if (! code
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1160 || (sys::canonicalize_file_name (code->fcn_file_name ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1161 != full_name))
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1162 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1163 // Wrong file, so load it below.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1164 ov_code = octave_value ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1165 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1166 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1167 else
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1168 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1169 // Not a script, so load it below.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1170 ov_code = octave_value ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1171 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1172
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1173 // If no symbol of this name, or the symbol is for a different
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1174 // file, load.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1175
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1176 if (ov_code.is_undefined ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1177 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1178 try
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1179 {
27509
fefc780b4e2e move parse_fcn_file from interpreter member function to parser friend
John W. Eaton <jwe@octave.org>
parents: 27507
diff changeset
1180 ov_code = parse_fcn_file (m_interpreter, file_full_name,
fefc780b4e2e move parse_fcn_file from interpreter member function to parser friend
John W. Eaton <jwe@octave.org>
parents: 27507
diff changeset
1181 file_name, dir_name, "", "",
fefc780b4e2e move parse_fcn_file from interpreter member function to parser friend
John W. Eaton <jwe@octave.org>
parents: 27507
diff changeset
1182 require_file, true, false, false);
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1183 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1184 catch (execution_exception& e)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1185 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1186 error (e, "source: error sourcing file '%s'",
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1187 file_full_name.c_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1188 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1189 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1190
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1191 // Return or error if we don't have a valid script or function.
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1192
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1193 if (ov_code.is_undefined ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1194 return;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1195
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1196 if (! ov_code.is_user_code ())
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1197 error ("source: %s is not a script", full_name.c_str ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1198
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1199 if (verbose)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1200 {
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1201 octave_stdout << "executing commands from " << full_name << " ... ";
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1202 octave_stdout.flush ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1203 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1204
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1205 octave_user_code *code = ov_code.user_code_value ();
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1206
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1207 code->call (*this, 0, octave_value_list ());
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1208
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1209 if (verbose)
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1210 octave_stdout << "done." << std::endl;
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1211 }
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1212
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 27016
diff changeset
1213 void
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1214 tree_evaluator::set_auto_fcn_var (stack_frame::auto_var_type avt,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1215 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1216 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1217 m_call_stack.set_auto_fcn_var (avt, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1218 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1219
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1220 octave_value
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1221 tree_evaluator::get_auto_fcn_var (stack_frame::auto_var_type avt) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1222 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1223 return m_call_stack.get_auto_fcn_var (avt);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1224 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1225
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1226 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1227 tree_evaluator::define_parameter_list_from_arg_vector
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1228 (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
1229 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1230 int i = -1;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1231
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1232 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1233 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1234 i++;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1235
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
1236 octave_lvalue ref = elt->lvalue (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1237
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1238 if (i < args.length ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1239 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1240 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
1241 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1242 if (! eval_decl_elt (elt))
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1243 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
1244 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1245 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1246 ref.define (args(i));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1247 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1248 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1249 eval_decl_elt (elt);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1250 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1251 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1252
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
1253 void
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1254 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
1255 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
1256 for (tree_decl_elt *elt : *param_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1257 {
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
1258 octave_lvalue ref = elt->lvalue (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1259
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1260 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
1261 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1262 }
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1263 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1264
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1265 // END is documented in op-kw-docs.
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1266 DEFCONSTMETHOD (end, interp, , ,
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1267 doc: /* -*- texinfo -*-
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1268 @deftypefn {} {} end
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1269 Last element of an array or the end of any @code{for}, @code{parfor},
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1270 @code{if}, @code{do}, @code{while}, @code{function}, @code{switch},
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1271 @code{try}, or @code{unwind_protect} block.
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1272
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1273 As an index of an array, the magic index @qcode{"end"} refers to the
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1274 last valid entry in an indexing operation.
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1275
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1276 Example:
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1277
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1278 @example
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1279 @group
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1280 @var{x} = [ 1 2 3; 4 5 6 ];
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1281 @var{x}(1,end)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1282 @result{} 3
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1283 @var{x}(end,1)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1284 @result{} 4
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1285 @var{x}(end,end)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1286 @result{} 6
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1287 @end group
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1288 @end example
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1289 @seealso{for, parfor, if, do, while, function, switch, try, unwind_protect}
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1290 @end deftypefn */)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1291 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1292 octave_value retval;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1293
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1294 octave::tree_evaluator& tw = interp.get_evaluator ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1295
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1296 const octave_value *indexed_object = tw.indexed_object ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1297 int index_position = tw.index_position ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1298 int num_indices = tw.num_indices ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1299
27100
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1300 // Return invalid index value instead of throwing an error so that we
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1301 // will see an error about the object that is indexed rather than
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1302 // "end" being used incorrectly.
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1303 if (! indexed_object)
27100
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1304 return ovl (octave_NaN);
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1305
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1306 if (indexed_object->isobject ())
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1307 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1308 octave_value_list args;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1309
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1310 args(2) = num_indices;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1311 args(1) = index_position + 1;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1312 args(0) = *indexed_object;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1313
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1314 std::string class_name = indexed_object->class_name ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1315
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1316 octave::symbol_table& symtab = interp.get_symbol_table ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1317
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1318 octave_value meth = symtab.find_method ("end", class_name);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1319
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1320 if (meth.is_defined ())
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1321 return octave::feval (meth.function_value (), args, 1);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1322 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1323
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1324 dim_vector dv = indexed_object->dims ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1325 int ndims = dv.ndims ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1326
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1327 if (num_indices < ndims)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1328 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1329 for (int i = num_indices; i < ndims; i++)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1330 dv(num_indices-1) *= dv(i);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1331
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1332 if (num_indices == 1)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1333 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1334 ndims = 2;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1335 dv.resize (ndims);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1336 dv(1) = 1;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1337 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1338 else
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1339 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1340 ndims = num_indices;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1341 dv.resize (ndims);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1342 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1343 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1344
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1345 if (index_position < ndims)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1346 retval = dv(index_position);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1347 else
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1348 retval = 1;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1349
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1350 return retval;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1351 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1352
27100
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1353 /*
27123
dc89c9b30f3c update bug status for tests
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1354 %!test <*33637>
27100
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1355 %! fail ("__undef_sym__ (end)", "'__undef_sym__' undefined");
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1356 */
b453b586da16 improve error message when indexing undefined object with "end" (bug #33637)
John W. Eaton <jwe@octave.org>
parents: 27037
diff changeset
1357
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1358 namespace octave
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1359 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1360 octave_value_list
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1361 tree_evaluator::convert_to_const_vector (tree_argument_list *arg_list,
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1362 const octave_value *object)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1363 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1364 // END doesn't make sense as a direct argument for a function (i.e.,
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1365 // "fcn (end)" is invalid but "fcn (array (end))" is OK). Maybe we
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1366 // need a different way of asking an octave_value object this
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1367 // question?
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1368
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1369 bool stash_object = (arg_list->includes_magic_end ()
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1370 && object
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1371 && ! (object->is_function ()
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1372 || object->is_function_handle ()));
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1373
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1374 unwind_protect_var<const octave_value *> upv1 (m_indexed_object);
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1375 unwind_protect_var<int> upv2 (m_index_position);
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1376 unwind_protect_var<int> upv3 (m_num_indices);
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1377
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1378 if (stash_object)
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
1379 m_indexed_object = object;
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1380
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1381 int len = arg_list->length ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1382
27353
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1383 std::list<octave_value> args;
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1384
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1385 auto p = arg_list->begin ();
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1386 for (int k = 0; k < len; k++)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1387 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1388 if (stash_object)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1389 {
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1390 m_index_position = k;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1391 m_num_indices = len;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1392 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1393
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1394 tree_expression *elt = *p++;
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1395
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1396 if (elt)
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1397 {
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
1398 octave_value tmp = elt->evaluate (*this);
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1399
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1400 if (tmp.is_cs_list ())
27353
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1401 {
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1402 octave_value_list tmp_ovl = tmp.list_value ();
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1403
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1404 for (octave_idx_type i = 0; i < tmp_ovl.length (); i++)
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1405 args.push_back (tmp_ovl(i));
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1406 }
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1407 else if (tmp.is_defined ())
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1408 args.push_back (tmp);
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1409 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1410 else
27353
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1411 break;
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1412 }
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1413
27353
8db55255c9d1 improve convert_to_const_vector
John W. Eaton <jwe@octave.org>
parents: 27349
diff changeset
1414 return octave_value_list (args);
25382
749d9e858553 move convert_to_const_vector from tree_argument_list to tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25381
diff changeset
1415 }
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1416
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1417 octave_value_list
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1418 tree_evaluator::convert_return_list_to_const_vector
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1419 (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
1420 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1421 octave_idx_type vlen = varargout.numel ();
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1422 int len = ret_list->length ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1423
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1424 // Special case. Will do a shallow copy.
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1425 if (len == 0)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1426 return varargout;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1427 else if (nargout <= len)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1428 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1429 octave_value_list retval (nargout);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1430
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1431 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1432
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1433 for (tree_decl_elt *elt : *ret_list)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1434 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1435 if (is_defined (elt->ident ()))
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
1436 retval(i) = evaluate (elt);
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1437
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1438 i++;
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1439 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1440
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1441 return retval;
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 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1444 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1445 octave_value_list retval (len + vlen);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1446
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1447 int i = 0;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1448
23916
85488effc0ff refactor function value return code
John W. Eaton <jwe@octave.org>
parents: 23913
diff changeset
1449 for (tree_decl_elt *elt : *ret_list)
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
1450 retval(i++) = evaluate (elt);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1451
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1452 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
1453 retval(i++) = varargout(j);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1454
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1455 return retval;
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 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1458
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1459 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1460 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
1461 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1462 bool retval = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1463
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1464 tree_identifier *id = elt->ident ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1465 tree_expression *expr = elt->expression ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1466
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1467 if (id && expr)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1468 {
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
1469 octave_lvalue ult = id->lvalue (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1470
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
1471 octave_value init_val = expr->evaluate (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1472
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1473 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
1474
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1475 retval = true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1476 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1477
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1478 return retval;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1479 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1480
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1481 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1482 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
1483 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
1484 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1485 tree_expression *label = expr->case_label ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1486
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
1487 octave_value label_value = label->evaluate (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1488
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1489 if (label_value.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1490 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
1491 if (label_value.iscell ())
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1492 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1493 Cell cell (label_value.cell_value ());
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1494
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1495 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
1496 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1497 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
1498 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1499 bool match = val.is_equal (cell(i,j));
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1500
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1501 if (match)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1502 return true;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1503 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1504 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1505 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1506 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1507 return val.is_equal (label_value);
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1508 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1509
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1510 return false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1511 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1512
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1513 void tree_evaluator::push_stack_frame (const symbol_scope& scope)
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1514 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1515 m_call_stack.push (scope);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1516 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1517
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1518 void tree_evaluator::push_stack_frame (octave_user_function *fcn,
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1519 unwind_protect *up_frame,
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1520 stack_frame *closure_frames)
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1521 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1522 m_call_stack.push (fcn, up_frame, closure_frames);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1523 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1524
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1525 void tree_evaluator::push_stack_frame (octave_user_script *script,
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1526 unwind_protect *up_frame)
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1527 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1528 m_call_stack.push (script, up_frame);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1529 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1530
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1531 void tree_evaluator::push_stack_frame (octave_function *fcn)
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1532 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1533 m_call_stack.push (fcn);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1534 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1535
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1536 void tree_evaluator::pop_stack_frame (void)
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1537 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1538 m_call_stack.pop ();
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1539 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1540
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1541 int tree_evaluator::current_line (void) const
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1542 {
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1543 return m_call_stack.current_line ();
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1544 }
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1545
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1546 int tree_evaluator::current_column (void) const
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1547 {
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1548 return m_call_stack.current_column ();
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1549 }
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1550
27205
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1551 int tree_evaluator::debug_user_code_line (void) const
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1552 {
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1553 return m_call_stack.debug_user_code_line ();
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1554 }
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1555
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1556 int tree_evaluator::debug_user_code_column (void) const
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1557 {
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1558 return m_call_stack.debug_user_code_column ();
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1559 }
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1560
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1561 void tree_evaluator::debug_where (std::ostream& os) const
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1562 {
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1563 stack_frame *frm = m_call_stack.current_user_frame ();
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1564
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1565 frm->display_stopped_in_message (os);
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1566 }
6648d1ae05fe eliminate direct access to call stack in debug functions
John W. Eaton <jwe@octave.org>
parents: 27204
diff changeset
1567
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1568 octave_user_code * tree_evaluator::current_user_code (void) const
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1569 {
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1570 return m_call_stack.current_user_code ();
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1571 }
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1572
27204
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1573 unwind_protect * tree_evaluator::curr_fcn_unwind_protect_frame (void) const
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1574 {
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1575 return m_call_stack.curr_fcn_unwind_protect_frame ();
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1576 }
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1577
27202
23962b243bad eliminate direct access to call stack in help functions
John W. Eaton <jwe@octave.org>
parents: 27201
diff changeset
1578 octave_user_code * tree_evaluator::debug_user_code (void) const
23962b243bad eliminate direct access to call stack in help functions
John W. Eaton <jwe@octave.org>
parents: 27201
diff changeset
1579 {
23962b243bad eliminate direct access to call stack in help functions
John W. Eaton <jwe@octave.org>
parents: 27201
diff changeset
1580 return m_call_stack.debug_user_code ();
23962b243bad eliminate direct access to call stack in help functions
John W. Eaton <jwe@octave.org>
parents: 27201
diff changeset
1581 }
23962b243bad eliminate direct access to call stack in help functions
John W. Eaton <jwe@octave.org>
parents: 27201
diff changeset
1582
27201
bd49997051ef eliminate direct access to call stack in defun functions
John W. Eaton <jwe@octave.org>
parents: 27200
diff changeset
1583 octave_function * tree_evaluator::current_function (void) const
bd49997051ef eliminate direct access to call stack in defun functions
John W. Eaton <jwe@octave.org>
parents: 27200
diff changeset
1584 {
bd49997051ef eliminate direct access to call stack in defun functions
John W. Eaton <jwe@octave.org>
parents: 27200
diff changeset
1585 return m_call_stack.current ();
bd49997051ef eliminate direct access to call stack in defun functions
John W. Eaton <jwe@octave.org>
parents: 27200
diff changeset
1586 }
bd49997051ef eliminate direct access to call stack in defun functions
John W. Eaton <jwe@octave.org>
parents: 27200
diff changeset
1587
27204
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1588 octave_function * tree_evaluator::caller_function (void) const
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1589 {
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1590 return m_call_stack.caller ();
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1591 }
9a3e92d02a03 eliminate direct access to call stack in variables functions
John W. Eaton <jwe@octave.org>
parents: 27203
diff changeset
1592
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1593 bool tree_evaluator::goto_frame (size_t n, bool verbose)
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1594 {
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1595 return m_call_stack.goto_frame (n, verbose);
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1596 }
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1597
27206
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1598 void tree_evaluator::goto_caller_frame (void)
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1599 {
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1600 m_call_stack.goto_caller_frame ();
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1601 }
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1602
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1603 void tree_evaluator::goto_base_frame (void)
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1604 {
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1605 m_call_stack.goto_base_frame ();
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1606 }
4e4a9d7b436e eliminate direct access to call stack in mex functions
John W. Eaton <jwe@octave.org>
parents: 27205
diff changeset
1607
27200
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1608 void tree_evaluator::restore_frame (size_t n)
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1609 {
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1610 return m_call_stack.restore_frame (n);
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1611 }
dc1edf932248 eliminate direct access to call_stack in input functions
John W. Eaton <jwe@octave.org>
parents: 27199
diff changeset
1612
27208
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1613 std::string tree_evaluator::get_dispatch_class (void) const
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1614 {
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1615 return m_call_stack.get_dispatch_class ();
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1616 }
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1617
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1618 void tree_evaluator::set_dispatch_class (const std::string& class_name)
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1619 {
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1620 m_call_stack.set_dispatch_class (class_name);
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1621 }
5b40cf4896f0 eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents: 27206
diff changeset
1622
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1623 bool
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1624 tree_evaluator::is_class_method_executing (std::string& dclass) const
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1625 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1626 return m_call_stack.is_class_method_executing (dclass);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1627 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1628
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1629 bool
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1630 tree_evaluator::is_class_constructor_executing (std::string& dclass) const
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1631 {
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1632 return m_call_stack.is_class_constructor_executing (dclass);
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1633 }
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 27208
diff changeset
1634
27199
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1635 std::list<stack_frame *>
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1636 tree_evaluator::backtrace_frames (octave_idx_type& curr_user_frame) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1637 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1638 return m_call_stack.backtrace_frames (curr_user_frame);
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1639 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1640
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1641 std::list<stack_frame *>
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1642 tree_evaluator::backtrace_frames (void) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1643 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1644 return m_call_stack.backtrace_frames ();
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1645 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1646
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1647 std::list<frame_info>
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1648 tree_evaluator::backtrace_info (octave_idx_type& curr_user_frame,
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1649 bool print_subfn) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1650 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1651 return m_call_stack.backtrace_info (curr_user_frame, print_subfn);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1652 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1653
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1654 std::list<frame_info> tree_evaluator::backtrace_info (void) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1655 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1656 return m_call_stack.backtrace_info ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1657 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1658
27199
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1659 octave_map
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1660 tree_evaluator::backtrace (octave_idx_type& curr_user_frame,
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1661 bool print_subfn) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1662 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1663 return m_call_stack.backtrace (curr_user_frame, print_subfn);
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1664 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1665
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1666 octave_map tree_evaluator::backtrace (void) const
27199
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1667 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1668 return m_call_stack.backtrace ();
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1669 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1670
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1671 octave_map tree_evaluator::empty_backtrace (void) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1672 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1673 return m_call_stack.empty_backtrace ();
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1674 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1675
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1676 std::string tree_evaluator::backtrace_message (void) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1677 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1678 std::list<frame_info> frames = backtrace_info ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1679
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1680 std::ostringstream buf;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1681
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1682 for (const auto& frm : frames)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1683 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1684 buf << " " << frm.fcn_name ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1685
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1686 int line = frm.line ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1687
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1688 if (line > 0)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1689 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1690 buf << " at line " << line;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1691
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1692 int column = frm.column ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1693
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1694 if (column > 0)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1695 buf << " column " << column;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1696
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1697 buf << "\n";
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1698 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1699 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1700
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1701 return buf.str ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1702 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
1703
27001
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1704 void tree_evaluator::push_dummy_scope (const std::string& name)
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1705 {
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1706 symbol_scope dummy_scope (name + "$dummy");
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1707
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1708 m_call_stack.push (dummy_scope);
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1709 }
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1710
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1711 void tree_evaluator::pop_scope (void)
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1712 {
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1713 m_call_stack.pop ();
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1714 }
3cea1cfb37d3 move toward limiting direct access of call stack
John W. Eaton <jwe@octave.org>
parents: 26975
diff changeset
1715
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1716 symbol_scope tree_evaluator::get_top_scope (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1717 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1718 return m_call_stack.top_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1719 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1720
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1721 symbol_scope tree_evaluator::get_current_scope (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1722 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1723 return m_call_stack.current_scope ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1724 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1725
27212
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1726 void tree_evaluator::mlock (void) const
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1727 {
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1728 octave_function *fcn = m_call_stack.current ();
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1729
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1730 if (! fcn)
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1731 error ("mlock: invalid use outside a function");
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1732
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1733 fcn->lock ();
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1734 }
f84c5528e932 eliminate direct access to call stack in interpreter::mlock
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
1735
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1736 octave_value
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1737 tree_evaluator::max_stack_depth (const octave_value_list& args, int nargout)
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1738 {
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1739 return m_call_stack.max_stack_depth (args, nargout);
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1740 }
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1741
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1742 void tree_evaluator::display_call_stack (void) const
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1743 {
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1744 m_call_stack.display ();
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1745 }
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27210
diff changeset
1746
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1747 octave_value tree_evaluator::find (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1748 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1749 const stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1750
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1751 octave_value val = frame.varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1752
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1753 if (val.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1754 return val;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1755
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1756 // Subfunction. I think it only makes sense to check for
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1757 // subfunctions if we are currently executing a function defined
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1758 // from a .m file.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1759
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1760 octave_value fcn = frame.find_subfunction (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1761
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1762 if (fcn.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1763 return fcn;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1764
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1765 symbol_table& symtab = m_interpreter.get_symbol_table ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1766
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1767 return symtab.fcn_table_find (name, ovl ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1768 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1769
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1770 void tree_evaluator::clear_objects (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1771 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1772 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1773
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1774 frame.clear_objects ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1775 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1776
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1777 void tree_evaluator::clear_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1778 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1779 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1780
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1781 frame.clear_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1782 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1783
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1784 void tree_evaluator::clear_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1785 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1786 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1787
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1788 frame.clear_variable_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1789 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1790
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1791 void tree_evaluator::clear_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1792 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1793 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1794
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1795 frame.clear_variable_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1796 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1797
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1798 void tree_evaluator::clear_variables (void)
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1799 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1800 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1801
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1802 frame.clear_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1803 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1804
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1805 void tree_evaluator::clear_global_variable (const std::string& name)
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1806 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1807 m_call_stack.clear_global_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1808 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1809
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1810 void
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1811 tree_evaluator::clear_global_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1812 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1813 m_call_stack.clear_global_variable_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1814 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1815
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1816 void tree_evaluator::clear_global_variable_regexp(const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1817 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1818 m_call_stack.clear_global_variable_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1819 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1820
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1821 void tree_evaluator::clear_global_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1822 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1823 m_call_stack.clear_global_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1824 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1825
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1826 void tree_evaluator::clear_all (bool force)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1827 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1828 // FIXME: should this also clear objects?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1829
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1830 clear_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1831 clear_global_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1832
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1833 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
1834
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1835 symtab.clear_functions (force);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1836 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1837
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1838 void tree_evaluator::clear_symbol (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1839 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1840 // FIXME: are we supposed to do both here?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1841
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1842 clear_variable (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1843
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1844 symbol_table& symtab = m_interpreter.get_symbol_table ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1845
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1846 symtab.clear_function (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1847 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1848
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1849 void tree_evaluator::clear_symbol_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1850 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1851 // FIXME: are we supposed to do both here?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1852
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1853 clear_variable_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1854
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1855 symbol_table& symtab = m_interpreter.get_symbol_table ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1856
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1857 symtab.clear_function_pattern (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1858 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1859
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1860 void tree_evaluator::clear_symbol_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1861 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1862 // FIXME: are we supposed to do both here?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1863
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1864 clear_variable_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1865
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1866 symbol_table& symtab = m_interpreter.get_symbol_table ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1867
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1868 symtab.clear_function_regexp (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1869 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1870
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1871 std::list<std::string> tree_evaluator::global_variable_names (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1872 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1873 return m_call_stack.global_variable_names ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1874 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1875
27594
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27540
diff changeset
1876 std::list<std::string> tree_evaluator::top_level_variable_names (void) const
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27540
diff changeset
1877 {
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27540
diff changeset
1878 return m_call_stack.top_level_variable_names ();
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27540
diff changeset
1879 }
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27540
diff changeset
1880
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1881 std::list<std::string> tree_evaluator::variable_names (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1882 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1883 return m_call_stack.variable_names ();
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1884 }
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23916
diff changeset
1885
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1886 // Return a pointer to the user-defined function FNAME. If FNAME is empty,
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1887 // search backward for the first user-defined function in the
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1888 // current call stack.
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1889
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1890 octave_user_code *
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1891 tree_evaluator::get_user_code (const std::string& fname,
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1892 const std::string& class_name)
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1893 {
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1894 octave_user_code *user_code = nullptr;
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1895
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1896 if (fname.empty ())
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1897 user_code = m_call_stack.debug_user_code ();
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1898 else
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1899 {
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1900 std::string name = fname;
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1901
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1902 if (sys::file_ops::dir_sep_char () != '/' && name[0] == '@')
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1903 {
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1904 auto beg = name.begin () + 2; // never have @/method
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1905 auto end = name.end () - 1; // never have trailing '/'
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1906 std::replace (beg, end, '/', sys::file_ops::dir_sep_char ());
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1907 }
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1908
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1909 size_t name_len = name.length ();
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1910
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1911 if (name_len > 2 && name.substr (name_len-2) == ".m")
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1912 name = name.substr (0, name_len-2);
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1913
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1914 if (name.empty ())
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1915 return nullptr;
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1916
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1917 symbol_table& symtab = m_interpreter.get_symbol_table ();
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1918
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1919 octave_value fcn;
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1920 size_t p2 = std::string::npos;
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1921
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1922 if (name[0] == '@')
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1923 {
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1924 size_t p1 = name.find (sys::file_ops::dir_sep_char (), 1);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1925
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1926 if (p1 == std::string::npos)
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1927 return nullptr;
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1928
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1929 std::string dispatch_type = name.substr (1, p1-1);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1930
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1931 p2 = name.find ('>', p1);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1932
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1933 std::string method = name.substr (p1+1, p2-1);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1934
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1935 fcn = symtab.find_method (method, dispatch_type);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1936 }
26975
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1937 else if (! class_name.empty ())
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1938 {
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1939 cdef_manager& cdm = m_interpreter.get_cdef_manager ();
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1940
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1941 fcn = cdm.find_method (class_name, name);
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1942
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1943 // If there is no classdef method, then try legacy classes.
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1944 if (fcn.is_undefined ())
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1945 fcn = symtab.find_method (name, class_name);
de826e69a5ea make breakpoints in classdef methods work (bug #45404, bug #46451)
John W. Eaton <jwe@octave.org>
parents: 26924
diff changeset
1946 }
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1947 else
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1948 {
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1949 p2 = name.find ('>');
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1950
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1951 std::string main_fcn = name.substr (0, p2);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1952
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1953 fcn = symtab.find_function (main_fcn);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1954 }
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1955
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1956 // List of function names sub1>sub2>...
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1957 std::string subfuns;
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1958
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1959 if (p2 != std::string::npos)
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1960 subfuns = name.substr (p2+1);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1961
26179
a0b63c183d4b Do not attempt to extract user code from oct-files (bug #55184).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26164
diff changeset
1962 if (fcn.is_defined () && fcn.is_user_code ())
a0b63c183d4b Do not attempt to extract user code from oct-files (bug #55184).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26164
diff changeset
1963 user_code = fcn.user_code_value ();
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1964
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1965 if (! user_code || subfuns.empty ())
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1966 return user_code;
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1967
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1968 fcn = user_code->find_subfunction (subfuns);
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1969
27178
e3b2d4e442c4 improve message for setting breakpoint in nonexistent function (bug #56157)
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1970 if (fcn.is_undefined ())
e3b2d4e442c4 improve message for setting breakpoint in nonexistent function (bug #56157)
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1971 return nullptr;
e3b2d4e442c4 improve message for setting breakpoint in nonexistent function (bug #56157)
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
1972
26065
2eb71b83d3e2 partially refactor function lookup in symbol table
John W. Eaton <jwe@octave.org>
parents: 26039
diff changeset
1973 user_code = fcn.user_code_value ();
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1974 }
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1975
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1976 return user_code;
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1977 }
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1978
27199
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1979 std::string
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1980 tree_evaluator::current_function_name (void) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1981 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1982 octave_function *curfcn = m_call_stack.current ();
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1983
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1984 if (curfcn)
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1985 return curfcn->name ();
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1986
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1987 return "";
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1988 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1989
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1990 bool
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1991 tree_evaluator::in_user_code (void) const
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1992 {
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1993 return m_call_stack.current_user_code () != nullptr;
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1994 }
f27002104c5b eliminate direct access to call_stack in error functions
John W. Eaton <jwe@octave.org>
parents: 27179
diff changeset
1995
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
1996 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
1997 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
1998 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
1999 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
2000 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2001 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
2002 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
2003 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
2004 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2005
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2006 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2007 do_breakpoint (cmd.is_active_breakpoint (*this));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2008
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2009 // FIXME: tree_decl_init_list is not derived from tree, so should it
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2010 // really have an accept method?
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2011
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2012 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
2013
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2014 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
2015 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
2016 }
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2017
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2018 void
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2019 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
2020 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2021 tree_identifier *id = elt.ident ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2022
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2023 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
2024 {
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2025 if (elt.is_global ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2026 m_call_stack.make_global (id->symbol ());
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2027 else if (elt.is_persistent ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2028 m_call_stack.make_persistent (id->symbol ());
23469
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2029 else
2699c5974844 handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents: 23458
diff changeset
2030 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
2031
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
2032 octave_lvalue ult = id->lvalue (*this);
23435
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 (ult.is_undefined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2035 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2036 tree_expression *expr = elt.expression ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2037
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2038 octave_value init_val;
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 if (expr)
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
2041 init_val = expr->evaluate (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2042 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2043 init_val = Matrix ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2044
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2045 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
2046 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2047 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2048 }
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
2049
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2050 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2051 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
2052 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2053 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
2054
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2055 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
2056 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2057 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
2058 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2059 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2060
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2061 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2062 do_breakpoint (cmd.is_active_breakpoint (*this));
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
2063
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2064 // 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
2065 // and cmd.maxproc_expr ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2066
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
2067 unwind_protect_var<bool> upv (m_in_loop_command, true);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2068
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2069 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
2070
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2071 octave_value rhs = expr->evaluate (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2072
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
2073 #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
2074 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
2075 return;
15027
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
2076 #endif
741d2dbcc117 Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents: 15023
diff changeset
2077
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2078 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
2079 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2080
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2081 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
2082
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
2083 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
2084
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2085 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
2086
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2087 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
2088 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2089 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
2090
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2091 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
2092
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2093 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
2094 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2095 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
2096 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
2097
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2098 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
2099
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2100 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
2101
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2102 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
2103 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2104
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2105 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
2106 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2107 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2108 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2109 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
2110 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2111 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
2112 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
2113
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2114 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
2115
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2116 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
2117 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2118
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2119 // 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
2120 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
2121 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23563
diff changeset
2122 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
2123 || 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
2124 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2125 // 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
2126 // columns.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2127
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2128 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
2129
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2130 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
2131 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
2132
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2133 octave_value arg = rhs;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2134 if (rhs.ndims () > 2)
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2135 arg = arg.reshape (dv);
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2136
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2137 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
2138 {
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2139 octave_value_list idx;
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2140 octave_idx_type iidx;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2141
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2142 // 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
2143 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
2144 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2145 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
2146 iidx = 0;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2147 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2148 else
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 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
2151 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
2152 iidx = 1;
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2155 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
2156 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2157 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
2158 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
2159
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2160 // 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
2161 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
2162 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
2163
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2164 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
2165
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2166 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
2167 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
2168
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2169 if (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
2170 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2171 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2172 }
23514
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2173 else
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2174 {
fd7a16594614 Don't iterate over empty for loop expressions (bug #50893).
Rik <rik@octave.org>
parents: 23503
diff changeset
2175 // 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
2176 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
2177 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2178 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2179 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2180 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
2181 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
2182 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2183
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2184 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2185 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
2186 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2187 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
2188
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2189 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
2190 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2191 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
2192 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2193 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2194
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2195 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2196 do_breakpoint (cmd.is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2197
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
2198 unwind_protect_var<bool> upv (m_in_loop_command, true);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2199
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2200 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
2201
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
2202 octave_value rhs = expr->evaluate (*this);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2203
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2204 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
2205 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2206
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23577
diff changeset
2207 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
2208 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
2209
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2210 // 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
2211 // 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
2212 // structure element.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2213
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2214 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
2215
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
2216 auto p = lhs->begin ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2217
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2218 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
2219
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
2220 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
2221
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2222 elt = *p;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2223
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
2224 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
2225
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2226 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
2227
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2228 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
2229
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2230 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
2231
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2232 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
2233
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2234 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
2235 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2236 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
2237 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
2238
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2239 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
2240
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2241 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
2242
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2243 octave_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
2244
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2245 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
2246
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2247 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
2248 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
2249
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2250 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
2251 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
2252
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2253 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
2254 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2255 }
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2258 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2259 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
2260 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2261 // ??
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2262 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2263 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2264
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2265 octave_value_list
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2266 tree_evaluator::execute_user_script (octave_user_script& user_script,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2267 int nargout,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2268 const octave_value_list& args)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2269 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2270 octave_value_list retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2271
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2272 std::string file_name = user_script.fcn_file_name ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2273
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2274 if (args.length () != 0 || nargout != 0)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2275 error ("invalid call to script %s", file_name.c_str ());
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2276
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2277 tree_statement_list *cmd_list = user_script.body ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2278
25401
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2279 if (! cmd_list)
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2280 return retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2281
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2282 unwind_protect frame;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2283
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2284 if (m_call_stack.size () >= static_cast<size_t> (m_max_recursion_depth))
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2285 error ("max_recursion_depth exceeded");
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2286
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2287 m_call_stack.push (&user_script, &frame);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2288
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2289 // Set pointer to the current unwind_protect frame to allow
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2290 // certain builtins register simple cleanup in a very optimized manner.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2291 // This is *not* intended as a general-purpose on-cleanup mechanism,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2292
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2293 frame.add_method (m_call_stack, &call_stack::pop);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2294
25401
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2295 frame.protect_var (m_statement_context);
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2296 m_statement_context = SC_SCRIPT;
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2297
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2298 profiler::enter<octave_user_script> block (m_profiler, user_script);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2299
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2300 if (echo ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2301 push_echo_state (frame, tree_evaluator::ECHO_SCRIPTS, file_name);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2302
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2303 cmd_list->accept (*this);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2304
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2305 if (m_returning)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2306 m_returning = 0;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2307
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2308 if (m_breaking)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2309 m_breaking--;
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2310
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2311 return retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2312 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2313
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2314 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2315 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
2316 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2317 // ??
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2318 panic_impossible ();
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
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2321 octave_value_list
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2322 tree_evaluator::execute_user_function (octave_user_function& user_function,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2323 int nargout,
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2324 const octave_value_list& xargs,
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2325 stack_frame *closure_frames)
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2326 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2327 octave_value_list retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2328
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2329 tree_statement_list *cmd_list = user_function.body ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2330
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2331 if (! cmd_list)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2332 return retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2333
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2334 // If this function is a classdef constructor, extract the first input
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2335 // argument, which must be the partially constructed object instance.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2336
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2337 octave_value_list args (xargs);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2338 octave_value_list ret_args;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2339
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2340 if (user_function.is_classdef_constructor ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2341 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2342 if (args.length () > 0)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2343 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2344 ret_args = args.slice (0, 1, true);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2345 args = args.slice (1, args.length () - 1, true);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2346 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2347 else
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2348 panic_impossible ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2349 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2350
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2351 #if defined (HAVE_LLVM)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2352 if (user_function.is_special_expr ()
26004
94fecd437d9c * pt-eval.cc: Fix call to JIT evaluate function.
John W. Eaton <jwe@octave.org>
parents: 25789
diff changeset
2353 && tree_jit::execute (user_function, args, retval))
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2354 return retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2355 #endif
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2356
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2357 unwind_protect frame;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2358
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2359 if (m_call_stack.size () >= static_cast<size_t> (m_max_recursion_depth))
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2360 error ("max_recursion_depth exceeded");
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2361
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2362 // Save old and set current symbol table context, for
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2363 // eval_undefined_error().
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2364
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2365 m_call_stack.push (&user_function, &frame, closure_frames);
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2366
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2367 frame.add_method (m_call_stack, &call_stack::pop);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2368
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2369 bind_auto_fcn_vars (xargs.name_tags (), args.length (),
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
2370 nargout, user_function.takes_varargs (),
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
2371 user_function.all_va_args (args));
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2372
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2373 if (user_function.is_anonymous_function ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2374 init_local_fcn_vars (user_function);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2375
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2376 tree_parameter_list *param_list = user_function.parameter_list ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2377
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2378 if (param_list && ! param_list->varargs_only ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2379 define_parameter_list_from_arg_vector (param_list, args);
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2380
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2381 // For classdef constructor, pre-populate the output arguments
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2382 // with the pre-initialized object instance, extracted above.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2383
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2384 tree_parameter_list *ret_list = user_function.return_list ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2385
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2386 if (user_function.is_classdef_constructor ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2387 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2388 if (! ret_list)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2389 error ("%s: invalid classdef constructor, no output argument defined",
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2390 user_function.dispatch_class ().c_str ());
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2391
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2392 define_parameter_list_from_arg_vector (ret_list, ret_args);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2393 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2394
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2395 // Force parameter list to be undefined when this function exits.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2396 // Doing so decrements the reference counts on the values of local
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2397 // variables that are also named function parameters.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2398
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2399 // if (param_list)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2400 // frame.add_method (this, &tree_evaluator::undefine_parameter_list,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2401 // param_list);
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2402
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2403 // Force return list to be undefined when this function exits.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2404 // Doing so decrements the reference counts on the values of local
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2405 // variables that are also named values returned by this function.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2406
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2407 // if (ret_list)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2408 // frame.add_method (this, &tree_evaluator::undefine_parameter_list,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2409 // ret_list);
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2410
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2411 frame.add_method (&user_function,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2412 &octave_user_function::restore_warning_states);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2413
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2414 // Evaluate the commands that make up the function.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2415
25401
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2416 frame.protect_var (m_statement_context);
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2417 m_statement_context = SC_FUNCTION;
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2418
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2419 frame.add_method (m_call_stack, &call_stack::clear_current_frame_values);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2420
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2421 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2422 profiler::enter<octave_user_function> block (m_profiler, user_function);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2423
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2424 if (echo ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2425 push_echo_state (frame, tree_evaluator::ECHO_FUNCTIONS,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2426 user_function.fcn_file_name ());
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2427
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2428 if (user_function.is_special_expr ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2429 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2430 assert (cmd_list->length () == 1);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2431
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2432 tree_statement *stmt = cmd_list->front ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2433
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2434 tree_expression *expr = stmt->expression ();
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2435
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2436 if (expr)
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2437 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2438 m_call_stack.set_location (stmt->line (), stmt->column ());
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2439
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
2440 retval = expr->evaluate_n (*this, nargout);
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2441 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2442 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2443 else
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2444 cmd_list->accept (*this);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2445 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2446
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2447 if (m_returning)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2448 m_returning = 0;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2449
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2450 if (m_breaking)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2451 m_breaking--;
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2452
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2453 // Copy return values out.
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2454
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2455 if (ret_list && ! user_function.is_special_expr ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2456 {
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2457 Cell varargout;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2458
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2459 if (ret_list->takes_varargs ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2460 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2461 octave_value varargout_varval = varval ("varargout");
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2462
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2463 if (varargout_varval.is_defined ())
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2464 varargout = varargout_varval.xcell_value ("varargout must be a cell array object");
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2465 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2466
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2467 retval = convert_return_list_to_const_vector (ret_list, nargout,
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2468 varargout);
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2469 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2470
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2471 if (user_function.is_nested_function ()
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2472 || user_function.is_parent_function ())
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2473 {
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2474 // Copy current stack frame to handles to nested functions.
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2475
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2476 for (octave_idx_type i = 0; i < retval.length (); i++)
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2477 {
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2478 octave_value val = retval(i);
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2479
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2480 if (val.is_function_handle ())
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2481 {
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2482 octave_fcn_handle *fh = val.fcn_handle_value ();
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2483
26847
8bd9fd99c12a lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
2484 if (fh)
8bd9fd99c12a lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
2485 fh->push_closure_context (*this);
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2486 }
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2487 }
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2488 }
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26769
diff changeset
2489
25400
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2490 return retval;
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2491 }
d423ce60f5c8 evaluate script and function code in tree_evaluator methods
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
2492
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2493 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2494 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
2495 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2496 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2497 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2498
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2499 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2500 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
2501 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2502 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2503 }
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 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2506 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
2507 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2508 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
2509
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2510 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
2511
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2512 if (f)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2513 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2514 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
2515
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
2516 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
2517
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23587
diff changeset
2518 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
2519
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2520 // 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
2521 // 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
2522
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2523 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
2524 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2525 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
2526
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2527 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2528 tree_evaluator::visit_identifier (tree_identifier&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2529 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2530 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2531 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2532
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2533 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2534 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
2535 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2536 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2537 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2538
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2539 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2540 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
2541 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2542 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
2543 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2544 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
2545 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
2546 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
2547 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2548
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2549 // FIXME: tree_if_command_list is not derived from tree, so should it
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2550 // really have an accept method?
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2551
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2552 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
2553
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2554 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2555 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
2556 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2557
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2558 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2559 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
2560 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
2561 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
2562 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2563 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
2564
27761
223981108144 fix stack frame location info when using debugger (bug #57315)
John W. Eaton <jwe@octave.org>
parents: 27725
diff changeset
2565 if (! (in_debug_repl ()
223981108144 fix stack frame location info when using debugger (bug #57315)
John W. Eaton <jwe@octave.org>
parents: 27725
diff changeset
2566 && m_call_stack.current_frame () == m_debug_frame))
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2567 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
2568
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2569 if (m_debug_mode && ! tic->is_else_clause ())
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2570 do_breakpoint (tic->is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2571
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2572 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
2573 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2574 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
2575
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2576 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
2577 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
2578
20784
52f6921dde09 * pt-eval.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20715
diff changeset
2579 break;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2580 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2581 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2582 }
24722
af6c1ed60581 avoid splitting namespace blocks unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24690
diff changeset
2583
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2584 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2585 tree_evaluator::visit_index_expression (tree_index_expression&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2586 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2587 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2588 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2589
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2590 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2591 tree_evaluator::visit_matrix (tree_matrix&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2592 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2593 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2594 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2595
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2596 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2597 tree_evaluator::visit_cell (tree_cell&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2598 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2599 panic_impossible ();
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2600 }
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2601
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2602 void
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2603 tree_evaluator::visit_multi_assignment (tree_multi_assignment&)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2604 {
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2605 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2606 }
13225
359153d26cc1 eliminate DO_SIMPLE_FOR_LOOP_ONCE macro
John W. Eaton <jwe@octave.org>
parents: 12833
diff changeset
2607
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2608 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2609 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
2610 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2611 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
2612 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2613 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
2614 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
2615 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
2616 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2617
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2618 if (m_debug_mode && cmd.is_end_of_fcn_or_script ())
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2619 do_breakpoint (cmd.is_active_breakpoint (*this), true);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2620 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2621
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2622 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2623 tree_evaluator::visit_constant (tree_constant&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2624 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2625 panic_impossible ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2626 }
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2627
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2628 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2629 tree_evaluator::visit_fcn_handle (tree_fcn_handle&)
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2630 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2631 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2632 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2633
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2634 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2635 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
2636 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2637 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2638 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2639
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2640 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2641 tree_evaluator::visit_postfix_expression (tree_postfix_expression&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2642 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2643 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2644 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2645
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2646 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2647 tree_evaluator::visit_prefix_expression (tree_prefix_expression&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2648 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2649 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2650 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2651
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2652 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2653 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
2654 {
23723
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 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
2658 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
2659 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
2660 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2661
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2662 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2663 do_breakpoint (cmd.is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2664
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2665 // 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
2666
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
2667 if (in_debug_repl () && m_call_stack.current_frame () == m_debug_frame)
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
2668 dbcont ();
25401
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2669 else if (m_statement_context == SC_FUNCTION
6f6479125d80 eliminate some globals from tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 25400
diff changeset
2670 || m_statement_context == SC_SCRIPT
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
2671 || m_in_loop_command)
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2672 m_returning = 1;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2673 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2674
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2675 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2676 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
2677 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2678 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2679 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2680
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2681 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2682 tree_evaluator::visit_simple_assignment (tree_simple_assignment&)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2683 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2684 panic_impossible ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2685 }
8662
af72c8137d64 improve looping over arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 8658
diff changeset
2686
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2687 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2688 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
2689 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2690 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
2691 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
2692
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2693 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
2694 {
27761
223981108144 fix stack frame location info when using debugger (bug #57315)
John W. Eaton <jwe@octave.org>
parents: 27725
diff changeset
2695 if (! (in_debug_repl ()
223981108144 fix stack frame location info when using debugger (bug #57315)
John W. Eaton <jwe@octave.org>
parents: 27725
diff changeset
2696 && m_call_stack.current_frame () == m_debug_frame))
27540
6971bc1a2f92 deprecate unecessary global variable Vtrack_line_num
John W. Eaton <jwe@octave.org>
parents: 27533
diff changeset
2697 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
2698
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2699 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2700 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2701 if (cmd)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2702 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
2703 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2704 {
23723
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 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
2708 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
2709 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
2710 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2711
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2712 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2713 do_breakpoint (expr->is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2714
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2715 // 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
2716 // 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
2717 // 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
2718 // 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
2719
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2720 // 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
2721 // 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
2722 // 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
2723
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
2724 octave_value tmp_result = expr->evaluate (*this, 0);
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2725
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2726 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
2727 {
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2728 bool do_bind_ans = false;
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2729
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2730 if (expr->is_identifier ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2731 do_bind_ans = ! is_variable (expr);
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2732 else
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
2733 do_bind_ans = ! expr->is_assignment_expression ();
24564
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2734
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2735 if (do_bind_ans)
07876b7127bf reorganize binding to ans in evaluator for clarity
John W. Eaton <jwe@octave.org>
parents: 24563
diff changeset
2736 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
2737 && 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
2738 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2739 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2740 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2741 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
2742 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2743 // 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
2744 // 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
2745 // 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
2746 // 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
2747
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2748 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
2749 "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
2750 }
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
2751 catch (const interrupt_exception&)
24583
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2752 {
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2753 // 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
2754 // 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
2755
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2756 if (m_debug_mode)
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
2757 m_interpreter.recover_from_exception ();
24583
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2758 else
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2759 throw;
466e2aab871b stay in debug mode on Control-C interrupts (bug #52750)
John W. Eaton <jwe@octave.org>
parents: 24565
diff changeset
2760 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2761 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2762 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2763
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2764 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2765 tree_evaluator::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
2766 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2767 // 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
2768 // 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
2769
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
2770 auto p = lst.begin ();
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2771
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2772 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
2773 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2774 while (true)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2775 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2776 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
2777
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2778 if (! elt)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2779 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
2780
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2781 octave_quit ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2782
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2783 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
2784
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2785 if (m_breaking || m_continuing)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2786 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2787
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2788 if (m_returning)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2789 break;
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 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
2792 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2793 else
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 // 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
2796 // 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
2797 // 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
2798 // 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
2799 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2800 // 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
2801 // # 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
2802 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2803 // 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
2804 // # 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
2805 // # 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
2806 // # 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
2807
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2808 // 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
2809 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2810 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2811 }
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2814 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2815 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
2816 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2817 panic_impossible ();
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2818 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2819
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2820 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2821 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
2822 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2823 panic_impossible ();
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
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2826 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2827 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
2828 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2829 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
2830 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2831 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
2832 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
2833 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
2834 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2835
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
2836 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
2837 do_breakpoint (cmd.is_active_breakpoint (*this));
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2838
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2839 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
2840
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2841 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2842 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
2843 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
2844
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
2845 octave_value val = expr->evaluate (*this);
22196
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 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
2848
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2849 if (lst)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2850 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23435
diff changeset
2851 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
2852 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
2853 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
2854 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2855 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
2856
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2857 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
2858 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
2859
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2860 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2861 }
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 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2864 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2865
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2866 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2867 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
2868 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2869 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
2870 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2871 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
2872 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
2873 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
2874 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
2875
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2876 bool execution_error = false;
27472
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2877 octave_scalar_map err_map;
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2878
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2879 tree_statement_list *try_code = cmd.body ();
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2880
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2881 if (try_code)
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2882 {
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2883 // unwind frame before catch block
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2884
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2885 unwind_protect frame;
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2886
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2887 interpreter_try (frame);
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2888
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2889 // The catch code is *not* added to unwind_protect stack; it
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2890 // doesn't need to be run on interrupts.
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2891
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2892 try
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2893 {
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2894 try_code->accept (*this);
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2895 }
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2896 catch (const execution_exception& ee)
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2897 {
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2898 execution_error = true;
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2899
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2900 error_system& es = m_interpreter.get_error_system ();
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2901
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2902 es.save_exception (ee);
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2903
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2904 err_map.assign ("message", es.last_error_message ());
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2905 err_map.assign ("identifier", es.last_error_id ());
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2906 err_map.assign ("stack", es.last_error_stack ());
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2907
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
2908 m_interpreter.recover_from_exception ();
27472
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2909 }
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2910
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2911 // Actions attached to unwind_protect frame will run here, prior
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2912 // to executing the catch block.
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2913 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2914
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2915 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
2916 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2917 tree_statement_list *catch_code = cmd.cleanup ();
27472
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2918
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2919 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
2920 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2921 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
2922
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2923 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
2924 {
25383
d3a035528c9a use reference to tree_evaluator instead of pointer
John W. Eaton <jwe@octave.org>
parents: 25382
diff changeset
2925 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
2926
27472
c0883bfc0f36 simplify evaluator logic for try-catch command
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
2927 ult.assign (octave_value::op_asn_eq, err_map);
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2928 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2929
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2930 // perform actual "catch" block
26451
0ab258611cc5 pt-eval.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2931 catch_code->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
2932 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2933 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2934 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2935
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2936 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2937 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
2938 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2939 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
2940
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2941 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
2942 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
2943
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2944 // 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
2945 // backtracking.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2946
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
2947 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
2948 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
2949 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
2950 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
2951
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2952 // 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
2953 // 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
2954 // 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
2955 // 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
2956
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2957 frame.protect_var (m_returning);
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2958 m_returning = 0;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2959
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2960 frame.protect_var (m_breaking);
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2961 m_breaking = 0;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2962
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2963 try
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2964 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2965 if (list)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2966 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
2967 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
2968 catch (const execution_exception& ee)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2969 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
2970 error_system& es = m_interpreter.get_error_system ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
2971
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
2972 es.save_exception (ee);
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
2973 m_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
2974
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
2975 if (m_breaking || m_returning)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2976 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
2977 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2978 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
2979
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2980 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
2981
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2982 throw;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2983 }
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
2984
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2985 // 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
2986 // 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
2987
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2988 // 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
2989 // 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
2990 // 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
2991 // 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
2992 // 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
2993 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2994 // function foo ()
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2995 // unwind_protect
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2996 // 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
2997 // break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
2998 // 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
2999 // 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
3000 // 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
3001 // return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3002 // 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
3003 // 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
3004 // endfunction
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3005 //
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3006 // 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
3007 // 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
3008 // 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
3009 // 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
3010 // 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
3011
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3012 if (m_breaking || m_returning)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3013 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
3014 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3015 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
3016 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
3017
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3018 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3019 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
3020 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3021 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
3022 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3023 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
3024 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
3025 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
3026 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3027
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3028 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
3029
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3030 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
3031
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3032 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
3033 {
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
3034 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
3035 {
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3036 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
3037 }
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
3038 catch (const execution_exception& ee)
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
3039 {
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
3040 error_system& es = m_interpreter.get_error_system ();
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
3041
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3042 // 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
3043 // 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
3044 // 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
3045 // here?
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27441
diff changeset
3046 es.save_exception (ee);
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
3047 m_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
3048
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3049 // 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
3050 // 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
3051 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
3052
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3053 // 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
3054 // 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
3055 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
3056 }
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
3057 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
3058 {
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
3059 // The comments above apply here as well.
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27472
diff changeset
3060 m_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
3061 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
3062 throw;
fecca33388f7 also run unwind protect cleanup code on interrupt exceptions (bug #51209)
John W. Eaton <jwe@octave.org>
parents: 23219
diff changeset
3063 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3064
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3065 // 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
3066 // 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
3067 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
3068 }
c34f9c182dcf Make debug_on_error to apply to the "catch" block of try/catch (bug #47685)
Rik <rik@octave.org>
parents: 21743
diff changeset
3069 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3070
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3071 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3072 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
3073 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3074 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
3075
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3076 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
3077 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3078 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
3079 line++;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3080 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3081
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3082 #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
3083 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
3084 return;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3085 #endif
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9378
diff changeset
3086
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
3087 unwind_protect_var<bool> upv (m_in_loop_command, true);
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
3088
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3089 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
3090
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3091 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3092 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3093
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3094 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3095 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3096 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
3097 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
3098
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
3099 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
3100 do_breakpoint (cmd.is_active_breakpoint (*this));
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3101
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3102 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
3103 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3104 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
3105
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3106 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
3107 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3108
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3109 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
3110 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3111 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3112 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3113 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3114 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3115 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20560
diff changeset
3116
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3117 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3118 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
3119 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3120 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
3121
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3122 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
3123 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3124 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
3125 line++;
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
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
3128 #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
3129 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
3130 return;
15023
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
3131 #endif
75d1bc2fd6d2 Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents: 14932
diff changeset
3132
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
3133 unwind_protect_var<bool> upv (m_in_loop_command, true);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3134
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3135 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
3136 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
3137 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
3138
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3139 if (! expr)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3140 panic_impossible ();
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3141
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3142 for (;;)
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3143 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3144 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
3145 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
3146
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3147 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
3148
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3149 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
3150 loop_body->accept (*this);
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3151
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3152 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
3153 break;
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3154
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25401
diff changeset
3155 if (m_debug_mode)
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
3156 do_breakpoint (cmd.is_active_breakpoint (*this));
18325
2a8243d8327a jit compiler: Add support for the do_until statement
LYH <lyh.kernel@gmail.com>
parents: 18270
diff changeset
3157
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
3158 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
3159
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3160 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
3161 break;
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3162 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3163 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3164
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3165 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3166 tree_evaluator::visit_superclass_ref (tree_superclass_ref&)
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3167 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3168 panic_impossible ();
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3169 }
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3170
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3171 void
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3172 tree_evaluator::visit_metaclass_query (tree_metaclass_query&)
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3173 {
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3174 panic_impossible ();
26686
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3175 }
581d01526b34 eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents: 26662
diff changeset
3176
23702
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3177 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
3178 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3179 static std::string ans = "ans";
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3180
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3181 if (val.is_defined ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3182 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3183 if (val.is_cs_list ())
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3184 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3185 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
3186
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3187 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
3188 bind_ans (lst(i), print);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3189 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3190 else
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3191 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3192 assign (ans, val);
23702
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3193
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3194 if (print)
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3195 {
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3196 octave_value_list args = ovl (val);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3197 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
3198 feval ("display", args);
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3199 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3200 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3201 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3202 }
d396b5fd9199 move bind_ans to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
3203
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3204 void
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3205 tree_evaluator::do_breakpoint (tree_statement& stmt)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3206 {
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
3207 do_breakpoint (stmt.is_active_breakpoint (*this),
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26094
diff changeset
3208 stmt.is_end_of_fcn_or_script ());
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3209 }
8845
5a6db6bd1a02 eigs.cc (Feigs): fix handling of sigma arg
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
3210
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3211 void
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3212 tree_evaluator::do_breakpoint (bool is_breakpoint,
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3213 bool is_end_of_fcn_or_script)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3214 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3215 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
3216
25405
df2f3af2c6c5 eliminate unused octave_debug_on_interrupt_state variable
John W. Eaton <jwe@octave.org>
parents: 25404
diff changeset
3217 if (is_breakpoint)
27233
fc668ac9ce7c re-enter debugger when doing dbstep (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27222
diff changeset
3218 break_on_this_statement = true;
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3219 else if (m_dbstep_flag > 0)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3220 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3221 if (m_call_stack.current_frame () == m_debug_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3222 {
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3223 if (m_dbstep_flag == 1 || is_end_of_fcn_or_script)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3224 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3225 // 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
3226 // 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
3227 // 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
3228 // 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
3229 // return to prompt.
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3230
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3231 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
3232 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3233 else
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3234 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3235 // 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
3236
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3237 m_dbstep_flag--;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3238 }
15574
d20cbfec6df7 Fix off-by-1 error when executing 'dbstep N'
Rik <rik@octave.org>
parents: 15469
diff changeset
3239
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3240 }
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3241 else if (m_dbstep_flag == 1
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3242 && m_call_stack.current_frame () < m_debug_frame)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3243 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3244 // 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
3245
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3246 m_debug_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
3247
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3248 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
3249 }
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3250 }
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3251 else if (m_dbstep_flag == -1)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3252 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3253 // 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
3254
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3255 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
3256
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3257 m_debug_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
3258 }
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3259 else if (m_dbstep_flag == -2)
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3260 {
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3261 // 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
3262 // 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
3263 // 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
3264 // "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
3265 // that frame.
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3266
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3267 if (is_end_of_fcn_or_script
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3268 && m_call_stack.current_frame () == m_debug_frame)
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3269 m_dbstep_flag = -1;
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3270 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3271
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3272 if (break_on_this_statement)
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25405
diff changeset
3273 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3274 m_dbstep_flag = 0;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3275
27233
fc668ac9ce7c re-enter debugger when doing dbstep (bug #56150)
John W. Eaton <jwe@octave.org>
parents: 27222
diff changeset
3276 enter_debugger ();
25407
ab10403a0b50 new input_system class to manage user input for the interpreter
John W. Eaton <jwe@octave.org>
parents: 25405
diff changeset
3277 }
22196
dd992fd74fce put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents: 22164
diff changeset
3278 }
10219
979fb2606c4f new tree_evaluator::do_keyoard function
Ryan Rusaw <rrusaw@gmail.com>
parents: 10210
diff changeset
3279
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3280 bool
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3281 tree_evaluator::is_logically_true (tree_expression *expr,
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3282 const char *warn_for)
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3283 {
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3284 bool expr_value = false;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3285
27374
d171d356767b don't apply std::move to temporary values
John W. Eaton <jwe@octave.org>
parents: 27373
diff changeset
3286 octave_value t1 = expr->evaluate (*this);
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3287
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3288 if (t1.is_defined ())
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3289 return t1.is_true ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3290 else
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3291 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
3292
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3293 return expr_value;
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23398
diff changeset
3294 }
23481
73558a835b64 eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents: 23470
diff changeset
3295
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3296 octave_value
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3297 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
3298 int nargout)
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3299 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3300 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
3301 "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
3302 }
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3303
27203
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3304 symbol_info_list
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3305 tree_evaluator::glob_symbol_info (const std::string& pattern) const
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3306 {
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3307 return m_call_stack.glob_symbol_info (pattern);
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3308 }
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3309
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3310 symbol_info_list
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3311 tree_evaluator::regexp_symbol_info (const std::string& pattern) const
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3312 {
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3313 return m_call_stack.regexp_symbol_info (pattern);
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3314 }
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3315
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3316 symbol_info_list
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3317 tree_evaluator::get_symbol_info (void)
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3318 {
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3319 return m_call_stack.get_symbol_info ();
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3320 }
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3321
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3322 symbol_info_list
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3323 tree_evaluator::top_scope_symbol_info (void) const
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3324 {
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3325 return m_call_stack.top_scope_symbol_info ();
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3326 }
79065f9d5553 eliminate direct access to call stack in load-save functions
John W. Eaton <jwe@octave.org>
parents: 27202
diff changeset
3327
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3328 octave_map tree_evaluator::get_autoload_map (void) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3329 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3330 Cell func_names (dim_vector (m_autoload_map.size (), 1));
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3331 Cell file_names (dim_vector (m_autoload_map.size (), 1));
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3332
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3333 octave_idx_type i = 0;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3334 for (const auto& fcn_fname : m_autoload_map)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3335 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3336 func_names(i) = fcn_fname.first;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3337 file_names(i) = fcn_fname.second;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3338
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3339 i++;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3340 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3341
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3342 octave_map m;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3343
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3344 m.assign ("function", func_names);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3345 m.assign ("file", file_names);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3346
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3347 return m;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3348 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3349
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3350 std::string tree_evaluator::lookup_autoload (const std::string& nm) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3351 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3352 std::string retval;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3353
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3354 auto p = m_autoload_map.find (nm);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3355
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3356 if (p != m_autoload_map.end ())
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3357 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3358 load_path& lp = m_interpreter.get_load_path ();
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3359
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3360 retval = lp.find_file (p->second);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3361 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3362
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3363 return retval;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3364 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3365
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3366 std::list<std::string> tree_evaluator::autoloaded_functions (void) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3367 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3368 std::list<std::string> names;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3369
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3370 for (const auto& fcn_fname : m_autoload_map)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3371 names.push_back (fcn_fname.first);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3372
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3373 return names;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3374 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3375
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3376 std::list<std::string>
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3377 tree_evaluator::reverse_lookup_autoload (const std::string& nm) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3378 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3379 std::list<std::string> names;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3380
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3381 for (const auto& fcn_fname : m_autoload_map)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3382 if (nm == fcn_fname.second)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3383 names.push_back (fcn_fname.first);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3384
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3385 return names;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3386 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3387
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3388 void tree_evaluator::add_autoload (const std::string& fcn,
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3389 const std::string& nm)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3390 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3391 std::string file_name = check_autoload_file (nm);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3392
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3393 m_autoload_map[fcn] = file_name;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3394 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3395
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3396 void tree_evaluator::remove_autoload (const std::string& fcn,
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3397 const std::string& nm)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3398 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3399 check_autoload_file (nm);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3400
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3401 // Remove function from symbol table and autoload map.
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3402 symbol_table& symtab = m_interpreter.get_symbol_table ();
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3403
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3404 symtab.clear_dld_function (fcn);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3405
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3406 m_autoload_map.erase (fcn);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3407 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3408
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3409 octave_value
26087
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3410 tree_evaluator::whos_line_format (const octave_value_list& args, int nargout)
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3411 {
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3412 return set_internal_variable (m_whos_line_format, args, nargout,
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3413 "whos_line_format");
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3414 }
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3415
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3416 octave_value
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3417 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
3418 {
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3419 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
3420 "silent_functions");
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3421 }
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3422
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3423 octave_value
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3424 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
3425 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3426 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
3427 "string_fill_char");
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3428 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3429
26094
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3430 // Final step of processing an indexing error. Add the name of the
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3431 // variable being indexed, if any, then issue an error. (Will this also
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3432 // be needed by pt-lvalue, which calls subsref?)
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3433
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3434 void tree_evaluator::final_index_error (index_exception& e,
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3435 const tree_expression *expr)
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3436 {
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3437 std::string extra_message;
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3438
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3439 symbol_scope scope = get_current_scope ();
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3440
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3441 if (is_variable (expr))
26094
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3442 {
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3443 std::string var = expr->name ();
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3444
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3445 e.set_var (var);
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3446
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3447 symbol_table& symtab = m_interpreter.get_symbol_table ();
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3448
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3449 octave_value fcn = symtab.find_function (var);
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3450
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3451 if (fcn.is_function ())
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3452 {
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3453 octave_function *fp = fcn.function_value ();
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3454
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3455 if (fp && fp->name () == var)
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3456 extra_message
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3457 = " (note: variable '" + var + "' shadows function)";
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3458 }
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3459 }
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3460
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3461 std::string msg = e.message () + extra_message;
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3462
26149
242aa7b2c783 Silence unnecessary warnings about security-format (bug #55046).
Rik <rik@octave.org>
parents: 26113
diff changeset
3463 error_with_id (e.err_id (), "%s", msg.c_str ());
26094
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3464 }
8fb0df0c8772 eliminate duplicate final_index_error function
John W. Eaton <jwe@octave.org>
parents: 26087
diff changeset
3465
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3466 octave_value
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3467 tree_evaluator::do_who (int argc, const string_vector& argv,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3468 bool return_list, bool verbose)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3469 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3470 return m_call_stack.do_who (argc, argv, return_list, verbose);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3471 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 27001
diff changeset
3472
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3473 octave_value_list
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3474 tree_evaluator::make_value_list (tree_argument_list *args,
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3475 const string_vector& arg_nm,
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3476 const octave_value *object, bool rvalue)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3477 {
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3478 octave_value_list retval;
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3479
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3480 if (args)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3481 {
27373
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
3482 unwind_protect_var<const std::list<octave_lvalue> *>
25627c524ad8 where possible, use new unwind-protect classes in evaluator
John W. Eaton <jwe@octave.org>
parents: 27371
diff changeset
3483 upv (m_lvalue_list, nullptr);
27371
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3484
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3485 if (rvalue && object && args->has_magic_end ()
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3486 && object->is_undefined ())
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3487 err_invalid_inquiry_subscript ();
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3488
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3489 retval = convert_to_const_vector (args, object);
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3490 }
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3491
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3492 octave_idx_type n = retval.length ();
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3493
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3494 if (n > 0)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3495 retval.stash_name_tags (arg_nm);
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3496
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3497 return retval;
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3498 }
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3499
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3500 std::list<octave_lvalue>
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3501 tree_evaluator::make_lvalue_list (tree_argument_list *lhs)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3502 {
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3503 std::list<octave_lvalue> retval;
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3504
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3505 for (tree_expression *elt : *lhs)
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3506 retval.push_back (elt->lvalue (*this));
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3507
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3508 return retval;
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3509 }
fcaecdbc8d8a don't use visitor pattern for expression evaluation (bug #56752)
John W. Eaton <jwe@octave.org>
parents: 27370
diff changeset
3510
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3511 void
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3512 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
3513 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
3514 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3515 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3516 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
3517
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3518 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
3519 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3520
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3521 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3522 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
3523 size_t pos)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3524 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3525 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
3526 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
3527 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
3528 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3529
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3530 void
25653
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3531 tree_evaluator::uwp_set_echo_state (bool state, const std::string& file_name,
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3532 size_t pos)
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3533 {
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3534 m_echo_state = state;
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3535 m_echo_file_name = file_name;
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3536 m_echo_file_pos = pos;
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3537 }
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3538
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3539 void
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3540 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
3541 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3542 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
3543
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3544 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
3545 {
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3546 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
3547
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3548 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
3549
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3550 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
3551
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3552 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
3553
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3554 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
3555 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3556 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3557
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3558 void
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3559 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
3560 {
25653
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3561 frame.add_method (this, &tree_evaluator::uwp_set_echo_state,
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25483
diff changeset
3562 m_echo_state, m_echo_file_name, m_echo_file_pos);
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3563 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3564
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3565 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
3566 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3567 // 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
3568 // the top of the call stack. If the caller of ECHO is a
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3569 // user-defined function or script, then set up unwind-protect
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3570 // 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
3571
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3572 unwind_protect *frame = m_call_stack.curr_fcn_unwind_protect_frame ();
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3573
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3574 if (frame)
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3575 {
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3576 push_echo_state_cleanup (*frame);
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25393
diff changeset
3577 return true;
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3578 }
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3579
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3580 return false;
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
3581 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3582
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3583
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3584 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3585 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
3586 {
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3587 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
3588
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3589 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
3590
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3591 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
3592 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3593 case 0:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3594 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
3595 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3596 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
3597 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
3598 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3599 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3600 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
3601 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3602
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3603 case 1:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3604 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3605 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
3606
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3607 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
3608 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
3609 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
3610 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
3611 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3612 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3613 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
3614 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
3615
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3616 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
3617 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
3618
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3619 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
3620 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3621 // 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
3622 // 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
3623
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3624 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
3625 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3626 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3627 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3628 // 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
3629
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3630 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
3631
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3632 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
3633 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3634 // 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
3635
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3636 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
3637 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
3638 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3639 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3640 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3641 // 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
3642 // 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
3643
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3644 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
3645 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3646 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3647 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3648 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3649 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3650
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3651 case 2:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3652 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3653 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
3654 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
3655
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3656 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
3657 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
3658
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3659 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
3660 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3661 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
3662 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3663 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
3664 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
3665 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3666 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3667 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3668 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
3669 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
3670
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3671 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
3672 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
3673
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3674 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
3675 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
3676 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3677 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3678 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
3679 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3680 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
3681 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3682 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
3683 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
3684 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3685 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3686 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3687 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
3688 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
3689
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3690 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
3691 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
3692
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3693 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
3694 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3695 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3696 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3697 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3698 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3699 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3700
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3701 default:
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3702 print_usage ();
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3703 break;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3704 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3705
23729
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3706 if (cleanup_pushed)
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3707 maybe_set_echo_state ();
06b3d1d54054 allow echo state to be modified from inside functions
John W. Eaton <jwe@octave.org>
parents: 23728
diff changeset
3708
23913
062ce545b21e mark octave_value from octave_value_list constructor explicit
John W. Eaton <jwe@octave.org>
parents: 23876
diff changeset
3709 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
3710 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3711
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3712 bool tree_evaluator::in_debug_repl (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3713 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3714 return (m_debugger_stack.empty ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3715 ? false : m_debugger_stack.top()->in_debug_repl ());
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3716 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3717
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3718 void tree_evaluator::dbcont (void)
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3719 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3720 if (! m_debugger_stack.empty ())
27282
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3721 m_debugger_stack.top()->dbcont ();
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3722 }
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3723
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3724 void tree_evaluator::dbquit (bool all)
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3725 {
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3726 if (! m_debugger_stack.empty ())
49c60d16866f improve dbquit and dbcont behavior
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
3727 m_debugger_stack.top()->dbquit (all);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3728 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3729
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3730 octave_value
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3731 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
3732 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3733 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
3734 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3735
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3736 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
3737 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3738 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
3739 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3740 // 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
3741 return true;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3742 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3743
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3744 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
3745 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3746 // 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
3747 // 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
3748
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3749 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
3750
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3751 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
3752 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3753 // 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
3754 // file.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3755
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3756 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
3757 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3758 else
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3759 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3760 // 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
3761
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3762 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
3763 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3764 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3765
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3766 return false;
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3767 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3768
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3769 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
3770 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3771 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
3772
23728
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3773 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
3774
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3775 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
3776 {
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3777 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
3778
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3779 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
3780
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3781 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
3782 = 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
3783
b40b7243a782 new class for caching file contents for debug and echo
John W. Eaton <jwe@octave.org>
parents: 23723
diff changeset
3784 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
3785 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
3786 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
3787 }
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
3788
25403
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3789 // Decide if it's time to quit a for or while loop.
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3790 bool tree_evaluator::quit_loop_now (void)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3791 {
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3792 octave_quit ();
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3793
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3794 // Maybe handle 'continue N' someday...
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3795
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3796 if (m_continuing)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3797 m_continuing--;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3798
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3799 bool quit = (m_returning || m_breaking || m_continuing);
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3800
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3801 if (m_breaking)
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3802 m_breaking--;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3803
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3804 return quit;
2b7d7a3f5f57 move returning, breaking, and continuing flags to evaluator
John W. Eaton <jwe@octave.org>
parents: 25402
diff changeset
3805 }
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3806
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3807 void tree_evaluator::bind_auto_fcn_vars (const string_vector& arg_names,
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3808 int nargin, int nargout,
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3809 bool takes_varargs,
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3810 const octave_value_list& va_args)
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3811 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3812 set_auto_fcn_var (stack_frame::ARG_NAMES, Cell (arg_names));
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3813 set_auto_fcn_var (stack_frame::IGNORED, ignored_fcn_outputs ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3814 set_auto_fcn_var (stack_frame::NARGIN, nargin);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3815 set_auto_fcn_var (stack_frame::NARGOUT, nargout);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3816 set_auto_fcn_var (stack_frame::SAVED_WARNING_STATES, octave_value ());
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3817
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3818 if (takes_varargs)
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3819 assign ("varargin", va_args.cell_value ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3820 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3821
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3822 void tree_evaluator::init_local_fcn_vars (octave_user_function& user_fcn)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3823 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3824 stack_frame& frame = m_call_stack.get_current_stack_frame ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3825
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3826 const octave_user_function::local_vars_map& lviv
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3827 = user_fcn.local_var_init_vals ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3828
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3829 for (const auto& nm_ov : lviv)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3830 frame.assign (nm_ov.first, nm_ov.second);
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3831 }
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3832
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3833 std::string
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3834 tree_evaluator::check_autoload_file (const std::string& nm) const
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3835 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3836 if (sys::env::absolute_pathname (nm))
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3837 return nm;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3838
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3839 std::string full_name = nm;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3840
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27019
diff changeset
3841 octave_user_code *fcn = m_call_stack.current_user_code ();
27016
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3842
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3843 bool found = false;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3844
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3845 if (fcn)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3846 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3847 std::string fname = fcn->fcn_file_name ();
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3848
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3849 if (! fname.empty ())
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3850 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3851 fname = sys::env::make_absolute (fname);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3852 fname = fname.substr (0, fname.find_last_of (sys::file_ops::dir_sep_str ()) + 1);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3853
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3854 sys::file_stat fs (fname + nm);
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3855
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3856 if (fs.exists ())
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3857 {
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3858 full_name = fname + nm;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3859 found = true;
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3860 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3861 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3862 }
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3863
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3864 if (! found)
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3865 warning_with_id ("Octave:autoload-relative-file-name",
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3866 "autoload: '%s' is not an absolute filename",
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3867 nm.c_str ());
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3868
9b261300a001 move file-scope static autoload map variable and functions to evaluator
John W. Eaton <jwe@octave.org>
parents: 27015
diff changeset
3869 return full_name;
26039
d2aae3570c81 perform automatic function variable binding in tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 26004
diff changeset
3870 }
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3871 }
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3872
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3873 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
3874 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
3875 @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
3876 @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
3877 @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
3878 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
3879 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
3880
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3881 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
3882 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
3883
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3884 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
3885 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
3886 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
3887
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24738
diff changeset
3888 @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
3889 @end deftypefn */)
10578
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3890 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3891 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
3892
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3893 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
3894 }
cb0883127251 limit on recursion via calls to source function
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3895
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3896 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3897 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3898 %! 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
3899 %! 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
3900 %! 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
3901 %! 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
3902 %! 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
3903 %! 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
3904
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
3905 %!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
3906 */
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3907
26087
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3908 DEFMETHOD (whos_line_format, interp, args, nargout,
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3909 doc: /* -*- texinfo -*-
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3910 @deftypefn {} {@var{val} =} whos_line_format ()
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3911 @deftypefnx {} {@var{old_val} =} whos_line_format (@var{new_val})
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3912 @deftypefnx {} {} whos_line_format (@var{new_val}, "local")
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3913 Query or set the format string used by the command @code{whos}.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3914
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3915 A full format string is:
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3916 @c Set example in small font to prevent overfull line
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3917
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3918 @smallexample
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3919 %[modifier]<command>[:width[:left-min[:balance]]];
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3920 @end smallexample
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3921
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3922 The following command sequences are available:
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3923
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3924 @table @code
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3925 @item %a
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26512
diff changeset
3926 Prints attributes of variables (g=global, p=persistent, f=formal parameter).
26087
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3927
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3928 @item %b
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3929 Prints number of bytes occupied by variables.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3930
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3931 @item %c
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3932 Prints class names of variables.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3933
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3934 @item %e
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3935 Prints elements held by variables.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3936
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3937 @item %n
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3938 Prints variable names.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3939
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3940 @item %s
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3941 Prints dimensions of variables.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3942
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3943 @item %t
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3944 Prints type names of variables.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3945 @end table
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3946
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3947 Every command may also have an alignment modifier:
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3948
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3949 @table @code
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3950 @item l
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3951 Left alignment.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3952
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3953 @item r
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3954 Right alignment (default).
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3955
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3956 @item c
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3957 Column-aligned (only applicable to command %s).
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3958 @end table
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3959
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3960 The @code{width} parameter is a positive integer specifying the minimum
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3961 number of columns used for printing. No maximum is needed as the field will
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3962 auto-expand as required.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3963
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3964 The parameters @code{left-min} and @code{balance} are only available when
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3965 the column-aligned modifier is used with the command @samp{%s}.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3966 @code{balance} specifies the column number within the field width which
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3967 will be aligned between entries. Numbering starts from 0 which indicates
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3968 the leftmost column. @code{left-min} specifies the minimum field width to
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3969 the left of the specified balance column.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3970
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3971 The default format is:
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3972
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3973 @qcode{" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;@xbackslashchar{}n"}
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3974
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3975 When called from inside a function with the @qcode{"local"} option, the
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3976 variable is changed locally for the function and any subroutines it calls.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3977 The original variable value is restored when exiting the function.
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3978 @seealso{whos}
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3979 @end deftypefn */)
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3980 {
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3981 octave::tree_evaluator& tw = interp.get_evaluator ();
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3982
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3983 return tw.whos_line_format (args, nargout);
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3984 }
7656fcd0ff9f move whos_line_format to evaluator
John W. Eaton <jwe@octave.org>
parents: 26065
diff changeset
3985
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
3986 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
3987 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
3988 @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
3989 @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
3990 @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
3991 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
3992 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
3993
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3994 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
3995 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
3996 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
3997
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21922
diff changeset
3998 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
3999 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
4000 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
4001 @end deftypefn */)
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4002 {
23705
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
4003 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
4004
4c597585ff52 move Vmax_recursion_depth and Vsilent_functions to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23702
diff changeset
4005 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
4006 }
12833
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4007
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4008 /*
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4009 %!test
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4010 %! orig_val = silent_functions ();
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4011 %! 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
4012 %! 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
4013 %! 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
4014 %! silent_functions (orig_val);
9f0f2c226053 codesprint: new tests for functions in pt-eval.cc
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
4015 %! 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
4016
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14294
diff changeset
4017 %!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
4018 */
23706
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4019
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4020 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
4021 doc: /* -*- texinfo -*-
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4022 @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
4023 @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
4024 @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
4025 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
4026 matrix to the same length.
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4027
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4028 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
4029 single space). For example:
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4030
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4031 @example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4032 @group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4033 string_fill_char ("X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4034 [ "these"; "are"; "strings" ]
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4035 @result{} "theseXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4036 "areXXXX"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4037 "strings"
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4038 @end group
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4039 @end example
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4040
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4041 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
4042 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
4043 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
4044 @end deftypefn */)
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4045 {
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4046 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
4047
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4048 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
4049 }
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4050
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4051 /*
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4052 ## 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
4053 ## 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
4054 %!shared orig_val, old_val
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4055 %! orig_val = string_fill_char ();
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4056 %! 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
4057 %!test
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4058 %! assert (orig_val, old_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4059 %! assert (string_fill_char (), "X");
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4060 %! 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
4061 %! string_fill_char (orig_val);
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4062 %! 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
4063
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4064 %!assert ( [ [], {1} ], {1} )
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4065
6683451b75b2 move Vstring_fill_char to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23705
diff changeset
4066 %!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
4067 */
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4068
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4069 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
4070 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4071 @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
4072 @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
4073 @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
4074 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
4075 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
4076
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4077 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
4078 @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
4079
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4080 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
4081 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
4082 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
4083 @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
4084 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4085 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4086 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
4087
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4088 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
4089 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4090
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4091 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
4092 doc: /* -*- texinfo -*-
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4093 @deftypefn {} {} echo
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4094 @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
4095 @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
4096 @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
4097 @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
4098 @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
4099 @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
4100 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
4101
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4102 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
4103
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4104 @table @code
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4105 @item on
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4106 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
4107
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4108 @item off
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4109 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
4110
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4111 @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
4112 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
4113 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4114
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4115 @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
4116 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
4117 functions.
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4118
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4119 @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
4120 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
4121
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4122 @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
4123 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
4124 @end table
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4125
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4126 @noindent
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4127 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
4128
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4129 @seealso{PS4}
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4130 @end deftypefn */)
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4131 {
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4132 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
4133
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4134 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
4135 }
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4136
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4137 /*
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4138 %!error echo ([])
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4139 %!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
4140 %!error echo ("")
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23706
diff changeset
4141 %!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
4142 %!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
4143 %!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
4144 %!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
4145 */