25 #if defined (HAVE_CONFIG_H) 97 error (
"handles to nested functions are not yet supported");
102 const std::list<octave_value_list>& idx,
121 error (
"%s cannot be indexed with %c", tnm.c_str (),
type[0]);
163 str_ov_map::iterator it =
overloads.find (dispatch_type);
172 std::list<std::string> plist
175 std::list<std::string>::const_iterator pit = plist.begin ();
177 while (pit != plist.end ())
210 error (
"%s: no method for class %s",
211 nm.c_str (), dispatch_type.c_str ());
219 error (
"%s: no longer valid function handle",
nm.c_str ());
243 str_ov_map::const_iterator iter =
overloads.begin ();
244 str_ov_map::const_iterator hiter =
h.overloads.begin ();
246 retval = (iter->first == hiter->first)
247 && (iter->second.is_copy_of (hiter->second));
257 if (octaveroot.length () != 0
258 && fpath.length () >= octaveroot.length ()
259 && fpath.substr (0, octaveroot.length ()) == octaveroot
265 + fpath.substr (octaveroot.length ()));
278 error (
"function handle points to non-existent function");
285 std::list<std::string>
names;
305 error (
"function handle points to non-existent function");
312 if (fpath.length () > 0)
322 error (
"function handle points to non-existent function");
334 error (
"function handle points to non-existent function");
354 std::list<octave::symbol_record>
vars;
365 size_t varlen =
vars.size ();
369 os <<
"# length: " << varlen <<
"\n";
371 for (
const auto& symrec :
vars)
374 symrec.
name (),
false, 0))
386 os <<
"# path: " << fnm <<
"\n";
403 if (parse_status == 0)
435 std::streampos pos =
is.tellg ();
437 if (octaveroot.empty ())
502 error (
"load: failed to load anonymous function handle");
520 success =
set_fcn (octaveroot, fpath);
530 std::ostringstream nmbuf;
535 std::list<octave::symbol_record>
vars;
546 size_t varlen =
vars.size ();
549 nmbuf <<
nm <<
' ' << varlen;
554 int32_t
tmp = buf_str.length ();
555 os.
write (reinterpret_cast<char *> (&
tmp), 4);
556 os.
write (buf_str.c_str (), buf_str.length ());
558 std::ostringstream buf;
561 tmp = stmp.length ();
562 os.
write (reinterpret_cast<char *> (&
tmp), 4);
563 os.
write (stmp.c_str (), stmp.length ());
567 for (
const auto& symrec :
vars)
577 std::ostringstream nmbuf;
585 int32_t
tmp = buf_str.length ();
586 os.
write (reinterpret_cast<char *> (&
tmp), 4);
587 os.
write (buf_str.c_str (), buf_str.length ());
600 if (!
is.read (reinterpret_cast<char *> (&
tmp), 4))
608 is.read (ctmp1,
tmp);
621 if (
nm.length () > anl)
623 std::istringstream nm_is (
nm.substr (anl));
625 nm =
nm.substr (0, anl);
628 if (!
is.read (reinterpret_cast<char *> (&
tmp), 4))
636 is.read (ctmp2,
tmp);
670 error (
"load: failed to load anonymous function handle");
686 if (
nm.find_first_of (
'\n') != std::string::npos)
688 size_t pos1 =
nm.find_first_of (
'\n');
689 size_t pos2 =
nm.find_first_of (
'\n', pos1 + 1);
690 octaveroot =
nm.substr (pos1 + 1, pos2 - pos1 - 1);
691 fpath =
nm.substr (pos2 + 1);
692 nm =
nm.substr (0, pos1);
695 success =
set_fcn (octaveroot, fpath);
705 #if defined (HAVE_HDF5) 709 hid_t group_hid = -1;
710 #if defined (HAVE_HDF5_18) 714 group_hid = H5Gcreate (loc_id,
name, 0);
719 hid_t space_hid, data_hid, type_hid;
720 space_hid = data_hid = type_hid = -1;
723 type_hid = H5Tcopy (H5T_C_S1);
724 H5Tset_size (type_hid,
nm.length () + 1);
727 H5Gclose (group_hid);
734 space_hid = H5Screate_simple (0 , hdims,
nullptr);
738 H5Gclose (group_hid);
741 #if defined (HAVE_HDF5_18) 742 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
746 data_hid = H5Dcreate (group_hid,
"nm", type_hid, space_hid,
753 H5Sclose (space_hid);
755 H5Gclose (group_hid);
762 std::ostringstream buf;
767 H5Tset_size (type_hid, stmp.length () + 1);
770 H5Sclose (space_hid);
771 H5Gclose (group_hid);
775 #if defined (HAVE_HDF5_18) 776 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
780 data_hid = H5Dcreate (group_hid,
"fcn", type_hid, space_hid,
787 H5Sclose (space_hid);
789 H5Gclose (group_hid);
795 std::list<octave::symbol_record>
vars;
806 size_t varlen =
vars.size ();
810 hid_t as_id = H5Screate (H5S_SCALAR);
814 #if defined (HAVE_HDF5_18) 815 hid_t a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
820 hid_t a_id = H5Acreate (group_hid,
"SYMBOL_TABLE",
837 #if defined (HAVE_HDF5_18) 838 data_hid = H5Gcreate (group_hid,
"symbol table",
841 data_hid = H5Gcreate (group_hid,
"symbol table", 0);
845 H5Sclose (space_hid);
847 H5Gclose (group_hid);
851 for (
const auto& symrec :
vars)
867 H5Sclose (space_hid);
869 hdims[1] = octaveroot.length ();
870 space_hid = H5Screate_simple (0 , hdims,
nullptr);
874 H5Gclose (group_hid);
879 type_hid = H5Tcopy (H5T_C_S1);
880 H5Tset_size (type_hid, octaveroot.length () + 1);
881 #if defined (HAVE_HDF5_18) 882 hid_t a_id = H5Acreate (group_hid,
"OCTAVEROOT",
885 hid_t a_id = H5Acreate (group_hid,
"OCTAVEROOT",
891 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0);
897 H5Sclose (space_hid);
899 H5Gclose (group_hid);
903 H5Sclose (space_hid);
905 hdims[1] = fpath.length ();
906 space_hid = H5Screate_simple (0 , hdims,
nullptr);
910 H5Gclose (group_hid);
915 type_hid = H5Tcopy (H5T_C_S1);
916 H5Tset_size (type_hid, fpath.length () + 1);
918 #if defined (HAVE_HDF5_18) 919 a_id = H5Acreate (group_hid,
"FILE", type_hid, space_hid,
927 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0);
935 H5Sclose (space_hid);
937 H5Gclose (group_hid);
942 octave_unused_parameter (loc_id);
943 octave_unused_parameter (
name);
955 #if defined (HAVE_HDF5) 959 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id;
963 #if defined (HAVE_HDF5_18) 966 group_hid = H5Gopen (loc_id,
name);
971 #if defined (HAVE_HDF5_18) 974 data_hid = H5Dopen (group_hid,
"nm");
979 H5Gclose (group_hid);
983 type_hid = H5Dget_type (data_hid);
984 type_class_hid = H5Tget_class (type_hid);
986 if (type_class_hid != H5T_STRING)
990 H5Gclose (group_hid);
994 space_hid = H5Dget_space (data_hid);
995 rank = H5Sget_simple_extent_ndims (space_hid);
999 H5Sclose (space_hid);
1000 H5Tclose (type_hid);
1001 H5Dclose (data_hid);
1002 H5Gclose (group_hid);
1006 slen = H5Tget_size (type_hid);
1009 H5Sclose (space_hid);
1010 H5Tclose (type_hid);
1011 H5Dclose (data_hid);
1012 H5Gclose (group_hid);
1019 st_id = H5Tcopy (H5T_C_S1);
1020 H5Tset_size (st_id, slen);
1027 H5Sclose (space_hid);
1028 H5Tclose (type_hid);
1029 H5Dclose (data_hid);
1030 H5Gclose (group_hid);
1034 H5Dclose (data_hid);
1039 #if defined (HAVE_HDF5_18) 1042 data_hid = H5Dopen (group_hid,
"fcn");
1047 H5Sclose (space_hid);
1048 H5Tclose (type_hid);
1049 H5Gclose (group_hid);
1053 H5Tclose (type_hid);
1054 type_hid = H5Dget_type (data_hid);
1055 type_class_hid = H5Tget_class (type_hid);
1057 if (type_class_hid != H5T_STRING)
1059 H5Sclose (space_hid);
1060 H5Tclose (type_hid);
1061 H5Dclose (data_hid);
1062 H5Gclose (group_hid);
1066 H5Sclose (space_hid);
1067 space_hid = H5Dget_space (data_hid);
1068 rank = H5Sget_simple_extent_ndims (space_hid);
1072 H5Sclose (space_hid);
1073 H5Tclose (type_hid);
1074 H5Dclose (data_hid);
1075 H5Gclose (group_hid);
1079 slen = H5Tget_size (type_hid);
1082 H5Sclose (space_hid);
1083 H5Tclose (type_hid);
1084 H5Dclose (data_hid);
1085 H5Gclose (group_hid);
1092 st_id = H5Tcopy (H5T_C_S1);
1093 H5Tset_size (st_id, slen);
1100 H5Sclose (space_hid);
1101 H5Tclose (type_hid);
1102 H5Dclose (data_hid);
1103 H5Gclose (group_hid);
1107 H5Dclose (data_hid);
1115 H5E_auto_t err_func;
1116 void *err_func_data;
1120 #if defined (HAVE_HDF5_18) 1124 H5Eget_auto (&err_func, &err_func_data);
1125 H5Eset_auto (
nullptr,
nullptr);
1128 hid_t attr_id = H5Aopen_name (group_hid,
"SYMBOL_TABLE");
1139 #if defined (HAVE_HDF5_18) 1142 H5Eset_auto (err_func, err_func_data);
1160 cs.
push (local_scope, 0);
1163 if (len > 0 && success)
1165 hsize_t num_obj = 0;
1166 #if defined (HAVE_HDF5_18) 1169 data_hid = H5Gopen (group_hid,
"symbol table");
1171 H5Gget_num_objs (data_hid, &num_obj);
1172 H5Gclose (data_hid);
1174 if (num_obj != static_cast<hsize_t>(len))
1175 error (
"load: failed to load anonymous function handle");
1178 int current_item = 0;
1183 error (
"load: failed to load anonymous function handle");
1203 H5E_auto_t err_func;
1204 void *err_func_data;
1208 #if defined (HAVE_HDF5_18) 1212 H5Eget_auto (&err_func, &err_func_data);
1213 H5Eset_auto (
nullptr,
nullptr);
1216 hid_t attr_id = H5Aopen_name (group_hid,
"OCTAVEROOT");
1219 H5Tclose (type_hid);
1220 type_hid = H5Aget_type (attr_id);
1221 type_class_hid = H5Tget_class (type_hid);
1223 if (type_class_hid != H5T_STRING)
1227 slen = H5Tget_size (type_hid);
1228 st_id = H5Tcopy (H5T_C_S1);
1229 H5Tset_size (st_id, slen);
1232 if (H5Aread (attr_id, st_id, root_tmp) < 0)
1235 octaveroot = root_tmp;
1245 attr_id = H5Aopen_name (group_hid,
"FILE");
1248 H5Tclose (type_hid);
1249 type_hid = H5Aget_type (attr_id);
1250 type_class_hid = H5Tget_class (type_hid);
1252 if (type_class_hid != H5T_STRING)
1256 slen = H5Tget_size (type_hid);
1257 st_id = H5Tcopy (H5T_C_S1);
1258 H5Tset_size (st_id, slen);
1261 if (H5Aread (attr_id, st_id, path_tmp) < 0)
1274 #if defined (HAVE_HDF5_18) 1277 H5Eset_auto (err_func, err_func_data);
1280 success = (success ?
set_fcn (octaveroot, fpath) : success);
1283 H5Tclose (type_hid);
1284 H5Sclose (space_hid);
1285 H5Gclose (group_hid);
1290 octave_unused_parameter (loc_id);
1291 octave_unused_parameter (
name);
1424 assert (
b->length () == 1);
1430 assert (
s->is_expression ());
1463 if (len == 3 &&
nm ==
".**")
1500 else if (
nm[1] ==
'=')
1522 else if (
nm ==
"**")
1589 if (local_funcs &&
fptr 1590 && (
fptr->is_subfunction () ||
fptr->is_private_function ()
1591 ||
fptr->is_class_constructor ()
1592 ||
fptr->is_classdef_constructor ()))
1602 std::list<std::string> classes = lp.
overloads (tnm);
1603 bool any_match =
fptr !=
nullptr || classes.size () > 0;
1609 any_match = classes.size () > 0;
1613 error (
"@%s: no function and no method found", tnm.c_str ());
1618 for (
auto& cls : classes)
1623 bool is_builtin =
false;
1630 fh->set_overload (static_cast<builtin_type_t> (
i), fmeth);
1635 fh->set_overload (class_name, fmeth);
1724 if (args.length () != 1)
1732 error (
"functions: FCN_HANDLE is not a valid function handle object");
1740 std::ostringstream buf;
1742 m.
setfield (
"function", buf.str ());
1752 m.
setfield (
"type",
"subfunction");
1754 parentage.
elem (0) = fh_nm;
1772 std::list<octave::symbol_record>
vars;
1783 size_t varlen =
vars.size ();
1788 for (
const auto& symrec :
vars)
1805 DEFUN (func2str, args, ,
1813 if (args.length () != 1)
1819 error (
"func2str: FCN_HANDLE must be a valid function handle");
1827 std::ostringstream buf;
1839 DEFUN (str2func, args, ,
1850 int nargin = args.length ();
1855 std::string nm = args(0).xstring_value (
"str2func: FCN_NAME must be a string");
1865 if (parse_status == 0)
1866 retval = anon_fcn_handle;
1906 DEFUN (is_function_handle, args, ,
1913 if (args.length () != 1)
1916 return ovl (args(0).is_function_handle ());
1934 const std::vector<int>& mask,
1937 arg_mask (mask), expected_nargin (exp_nargin)
1955 cmd_list = usr_fcn->
body ();
1959 body_expr = (cmd_list->
length () == 1
1971 std::list<octave::tree_argument_list *> arg_lists = idx_expr->
arg_lists ();
1974 if (type_tags.length () == 1 && type_tags[0] ==
'(' 1977 assert (arg_lists.size () == 1);
1985 std::map<std::string, int> arginmap;
1990 for (
auto& param_p : *param_list)
1994 if (
id && !
id->is_black_hole ())
1995 arginmap[
id->name ()] = npar;
1999 if (arg_list && arg_list->
length () > 0)
2007 int nargs = arg_list->
length ();
2015 it != arg_list->
end (); ++it, ++iarg)
2027 if (arginmap.find (elt_id->
name ()) != arginmap.end ())
2054 if (head_id->is_defined (
context))
2061 if (head_name ==
"eval" || head_name ==
"feval")
2073 catch (
const octave::execution_exception&)
2086 std::list<string_vector> arg_names = idx_expr->
arg_names ();
2087 assert (arg_names.size () == 1);
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
OCTINTERP_API octave_value_list feval(const std::string &name, const octave_value_list &args=octave_value_list(), int nargout=0)
std::string read_until_newline(std::istream &is, bool keep_newline)
octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
virtual bool is_user_function(void) const
static const std::string anonymous
std::list< std::string > overloads(const std::string &meth) const
void assign(const std::string &name, const octave_value &value, bool force_add)
std::string system_path(void) const
static void recover_from_exception(void)
std::string type_name(void) const
octave_fcn_handle * fcn_handle_value(bool=false)
OCTINTERP_API void print_usage(void)
std::string dir_sep_chars(void)
int current_print_indent_level(void) const
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
const octave_hdf5_id octave_H5S_ALL
bool set_fcn(const std::string &octaveroot, const std::string &fpath)
void newline(std::ostream &os) const
static std::map< std::string, std::string > vars
std::vector< int > arg_mask
const octave_hdf5_id octave_H5E_DEFAULT
size_t length(void) const
OCTINTERP_API octave_value load_fcn_from_file(const std::string &file_name, const std::string &dir_name="", const std::string &dispatch_type="", const std::string &package_name="", const std::string &fcn_name="", bool autoload=false)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
octave::tree_statement_list * body(void)
std::string octave_exec_home(void)
void setfield(const std::string &key, const octave_value &val)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
std::list< tree_expression * >::iterator iterator
bool is_defined(void) const
static llvm::LLVMContext & context
void skip_preceeding_newline(std::istream &is)
T & elem(octave_idx_type n)
void print_fcn_handle_body(tree_expression *)
std::list< string_vector > arg_names(void)
bool load_ascii(std::istream &is)
dim_vector dims(void) const
bool save_binary(std::ostream &os, bool &save_as_floats)
bool takes_varargs(void) const
virtual std::string fcn_file_name(void) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
octave_value_list call(int nargout, const octave_value_list &args)
void push(octave_function *fcn)
std::list< std::string > parent_classes(const std::string &dispatch_type)
virtual bool is_user_script(void) const
void warn_load(const char *type) const
bool is_overloaded(void) const
octave_value make_fcn_handle(const std::string &nm, bool local_funcs)
bool parse_anon_fcn_handle(const std::string &fcn_text)
octave_fcn_binder(const octave_value &f, const octave_value &root, const octave_value_list &templ, const std::vector< int > &mask, int exp_nargin)
octave::tree_parameter_list * parameter_list(void)
octave::symbol_scope scope(void)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
bool is_subfunction(void) const
std::list< symbol_record > all_variables(bool defined_only=true, unsigned int exclude=symbol_record::hidden) const
symbol_table & __get_symbol_table__(const std::string &who)
void cache_name(const std::string &name)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
void swap_bytes< 4 >(void *ptr)
std::string fcn_name(void) const
tree_expression * expression(void)
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)
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
OCTINTERP_API octave_value_list eval_string(const std::string &, bool silent, int &parse_status, int nargout)
virtual std::string parent_fcn_name(void) const
bool save_ascii(std::ostream &os)
symbol_record::context_id current_context(void) const
std::string get_dispatch_type(const octave_value_list &args, builtin_type_t &builtin_type)
virtual bool is_subfunction(void) const
virtual bool is_index_expression(void) const
std::string btyp_class_name[btyp_num_types]
std::list< tree_argument_list * > arg_lists(void)
std::string type_tags(void)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
octave_value_list arg_template
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
octave_value builtin_overloads[btyp_num_types]
octave_user_function * user_function_value(bool silent=false) const
void warn_save(const char *type) const
octave_value find_method(const std::string &name, const std::string &dispatch_type)
bool is_function(void) const
std::string name(void) const
virtual bool is_constant(void) const
load_path & __get_load_path__(const std::string &who)
friend octave_value make_fcn_handle(const std::string &, bool)
virtual bool is_identifier(void) const
friend class octave_value
If this string is printed
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave::unwind_protect frame
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_fcn_handle * fcn_handle_value(bool silent=false) const
bool is_undefined(void) const
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
void assign(const std::string &k, const octave_value &val)
void force_assign(const std::string &name, const octave_value &value)
call_stack & __get_call_stack__(const std::string &who)
bool is_copy_of(const octave_value &val) const
bool out_of_date_check(octave_value &function, const std::string &dispatch_type, bool check_relative)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
octave_idx_type length(void) const
static octave_fcn_handle * maybe_binder(const octave_value &f, octave::tree_evaluator *tw)
symbol_scope get_current_scope(void)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
octave::sys::file_stat fs(filename)
void add_method(T *obj, void(T::*method)(void))
std::string name(void) const
octave_value evaluate(tree_expression *expr, int nargout=1)
const octave_hdf5_id octave_H5P_DEFAULT
void set_scope(const symbol_scope &sid)
void set_overload(builtin_type_t btyp, const octave_value &ov_fcn)
tree_identifier * ident(void)
bool is_nested_function(void) const
write the output to stdout if nargout is
bool is_private_function(void) const
Vector representing the dimensions (size) of an Array.
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is for polygamma functions(ar{k} higher than 0)
void print(std::ostream &os, bool pr_as_read_syntax=false)
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
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
bool is_defined(symbol_record::context_id context)
octave_function * function_value(bool=false)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
bool is_equal_to(const octave_fcn_handle &) const
OCTINTERP_API void interpreter_try(octave::unwind_protect &)
virtual octave_value_list call(int nargout, const octave_value_list &args)
tree_expression * expression(void)
void stash_name_tags(const string_vector &nm)
octave_user_function * user_function_value(bool=false)