Mercurial > octave
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 |
rev | line source |
---|---|
2974 | 1 /* |
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 | 4 |
5 This file is part of Octave. | |
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 | 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 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 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 | 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" |
2974 | 25 #endif |
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 | 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 | 30 #include "interpreter-private.h" |
31 #include "interpreter.h" | |
2974 | 32 #include "ov-builtin.h" |
33 #include "ov.h" | |
23518 | 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 | 36 #include "unwind-prot.h" |
2974 | 37 |
38 | |
4612 | 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 | 42 |
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 | 46 { |
47 octave_value_list retval; | |
48 | |
5864 | 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 | 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 | 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 | 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 | 64 if (f) |
65 retval = (*f) (args, nargout); | |
66 else | |
67 { | |
68 octave::interpreter& interp | |
69 = octave::__get_interpreter__ ("octave_builtin::call"); | |
70 | |
71 retval = (*m) (interp, args, nargout); | |
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 | 93 return retval; |
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 | 97 octave_builtin::to_jit (void) const |
98 { | |
99 return jtype; | |
100 } | |
101 | |
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 | 104 { |
105 jtype = &type; | |
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 | 114 octave_builtin::meth |
115 octave_builtin::method (void) const | |
116 { | |
117 return m; | |
118 } | |
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 } |