GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-builtin.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "error.h"
31#include "errwarn.h"
32#include "interpreter-private.h"
33#include "interpreter.h"
34#include "ov-builtin.h"
35#include "ov.h"
36#include "ovl.h"
37#include "profiler.h"
38#include "unwind-prot.h"
39
40
42 "built-in function",
43 "built-in function");
44
46octave_builtin::execute (octave::tree_evaluator& tw, int nargout,
47 const octave_value_list& args)
48{
49 octave_value_list retval;
50
51 if (args.has_magic_colon ())
52 error ("invalid use of colon in function argument list");
53
54 octave::profiler& profiler = tw.get_profiler ();
55
56 octave::profiler::enter<octave_builtin> block (profiler, *this);
57
58 if (m_fcn)
59 retval = (*m_fcn) (args, nargout);
60 else
61 {
62 octave::interpreter& interp
63 = octave::__get_interpreter__ ("octave_builtin::call");
64
65 retval = (*m_meth) (interp, args, nargout);
66 }
67
68 // Do not allow null values to be returned from functions.
69 // FIXME: perhaps true builtins should be allowed?
70
71 retval.make_storable_values ();
72
73 // Fix the case of a single undefined value.
74 // This happens when a compiled function uses
75 //
76 // octave_value retval;
77 //
78 // instead of
79 //
80 // octave_value_list retval;
81 //
82 // the idiom is very common, so we solve that here.
83
84 if (retval.length () == 1 && retval.xelem (0).is_undefined ())
85 retval.clear ();
86
87 return retval;
88}
89
92{
93 return m_fcn;
94}
95
98{
99 return m_meth;
100}
101
102void
103octave_builtin::push_dispatch_class (const std::string& dispatch_type)
104{
105 m_dispatch_classes.insert (dispatch_type);
106}
107
108bool
109octave_builtin::handles_dispatch_class (const std::string& dispatch_type) const
110{
111 return m_dispatch_classes.find (dispatch_type) != m_dispatch_classes.end ();
112}
bool handles_dispatch_class(const std::string &dispatch_type) const
Definition: ov-builtin.cc:109
std::set< std::string > m_dispatch_classes
Definition: ov-builtin.h:120
octave_value_list execute(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-builtin.cc:46
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:62
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:59
fcn function(void) const
Definition: ov-builtin.cc:91
meth method(void) const
Definition: ov-builtin.cc:97
void push_dispatch_class(const std::string &dispatch_type)
Definition: ov-builtin.cc:103
void make_storable_values(void)
Definition: ovl.cc:277
octave_idx_type length(void) const
Definition: ovl.h:113
void clear(void)
Definition: ovl.h:173
octave_value & xelem(octave_idx_type i)
Definition: ovl.h:171
bool has_magic_colon(void) const
Definition: ovl.cc:215
bool is_undefined(void) const
Definition: ov.h:640
void error(const char *fmt,...)
Definition: error.cc:980
interpreter & __get_interpreter__(const std::string &who)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:222