GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-builtin.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 "ovl.h"
31 #include "ov-builtin.h"
32 #include "ov.h"
33 #include "profiler.h"
34 #include "interpreter.h"
35 #include "unwind-prot.h"
36 
37 
39  "built-in function",
40  "built-in function");
41 
44  const std::list<octave_value_list>& idx,
45  int nargout)
46 {
47  return octave_builtin::subsref (type, idx, nargout, 0);
48 }
49 
52  const std::list<octave_value_list>& idx,
53  int nargout,
54  const std::list<octave_lvalue>* lvalue_list)
55 {
57 
58  switch (type[0])
59  {
60  case '(':
61  {
62  int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
63 
64  retval = do_multi_index_op (tmp_nargout, idx.front (),
65  idx.size () == 1 ? lvalue_list : 0);
66  }
67  break;
68 
69  case '{':
70  case '.':
71  {
73  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
74  }
75  break;
76 
77  default:
79  }
80 
81  // FIXME: perhaps there should be an
82  // octave_value_list::next_subsref member function? See also
83  // octave_user_function::subsref.
84  //
85  // FIXME: Note that if a function call returns multiple
86  // values, and there is further indexing to perform, then we are
87  // ignoring all but the first value. Is this really what we want to
88  // do? If it is not, then what should happen for stat("file").size,
89  // for exmaple?
90 
91  if (idx.size () > 1)
92  retval = retval(0).next_subsref (nargout, type, idx);
93 
94  return retval;
95 }
96 
99 {
100  return octave_builtin::do_multi_index_op (nargout, args, 0);
101 }
102 
105  const std::list<octave_lvalue> *lvalue_list)
106 {
108 
109  if (args.has_magic_colon ())
110  error ("invalid use of colon in function argument list");
111 
113 
115 
117 
118  if (lvalue_list || curr_lvalue_list)
119  {
121  curr_lvalue_list = lvalue_list;
122  }
123 
125 
126  retval = (*f) (args, nargout);
127  // Do not allow null values to be returned from functions.
128  // FIXME: perhaps true builtins should be allowed?
129  retval.make_storable_values ();
130  // Fix the case of a single undefined value.
131  // This happens when a compiled function uses
132  // octave_value retval;
133  // instead of
134  // octave_value_list retval;
135  // the idiom is very common, so we solve that here.
136  if (retval.length () == 1 && retval.xelem (0).is_undefined ())
137  retval.clear ();
138 
140 
141  return retval;
142 }
143 
144 jit_type *
146 {
147  return jtype;
148 }
149 
150 void
152 {
153  jtype = &type;
154 }
155 
158 {
159  return f;
160 }
161 
162 const std::list<octave_lvalue> *octave_builtin::curr_lvalue_list = 0;
void stash_jit(jit_type &type)
Definition: ov-builtin.cc:151
void clear(void)
Definition: ovl.h:152
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:47
jit_type * to_jit(void) const
Definition: ov-builtin.cc:145
octave_idx_type length(void) const
Definition: ovl.h:96
jit_type * jtype
Definition: ov-builtin.h:105
void protect_var(T &var)
void error(const char *fmt,...)
Definition: error.cc:570
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:169
#define END_PROFILER_BLOCK
Definition: profiler.h:215
void make_storable_values(void)
Definition: ovl.cc:264
JNIEnv void * args
Definition: ov-java.cc:67
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
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:935
static const std::list< octave_lvalue > * curr_lvalue_list
Definition: ov-builtin.h:94
void add_fcn(void(*fcn)(void))
fcn function(void) const
Definition: ov-builtin.cc:157
bool has_magic_colon(void) const
Definition: ovl.cc:202
octave_value retval
Definition: data.cc:6294
#define panic_impossible()
Definition: error.h:40
static void push(octave_function *f, symbol_table::scope_id scope=symbol_table::current_scope(), symbol_table::context_id context=symbol_table::current_context())
Definition: call-stack.h:214
idx type
Definition: ov.cc:3129
std::string type_name(void) const
Definition: ov-builtin.h:115
octave::unwind_protect frame
Definition: graphics.cc:11584
bool is_undefined(void) const
Definition: ov.h:539
static void pop(void)
Definition: call-stack.h:313
octave_value_list do_multi_index_op(int nargout, const octave_value_list &args)
Definition: ov-builtin.cc:98
octave_value & xelem(octave_idx_type i)
Definition: ovl.h:150
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:854
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
Definition: ov.cc:1462
#define BEGIN_PROFILER_BLOCK(classname)
Definition: profiler.h:211
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-builtin.h:61