Mercurial > octave
annotate libinterp/octave-value/ov-builtin.cc @ 28429:8eb8ba8aff9a stable
refactor octave_function call method
This change is a step toward keeping stack frames for closures
(handles to nested functions) separate from the functions themselves.
* call-stack.h, call-stack.cc
(call_stack::curr_fcn_unwind_protect_frame: No longer const.
Update all uses.
(call_stack::push): Dliminate unwind protect frame argument. Change
all uses.
* stack-frame.h, stack-frame.cc (script_stack_frame,
user_fcn_stack_frame): Create uniwnd_protect_frame only if needed.
* ov-builtin.h, ov-builtin.cc (octave_builtin::execute):
New function that executes function without pushing stack frame.
(octave_builtin::call): Delete.
* ov-class.h, ov-class.cc (octave_inline_fcn::execute):
New function.
(octave_inline_fcn::call): Call execute.
* ov-classdef.h, ov-classdef.cc (octave_classdef_meta::execute):
New function.
(octave_classdef_meta::call): Call execute.
(octave_classdef_superclass_ref::execute): New function.
(octave_classdef_superclass_ref::call): Call execute.
* ov-fcn-handle.cc (octave_fcn_handle::call): When calling a function
that has closure_frames, push stack frame here instead of inside
octave_user_function object.
* ov-fcn.h (octave_function::execute): New pure virtual function.
* ov-fcn.h, ov-fcn.cc (octave_function::call): Define only one
variant, without closure frames as an argument. Default version
simply pushes stack frame and calls execute.
* ov-mex-fcn.h, ov-mex-fcn.cc (octave_mex_function::execute):
Rename from call. Don't push stack frame here.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_script::call,
octave_user_function::call): Push stack frame and call execute.
(octave_user_script::execute, octave_user_function::execute):
New function.
* pt-eval.h, pt-eval.cc (tree_evaluator::push_stack_frame): Eliminate
unwind protect frame argument. Change all uses.
(tree_evaluator::execute_user_script): Update.
(tree_evaluator::execute_user_function): Update. Don't push stack
frame here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 30 Mar 2020 10:43:47 -0400 |
parents | bd51beb6205e |
children | 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2974 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
2974 | 28 #endif |
29 | |
30 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
31 #include "errwarn.h" |
23518 | 32 #include "interpreter-private.h" |
33 #include "interpreter.h" | |
2974 | 34 #include "ov-builtin.h" |
35 #include "ov.h" | |
23518 | 36 #include "ovl.h" |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
37 #include "profiler.h" |
4748 | 38 #include "unwind-prot.h" |
2974 | 39 |
40 | |
4612 | 41 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
42 "built-in function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
43 "built-in function"); |
2974 | 44 |
45 octave_value_list | |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
46 octave_builtin::execute (octave::tree_evaluator& tw, int nargout, |
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
47 const octave_value_list& args) |
2974 | 48 { |
49 octave_value_list retval; | |
50 | |
5864 | 51 if (args.has_magic_colon ()) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
52 error ("invalid use of colon in function argument list"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
53 |
23753
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
54 octave::profiler& profiler = tw.get_profiler (); |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
55 |
c3828bd031cd
move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
56 octave::profiler::enter<octave_builtin> block (profiler, *this); |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
57 |
23518 | 58 if (f) |
59 retval = (*f) (args, nargout); | |
60 else | |
61 { | |
62 octave::interpreter& interp | |
63 = octave::__get_interpreter__ ("octave_builtin::call"); | |
64 | |
65 retval = (*m) (interp, args, nargout); | |
66 } | |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
67 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
68 // Do not allow null values to be returned from functions. |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
69 // FIXME: perhaps true builtins should be allowed? |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
70 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
71 retval.make_storable_values (); |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
72 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
73 // Fix the case of a single undefined value. |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
74 // This happens when a compiled function uses |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
75 // |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
76 // octave_value retval; |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
77 // |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
78 // instead of |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
79 // |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
80 // octave_value_list retval; |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
81 // |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
82 // the idiom is very common, so we solve that here. |
23436
c715a1aebbd5
eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
83 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
84 if (retval.length () == 1 && retval.xelem (0).is_undefined ()) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
85 retval.clear (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
86 |
2974 | 87 return retval; |
88 } | |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
89 |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
23753
diff
changeset
|
90 octave::jit_type * |
14973 | 91 octave_builtin::to_jit (void) const |
92 { | |
93 return jtype; | |
94 } | |
95 | |
96 void | |
24239
51e408a7d38f
jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents:
23753
diff
changeset
|
97 octave_builtin::stash_jit (octave::jit_type& type) |
14973 | 98 { |
99 jtype = &type; | |
100 } | |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
101 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
102 octave_builtin::fcn |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
103 octave_builtin::function (void) const |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
104 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
105 return f; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
106 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
107 |
23518 | 108 octave_builtin::meth |
109 octave_builtin::method (void) const | |
110 { | |
111 return m; | |
112 } | |
113 | |
22897
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
114 void |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
115 octave_builtin::push_dispatch_class (const std::string& dispatch_type) |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
116 { |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
117 dispatch_classes.insert (dispatch_type); |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
118 } |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
119 |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
120 bool |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
121 octave_builtin::handles_dispatch_class (const std::string& dispatch_type) const |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
122 { |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
123 return dispatch_classes.find (dispatch_type) != dispatch_classes.end (); |
4090c32fccf8
store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
124 } |