annotate libinterp/parse-tree/oct-lvalue.h @ 26661:cf9e10ce3351

move variable values from symbol_record objects to stack_frame objects Apologies for the massive commit. I see no way to untangle these changes into a set of smaller incremental changes in a way that would be more useful. Previously, handling data for recursive function calls was managed by a stack of values in the symbol_record class and an auxiliary integer variable was used for managing the recursion depth (context_id). Now, values for local variables are in the stack_frame class and recursion is handled naturally by the call_stack as a new stack frame is added to the call_stack object for any call to a function or a script. Values for internal function call information (nargin, nargout, etc.) are now stored specially in the stack_frame object. Values for global variables are now stored in a map in the call_stack object. Values for persistent variables are stored in the corresponding octave_user_function object. Access to non-local variables inside nested functions is managed through pointers to stack_frame objects for the parent function scopes. The new implementation more closely resembles the techniques described in standard compiler literature. These changes should make it easier to create proper closures and finally solve bug #39257 (handles to nested functions are not yet supported). They may also make it easier to implement JIT compiler, though that is probably still a long way off. The new stack-frame.h file has some details about the new implementation of stack frames that should help in understanding how things work now. Describing each change to each file and function will probably not provide much greater understanding of the changes and would be quite tedious to write so I am omitting them.
author John W. Eaton <jwe@octave.org>
date Mon, 28 Jan 2019 18:01:46 +0000
parents 00f796120a6d
children 711f23332204
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
1 /*
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
3 Copyright (C) 1996-2019 John W. Eaton
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
4
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24362
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: 22407
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: 24362
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: 22407
diff changeset
10 (at your option) any later version.
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
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: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
16
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5846
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: 24362
diff changeset
19 <https://www.gnu.org/licenses/>.
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
20
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
21 */
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20248
diff changeset
23 #if ! defined (octave_oct_lvalue_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17787
diff changeset
24 #define octave_oct_lvalue_h 1
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
25
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
26 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
27
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
28 #include <string>
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
29
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20791
diff changeset
30 #include "ovl.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
31 #include "call-stack.h"
24362
3fc24b792a24 avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents: 24356
diff changeset
32 #include "symrec.h"
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
33
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
34 namespace octave
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
35 {
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
36 class octave_lvalue
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
37 {
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
38 public:
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
39
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
40 octave_lvalue (const symbol_record& sr, stack_frame& frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
41 : m_sym (sr), m_frame (frame), m_black_hole (false),
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24355
diff changeset
42 m_type (), m_idx (), m_nel (1)
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
43 { }
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
44
24991
831389905438 omit argument name from default copy ctors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
45 octave_lvalue (const octave_lvalue&) = default;
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
46
24991
831389905438 omit argument name from default copy ctors and assignment operators
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
47 octave_lvalue& operator = (const octave_lvalue&) = default;
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
48
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
49 ~octave_lvalue (void) = default;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
50
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
51 bool is_black_hole (void) const { return m_black_hole; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
52
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
53 void mark_black_hole (void) { m_black_hole = true; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
54
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
55 bool is_defined (void) const;
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
56
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
57 bool is_undefined (void) const;
10206
37a08e0ce2dc support Matlab-style empty output/input arguments
Jaroslav Hajek <highegg@gmail.com>
parents: 10160
diff changeset
58
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
59 bool isstruct (void) const { return value().isstruct (); }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
60
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
61 // OCTAVE_DEPRECATED (5, "foobar, for sure!")
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
62 void define (const octave_value& v);
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
63
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
64 void assign (octave_value::assign_op, const octave_value&);
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
65
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
66 void numel (octave_idx_type n) { m_nel = n; }
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
67
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
68 octave_idx_type numel (void) const { return m_nel; }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
69
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
70 void set_index (const std::string& t, const std::list<octave_value_list>& i);
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
71
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
72 void clear_index (void) { m_type = ""; m_idx.clear (); }
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
73
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
74 std::string index_type (void) const { return m_type; }
5846
db0598f94c0f [project @ 2006-06-07 18:16:16 by jwe]
jwe
parents: 5775
diff changeset
75
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
76 bool index_is_empty (void) const;
2984
84c33881d0bc [project @ 1997-05-16 05:14:33 by jwe]
jwe
parents: 2979
diff changeset
77
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
78 void do_unary_op (octave_value::unary_op op);
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
79
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
80 octave_value value (void) const;
20248
011a364b4d78 improve compatibility of indexed assignment (bug #43813)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
81
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
82 private:
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
83
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
84 symbol_record m_sym;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
85
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
86 stack_frame& m_frame;
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24355
diff changeset
87
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
88 bool m_black_hole;
24037
21915520ac7b use more direct method for non-local symbol access (bug #38236)
John W. Eaton <jwe@octave.org>
parents: 23693
diff changeset
89
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
90 std::string m_type;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
91
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
92 std::list<octave_value_list> m_idx;
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
93
24355
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
94 octave_idx_type m_nel;
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
95 };
cc3b3ceb155c update octave_lvalue class and move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24350
diff changeset
96 }
2979
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
97
a3556d2adec9 [project @ 1997-05-15 22:35:37 by jwe]
jwe
parents:
diff changeset
98 #endif