GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "call-stack.h"
28 #include "error.h"
29 #include "errwarn.h"
30 #include "interpreter-private.h"
31 #include "interpreter.h"
32 #include "ov-builtin.h"
33 #include "ov.h"
34 #include "ovl.h"
35 #include "profiler.h"
36 #include "unwind-prot.h"
37 
38 
40  "built-in function",
41  "built-in function");
42 
45  const octave_value_list& args)
46 {
48 
49  if (args.has_magic_colon ())
50  error ("invalid use of colon in function argument list");
51 
53 
54  octave::call_stack& cs = octave::__get_call_stack__ ("octave_builtin::call");
55 
56  cs.push (this);
57 
59 
60  octave::profiler& profiler = tw.get_profiler ();
61 
62  octave::profiler::enter<octave_builtin> block (profiler, *this);
63 
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  }
73 
74  // Do not allow null values to be returned from functions.
75  // FIXME: perhaps true builtins should be allowed?
76 
77  retval.make_storable_values ();
78 
79  // Fix the case of a single undefined value.
80  // This happens when a compiled function uses
81  //
82  // octave_value retval;
83  //
84  // instead of
85  //
86  // octave_value_list retval;
87  //
88  // the idiom is very common, so we solve that here.
89 
90  if (retval.length () == 1 && retval.xelem (0).is_undefined ())
91  retval.clear ();
92 
93  return retval;
94 }
95 
98 {
99  return jtype;
100 }
101 
102 void
104 {
105  jtype = &type;
106 }
107 
110 {
111  return f;
112 }
113 
116 {
117  return m;
118 }
119 
120 void
122 {
123  dispatch_classes.insert (dispatch_type);
124 }
125 
126 bool
128 {
129  return dispatch_classes.find (dispatch_type) != dispatch_classes.end ();
130 }
octave::jit_type * to_jit(void) const
Definition: ov-builtin.cc:97
interpreter & __get_interpreter__(const std::string &who)
bool has_magic_colon(void) const
Definition: ovl.cc:200
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:60
void error(const char *fmt,...)
Definition: error.cc:578
void stash_jit(octave::jit_type &type)
Definition: ov-builtin.cc:103
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:180
void push(octave_function *fcn)
Definition: call-stack.cc:357
void push_dispatch_class(const std::string &dispatch_type)
Definition: ov-builtin.cc:121
octave::jit_type * jtype
Definition: ov-builtin.h:125
octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-builtin.cc:44
octave::call_stack & cs
Definition: ov-class.cc:1752
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
std::set< std::string > dispatch_classes
Definition: ov-builtin.h:122
meth method(void) const
Definition: ov-builtin.cc:115
octave_value retval
Definition: data.cc:6246
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:57
idx type
Definition: ov.cc:3114
bool handles_dispatch_class(const std::string &dispatch_type) const
Definition: ov-builtin.cc:127
fcn function(void) const
Definition: ov-builtin.cc:109
octave::unwind_protect frame
Definition: graphics.cc:12190
bool is_undefined(void) const
Definition: ov.h:526
call_stack & __get_call_stack__(const std::string &who)
void add_method(T *obj, void(T::*method)(void))
octave_idx_type length(void) const
profiler & get_profiler(void)
Definition: pt-eval.h:373
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888