Mercurial > octave
annotate libinterp/operators/op-class.cc @ 23599:5cb3a2bb5e1e
don't use singleton for symbol_table
This is the first of a series of changes to make the symbol table a
part of the interpreter instead of a global object. These changes
also aim to simplify the implementation of symbol table so that it is
easier to understand and modify.
* Functions now own their scope (workspace) data.
* The list of subfunctions is contained in the scope rather than a
global list.
* symtab.h, symtab.cc (class symbol_table): Don't use singleton
pattern.
* interpreter.h, interpreter.cc (interpreter::m_symbol_table): New
data member.
(interpreter::~interpreter): Don't set instance to 0.
* interpreter-private.h, interpreter-private.cc
(__get_symbol_table__): New function.
Change all uses of call_stack to access call_stack object from the
interpreter.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Jun 2017 02:21:28 -0400 |
parents | 0c468af9dc00 |
children | b9378eff6d13 |
rev | line source |
---|---|
7338 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2007-2017 John W. Eaton |
7338 | 4 |
5 This file is part of Octave. | |
6 | |
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 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
7338 | 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. |
7338 | 16 |
17 You should have received a copy of the GNU General Public License | |
7444 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
7338 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
7338 | 25 #endif |
26 | |
27 #include "oct-time.h" | |
28 | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
29 #include "errwarn.h" |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
30 #include "interpreter-private.h" |
7338 | 31 #include "load-path.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20833
diff
changeset
|
32 #include "ovl.h" |
7338 | 33 #include "ov.h" |
34 #include "ov-class.h" | |
35 #include "ov-typeinfo.h" | |
36 #include "ops.h" | |
37 #include "symtab.h" | |
38 #include "parse.h" | |
39 | |
40 // class ops. | |
41 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
42 #define DEF_CLASS_UNOP(name) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
43 static octave_value \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
44 oct_unop_ ## name (const octave_value& a) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
45 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
46 octave_value retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
47 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
48 std::string class_name = a.class_name (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
49 \ |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
50 symbol_table& symtab = octave::__get_symbol_table__ ("oct_unop_" #name); \ |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
51 \ |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
52 octave_value meth = symtab.find_method (#name, class_name); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
53 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
54 if (meth.is_undefined ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
55 error ("%s method not defined for %s class", #name, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
56 class_name.c_str ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
57 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
58 octave_value_list args; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
59 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
60 args(0) = a; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
61 \ |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
62 octave_value_list tmp = octave::feval (meth.function_value (), args, 1); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
63 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
64 if (tmp.length () > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
65 retval = tmp(0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
66 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
67 return retval; \ |
7338 | 68 } |
69 | |
70 DEF_CLASS_UNOP (not) | |
71 DEF_CLASS_UNOP (uplus) | |
72 DEF_CLASS_UNOP (uminus) | |
73 DEF_CLASS_UNOP (transpose) | |
74 DEF_CLASS_UNOP (ctranspose) | |
75 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 // FIXME: we need to handle precedence in the binop function. |
7338 | 77 |
78 #define DEF_CLASS_BINOP(name) \ | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
79 static octave_value \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
80 oct_binop_ ## name (const octave_value& a1, const octave_value& a2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
81 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
82 octave_value retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
83 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
84 std::string dispatch_type \ |
23587
0c468af9dc00
maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
85 = (a1.isobject () ? a1.class_name () : a2.class_name ()); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
86 \ |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
87 symbol_table& symtab = octave::__get_symbol_table__ ("oct_unop_" #name); \ |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
88 \ |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23587
diff
changeset
|
89 octave_value meth = symtab.find_method (#name, dispatch_type); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
90 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
91 if (meth.is_undefined ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
92 error ("%s method not defined for %s class", #name, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
93 dispatch_type.c_str ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
94 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
95 octave_value_list args; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
96 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
97 args(1) = a2; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
98 args(0) = a1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
99 \ |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
100 octave_value_list tmp = octave::feval (meth.function_value (), args, 1); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
101 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
102 if (tmp.length () > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
103 retval = tmp(0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
104 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
105 return retval; \ |
7338 | 106 } |
107 | |
108 DEF_CLASS_BINOP (plus) | |
109 DEF_CLASS_BINOP (minus) | |
110 DEF_CLASS_BINOP (mtimes) | |
111 DEF_CLASS_BINOP (mrdivide) | |
112 DEF_CLASS_BINOP (mpower) | |
113 DEF_CLASS_BINOP (mldivide) | |
114 DEF_CLASS_BINOP (lt) | |
115 DEF_CLASS_BINOP (le) | |
116 DEF_CLASS_BINOP (eq) | |
117 DEF_CLASS_BINOP (ge) | |
118 DEF_CLASS_BINOP (gt) | |
119 DEF_CLASS_BINOP (ne) | |
120 DEF_CLASS_BINOP (times) | |
121 DEF_CLASS_BINOP (rdivide) | |
122 DEF_CLASS_BINOP (power) | |
123 DEF_CLASS_BINOP (ldivide) | |
124 DEF_CLASS_BINOP (and) | |
125 DEF_CLASS_BINOP (or) | |
126 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
127 #define INSTALL_CLASS_UNOP(op, f) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
128 octave_value_typeinfo::register_unary_class_op \ |
7338 | 129 (octave_value::op, oct_unop_ ## f) |
130 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
131 #define INSTALL_CLASS_BINOP(op, f) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
132 octave_value_typeinfo::register_binary_class_op \ |
7338 | 133 (octave_value::op, oct_binop_ ## f) |
134 | |
135 void | |
136 install_class_ops (void) | |
137 { | |
138 INSTALL_CLASS_UNOP (op_not, not); | |
139 INSTALL_CLASS_UNOP (op_uplus, uplus); | |
140 INSTALL_CLASS_UNOP (op_uminus, uminus); | |
141 INSTALL_CLASS_UNOP (op_transpose, transpose); | |
142 INSTALL_CLASS_UNOP (op_hermitian, ctranspose); | |
143 | |
144 INSTALL_CLASS_BINOP (op_add, plus); | |
145 INSTALL_CLASS_BINOP (op_sub, minus); | |
146 INSTALL_CLASS_BINOP (op_mul, mtimes); | |
147 INSTALL_CLASS_BINOP (op_div, mrdivide); | |
148 INSTALL_CLASS_BINOP (op_pow, mpower); | |
149 INSTALL_CLASS_BINOP (op_ldiv, mldivide); | |
150 INSTALL_CLASS_BINOP (op_lt, lt); | |
151 INSTALL_CLASS_BINOP (op_le, le); | |
152 INSTALL_CLASS_BINOP (op_eq, eq); | |
153 INSTALL_CLASS_BINOP (op_ge, ge); | |
154 INSTALL_CLASS_BINOP (op_gt, gt); | |
155 INSTALL_CLASS_BINOP (op_ne, ne); | |
156 INSTALL_CLASS_BINOP (op_el_mul, times); | |
157 INSTALL_CLASS_BINOP (op_el_div, rdivide); | |
158 INSTALL_CLASS_BINOP (op_el_pow, power); | |
159 INSTALL_CLASS_BINOP (op_el_ldiv, ldivide); | |
160 INSTALL_CLASS_BINOP (op_el_and, and); | |
161 INSTALL_CLASS_BINOP (op_el_or, or); | |
162 } |