annotate libinterp/octave-value/ov-builtin.cc @ 25054:6652d3823428 stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Fri, 30 Mar 2018 09:19:05 -0400
parents 194eb4bd202b
children 00f796120a6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
1 /*
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
2
25054
6652d3823428 maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3 Copyright (C) 1996-2018 John W. Eaton
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
4
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24239
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: 24239
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.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 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.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
16
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 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: 5864
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: 24239
diff changeset
19 <https://www.gnu.org/licenses/>.
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
20
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
21 */
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
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"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
25 #endif
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
26
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
27 #include "call-stack.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
28 #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
29 #include "errwarn.h"
23518
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
30 #include "interpreter-private.h"
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
31 #include "interpreter.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
32 #include "ov-builtin.h"
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
33 #include "ov.h"
23518
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
34 #include "ovl.h"
12783
ad9263d965dc First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents: 11523
diff changeset
35 #include "profiler.h"
4748
7b145222fea3 [project @ 2004-02-07 06:27:27 by jwe]
jwe
parents: 4612
diff changeset
36 #include "unwind-prot.h"
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
37
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
38
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4247
diff changeset
39 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
40 "built-in function",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10184
diff changeset
41 "built-in function");
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
42
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
43 octave_value_list
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
44 octave_builtin::call (octave::tree_evaluator& tw, int nargout,
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23520
diff changeset
45 const octave_value_list& args)
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
46 {
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
47 octave_value_list retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
48
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5775
diff changeset
49 if (args.has_magic_colon ())
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 19697
diff changeset
50 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
51
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
52 octave::unwind_protect frame;
4987
bad4898b468e [project @ 2004-09-10 20:24:05 by jwe]
jwe
parents: 4975
diff changeset
53
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
54 octave::call_stack& cs = octave::__get_call_stack__ ("octave_builtin::call");
4975
80842ad3f85c [project @ 2004-09-08 18:37:58 by jwe]
jwe
parents: 4748
diff changeset
55
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
56 cs.push (this);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
57
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
58 frame.add_method (cs, &octave::call_stack::pop);
4748
7b145222fea3 [project @ 2004-02-07 06:27:27 by jwe]
jwe
parents: 4612
diff changeset
59
23753
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
60 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
61
c3828bd031cd move profiler inside evaluator and inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23553
diff changeset
62 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
63
23518
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
64 if (f)
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
65 retval = (*f) (args, nargout);
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
66 else
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
67 {
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
68 octave::interpreter& interp
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
69 = octave::__get_interpreter__ ("octave_builtin::call");
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
70
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
71 retval = (*m) (interp, args, nargout);
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
72 }
23436
c715a1aebbd5 eliminate remains of BEGIN_PROFILER_BLOCK and END_PROFILER_BLOCK macros
John W. Eaton <jwe@octave.org>
parents: 23433
diff changeset
73
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
74 // 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
75 // 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
76
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
77 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
78
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
79 // 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
80 // 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
81 //
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
82 // 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
83 //
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
84 // 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
85 //
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
86 // 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
87 //
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
88 // 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
89
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 20940
diff changeset
90 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
91 retval.clear ();
12960
43d78e103984 Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents: 12920
diff changeset
92
2974
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
93 return retval;
ebbc34ff7f66 [project @ 1997-05-15 19:36:16 by jwe]
jwe
parents:
diff changeset
94 }
10887
f10d0bc8f9cc make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
95
24239
51e408a7d38f jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents: 23753
diff changeset
96 octave::jit_type *
14973
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
97 octave_builtin::to_jit (void) const
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
98 {
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
99 return jtype;
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
100 }
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
101
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
102 void
24239
51e408a7d38f jit: Move everything inside the octave namespace
Julien Bect <jbect@users.sourceforge.net>
parents: 23753
diff changeset
103 octave_builtin::stash_jit (octave::jit_type& type)
14973
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
104 {
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
105 jtype = &type;
2960f1b2d6ea Add sin to JIT
Max Brister <max@2bass.com>
parents: 14138
diff changeset
106 }
10887
f10d0bc8f9cc make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
107
14974
e3cd4c9d7ccc Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents: 14973
diff changeset
108 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
109 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
110 {
e3cd4c9d7ccc Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents: 14973
diff changeset
111 return f;
e3cd4c9d7ccc Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents: 14973
diff changeset
112 }
e3cd4c9d7ccc Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents: 14973
diff changeset
113
23518
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
114 octave_builtin::meth
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
115 octave_builtin::method (void) const
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
116 {
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
117 return m;
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
118 }
8744d4ed8fb4 provide DEFMETHOD macros
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
119
22897
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
120 void
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
121 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
122 {
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
123 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
124 }
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
125
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
126 bool
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
127 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
128 {
4090c32fccf8 store set of dispatch classes in built-in function objects
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
129 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
130 }