GNU Octave  6.2.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-2021 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 
47  const octave_value_list& args)
48 {
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 (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  }
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 jtype;
94 }
95 
96 void
98 {
99  jtype = &type;
100 }
101 
104 {
105  return f;
106 }
107 
110 {
111  return m;
112 }
113 
114 void
115 octave_builtin::push_dispatch_class (const std::string& dispatch_type)
116 {
117  dispatch_classes.insert (dispatch_type);
118 }
119 
120 bool
121 octave_builtin::handles_dispatch_class (const std::string& dispatch_type) const
122 {
123  return dispatch_classes.find (dispatch_type) != dispatch_classes.end ();
124 }
T & xelem(octave_idx_type n)
Size of the specified dimension.
Definition: Array.h:469
void clear(void)
Definition: Array.cc:87
profiler & get_profiler(void)
Definition: pt-eval.h:374
octave::jit_type * to_jit(void) const
Definition: ov-builtin.cc:91
bool handles_dispatch_class(const std::string &dispatch_type) const
Definition: ov-builtin.cc:121
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::jit_type * jtype
Definition: ov-builtin.h:128
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:63
void stash_jit(octave::jit_type &type)
Definition: ov-builtin.cc:97
std::set< std::string > dispatch_classes
Definition: ov-builtin.h:125
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:60
fcn function(void) const
Definition: ov-builtin.cc:103
meth method(void) const
Definition: ov-builtin.cc:109
void push_dispatch_class(const std::string &dispatch_type)
Definition: ov-builtin.cc:115
bool has_magic_colon(void) const
Definition: ovl.cc:215
void error(const char *fmt,...)
Definition: error.cc:968
interpreter & __get_interpreter__(const std::string &who)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811