Mercurial > hg > octave-nkf
changeset 3005:fd2080b2800e
[project @ 1997-05-24 17:37:39 by jwe]
author | jwe |
---|---|
date | Sat, 24 May 1997 17:38:55 +0000 |
parents | 9a54159563de |
children | 8afe3bf4c449 |
files | src/defun-int.h src/defun.cc src/defun.h src/load-save.cc src/oct-lvalue.h src/variables.cc src/variables.h |
diffstat | 7 files changed, 70 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/defun-int.h +++ b/src/defun-int.h @@ -101,9 +101,10 @@ // How builtin variables are actually installed. -#define DEFVAR_INTERNAL(name, sname, defn, inst_as_fcn, protect, sv_fcn, doc) \ +#define DEFVAR_INTERNAL(name, sname, defn, inst_as_fcn, protect, \ + chg_fcn, doc) \ install_builtin_variable (name, octave_value (defn), inst_as_fcn, \ - protect, (sv_fcn != 0), sv_fcn, doc) + protect, (chg_fcn != 0), chg_fcn, doc) // How mapper functions are actually installed.
--- a/src/defun.cc +++ b/src/defun.cc @@ -95,18 +95,18 @@ void install_builtin_variable (const string& name, const octave_value& value, bool install_as_function, bool protect, - bool eternal, void *sv_fcn_arg, + bool eternal, void *chg_fcn_arg, const string& help_string) { - symbol_record::sv_function sv_fcn - = static_cast<symbol_record::sv_function> (sv_fcn_arg); + symbol_record::change_function chg_fcn + = static_cast<symbol_record::change_function> (chg_fcn_arg); if (install_as_function) install_builtin_variable_as_function (name, value, protect, eternal, help_string); else bind_builtin_variable (name, value, protect, eternal, - sv_fcn, help_string); + chg_fcn, help_string); } void
--- a/src/defun.h +++ b/src/defun.h @@ -46,34 +46,34 @@ // clear the variable. Most builtin variables are eternal, and // cannot be cleared. // -// sv_fcn is a pointer to a function that should be called whenever +// chg_fcn is a pointer to a function that should be called whenever // this variable is given a new value. It can be 0 if there is no // function to call. See also the code in user-prefs.cc. // // doc is the simple help text for this variable. -#define DEFVAR(name, defn, inst_as_fcn, sv_fcn, doc) \ - DEFVAR_INTERNAL (#name, SBV_ ## name, defn, inst_as_fcn, 0, sv_fcn, doc) +#define DEFVAR(name, defn, inst_as_fcn, chg_fcn, doc) \ + DEFVAR_INTERNAL (#name, SBV_ ## name, defn, inst_as_fcn, 0, chg_fcn, doc) // Define a builtin-constant, and a corresponding variable that can be // redefined. This is just the same as DEFVAR, except that it defines // `name' as a variable, and `__name__' as a constant that cannot be // redefined. -#define DEFCONST(name, defn, inst_as_fcn, sv_fcn, doc) \ +#define DEFCONST(name, defn, inst_as_fcn, chg_fcn, doc) \ DEFVAR_INTERNAL (#name, SBV_ ## name, defn, inst_as_fcn, false, \ - sv_fcn, doc); \ + chg_fcn, doc); \ DEFVAR_INTERNAL ("__" ## #name ## "__", XSBV_ ## name, defn, false, \ - true, sv_fcn, doc) + true, chg_fcn, doc) // This one can be used when `name' cannot be used directly (if it is // already defined as a macro). In that case, name is already a // quoted string, and the name of the structure has to be passed too. -#define DEFCONSTX(name, sname, defn, inst_as_fcn, sv_fcn, doc) \ - DEFVAR_INTERNAL (name, sname, defn, inst_as_fcn, false, sv_fcn, doc); \ +#define DEFCONSTX(name, sname, defn, inst_as_fcn, chg_fcn, doc) \ + DEFVAR_INTERNAL (name, sname, defn, inst_as_fcn, false, chg_fcn, doc); \ DEFVAR_INTERNAL ("__" ## name ## "__", X ## sname, defn, false, true, \ - sv_fcn, doc) + chg_fcn, doc) // Define a builtin function. //
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -78,6 +78,27 @@ LS_UNKNOWN, }; +// Return nonzero if S is a valid identifier. + +static bool +valid_identifier (const char *s) +{ + if (! s || ! (isalnum (*s) || *s == '_')) + return false; + + while (*++s != '\0') + if (! (isalnum (*s) || *s == '_')) + return false; + + return true; +} + +static bool +valid_identifier (const string& s) +{ + return valid_identifier (s.c_str ()); +} + // XXX FIXME XXX -- shouldn't this be implemented in terms of other // functions that are already available?
--- a/src/oct-lvalue.h +++ b/src/oct-lvalue.h @@ -36,11 +36,11 @@ { public: - octave_lvalue (octave_value *v = 0, symbol_record::sv_function f = 0) + octave_lvalue (octave_value *v = 0, symbol_record::change_function f = 0) : val (v), idx (), chg_fcn (f), struct_elt_name () { } octave_lvalue (octave_value *v, const string& nm, - symbol_record::sv_function f = 0) + symbol_record::change_function f = 0) : val (v), idx (), chg_fcn (f), struct_elt_name (nm) { } octave_lvalue (const octave_lvalue& vr) @@ -102,7 +102,7 @@ octave_value_list idx; - symbol_record::sv_function chg_fcn; + symbol_record::change_function chg_fcn; string struct_elt_name; };
--- a/src/variables.cc +++ b/src/variables.cc @@ -117,10 +117,10 @@ initialize_symbol_tables (void) { if (! global_sym_tab) - global_sym_tab = new symbol_table (); + global_sym_tab = new symbol_table (2048); if (! top_level_sym_tab) - top_level_sym_tab = new symbol_table (); + top_level_sym_tab = new symbol_table (4096); curr_sym_tab = top_level_sym_tab; } @@ -1512,7 +1512,7 @@ void bind_builtin_variable (const string& varname, const octave_value& val, bool protect, bool eternal, - symbol_record::sv_function sv_fcn, + symbol_record::change_function chg_fcn, const string& help) { symbol_record *sr = global_sym_tab->lookup (varname, true); @@ -1528,8 +1528,8 @@ // variable function only if it knows about it, and it needs to, so // that user prefs can be properly initialized. - if (sv_fcn) - sr->set_sv_function (sv_fcn); + if (chg_fcn) + sr->set_change_function (chg_fcn); sr->define_builtin_var (val); @@ -1788,6 +1788,30 @@ return retval; } +DEFUN (__dump_symtab_info__, args, , + "__dump_symtab_info__ (): print raw symbol table statistices") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin == 1) + { + string arg = args(0).string_value (); + + if (arg == "global") + global_sym_tab->print_stats (); + else + print_usage ("__dump_symtab_info__"); + } + else if (nargin == 0) + curr_sym_tab->print_stats (); + else + print_usage ("__dump_symtab_info__"); + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/src/variables.h +++ b/src/variables.h @@ -101,7 +101,7 @@ extern void bind_builtin_variable (const string&, const octave_value&, bool protect = false, bool eternal = false, - symbol_record::sv_function f = 0, + symbol_record::change_function f = 0, const string& help = string ()); // Symbol table for symbols at the top level.