# HG changeset patch # User jwe # Date 932593924 0 # Node ID 4964d5391acc9d2936ace965c0bf889bc35d9154 # Parent 5e61a7a62e2e51dfe634d68e9fb8ab2a23f0a8bd [project @ 1999-07-21 21:51:33 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,48 @@ +Wed Jul 21 15:38:52 1999 John W. Eaton + + * symtab.cc (symbol_record::define, symbol_record::variable_reference): + Handle constants the same as functions. + (symbol_record::link_to_builtin_variable): New function. + (symbol_record::define_builtin_const): New function. + (symbol_record::define_as_fcn): Delete unused function. + (symbol_record::read_only_error): + Handle constants the same as variables. + * symtab.h (symbol_record::BUILTIN_CONSTANT): New enum value. + (symbol_record::symbol_type): Increase width to 7 bits. + (symbol_record::symbol_def::is_constant): New function. + (symbol_record::symbol_def::is_builtin_constant): New function. + (symbol_record::is_constant): New function. + (symbol_record::is_builtin_constant): New function. + (SYMTAB_ALL_TYPES): Add symbol_record::BUILTIN_CONSTANT. + * variables.cc (link_to_builtin_variable): Delete unused function. + (link_to_builtin_or_function): Handle built-in constants here too. + + * defun.cc (install_builtin_variable): Delete inst_as_fcn arg. + (install_builtin_constant): New function. + (install_builtin_variable_as_function): Delete unused function. + * defun.h (DEFVAR_INTERNAL): Delete inst_as_fcn arg. + (DEFCONST_INTERNAL): New macro. + * defun.h (DEFVAR): Delete inst_as_fcn arg. + (DEFCONST, DEFCONSTX): Define using DEFCONST_INTERNAL instead of + DEFVAR_INTERNAL. + * data.cc, defaults.cc, error.cc, help.cc, input.cc, lex.l, + load-save.cc, oct-hist.cc, oct-procbuf.cc, ov-fcn.h, + ov-usr-fcn.cc, ov.cc, pager.cc, parse.y, pr-output.cc, + pt-assign.cc, pt-decl.cc, pt-mat.cc, pt-plot.cc, pt-stmt.cc, + toplev.cc, variables.cc: + Change all invocations of DEFVAR to match new definition. + + * data.cc (symbols_of_data): Add DEFCONSTs for true and false. + Thu Jul 15 10:59:42 1999 John W. Eaton + * data.cc (Fis_bool, Fis_complex, Fisempty, Fisnumeric, Fis_list, + Fis_map, Fis_struct): Return bool object. + (Fisreal): New function. + + * ov-str-mat.h (octave_char_matrix_str): Only return true if + Vimplicit_str_to_num_ok is also true. + * DLD-FUNCTIONS/time.cc (Ftime): Print usage message if any arguments are supplied. diff --git a/src/data.cc b/src/data.cc --- a/src/data.cc +++ b/src/data.cc @@ -759,7 +759,7 @@ octave_value retval; if (args.length () == 1) - retval = args(0).is_bool_type () ? 1.0 : 0.0; + retval = args(0).is_bool_type (); else print_usage ("is_bool"); @@ -769,18 +769,31 @@ DEFALIAS (islogical, is_bool); DEFUN (is_complex, args, , - "is_complex (x): return nonzero if x is a complex numeric object") + "is_complex (x): return nonzero if x is a complex-valued numeric object") { octave_value retval; if (args.length () == 1) - retval = args(0).is_complex_type () ? 1.0 : 0.0; + retval = args(0).is_complex_type (); else print_usage ("is_complex"); return retval; } +DEFUN (isreal, args, , + "isreal (x): return nonzero if x is a real-valued numeric object") +{ + octave_value retval; + + if (args.length () == 1) + retval = args(0).is_real_type (); + else + print_usage ("isreal"); + + return retval; +} + DEFUN (isempty, args, , "isempty (x): return nonzero if x is an empty matrix, string, or list") { @@ -807,7 +820,7 @@ octave_value retval; if (args.length () == 1) - retval = args(0).is_numeric_type () ? 1.0 : 0.0; + retval = args(0).is_numeric_type (); else print_usage ("isnumeric"); @@ -820,7 +833,7 @@ octave_value retval; if (args.length () == 1) - retval = args(0).is_list () ? 1.0 : 0.0; + retval = args(0).is_list (); else print_usage ("is_list"); @@ -853,7 +866,7 @@ octave_value retval; if (args.length () == 1) - retval = args(0).is_map () ? 1.0 : 0.0; + retval = args(0).is_map (); else print_usage ("is_struct"); @@ -1241,6 +1254,9 @@ DEFCONST (eps, DBL_EPSILON, "machine precision"); + DEFCONST (false, false, + "logical false value"); + DEFCONST (i, Complex (0.0, 1.0), "sqrt (-1)"); @@ -1268,8 +1284,11 @@ DEFCONST (realmin, DBL_MIN, "realmin (): return smallest representable floating point number"); - DEFVAR (treat_neg_dim_as_zero, 0.0, 0, treat_neg_dim_as_zero, + DEFVAR (treat_neg_dim_as_zero, 0.0, treat_neg_dim_as_zero, "convert negative dimensions to zero"); + + DEFCONST (true, true, + "logical true value"); } /* diff --git a/src/defaults.cc b/src/defaults.cc --- a/src/defaults.cc +++ b/src/defaults.cc @@ -415,13 +415,13 @@ void symbols_of_defaults (void) { - DEFVAR (EDITOR, Veditor, 0, editor, + DEFVAR (EDITOR, Veditor, editor, "name of the editor to be invoked by the edit_history command"); - DEFVAR (EXEC_PATH, Vexec_path, 0, exec_path, + DEFVAR (EXEC_PATH, Vexec_path, exec_path, "colon separated list of directories to search for programs to run"); - DEFVAR (LOADPATH, Vload_path, 0, loadpath, + DEFVAR (LOADPATH, Vload_path, loadpath, "colon separated list of directories to search for scripts.\n\ The default value is \":\", which means to search the default list\n\ of directories. The default list of directories may be found in\n\ @@ -430,7 +430,7 @@ DEFCONST (DEFAULT_LOADPATH, Vdefault_load_path, "the default colon separated list of directories to search for scripts"); - DEFVAR (IMAGEPATH, OCTAVE_IMAGEPATH, 0, imagepath, + DEFVAR (IMAGEPATH, OCTAVE_IMAGEPATH, imagepath, "colon separated list of directories to search for image files"); DEFCONST (OCTAVE_HOME, Voctave_home, diff --git a/src/defun-int.h b/src/defun-int.h --- a/src/defun-int.h +++ b/src/defun-int.h @@ -45,11 +45,15 @@ extern void install_builtin_variable (const string& n, const octave_value& v, - bool iaf, bool p, bool e, + bool p, bool e, symbol_record::change_function chg_fcn, const string& h); extern void +install_builtin_constant (const string& n, const octave_value& v, + bool p, const string& h); + +extern void alias_builtin (const string& alias, const string& name); // MAKE_BUILTINS is defined to extract function names and related @@ -112,10 +116,14 @@ // How builtin variables are actually installed. -#define DEFVAR_INTERNAL(name, sname, defn, inst_as_fcn, protect, \ - chg_fcn, doc) \ - install_builtin_variable (name, octave_value (defn), inst_as_fcn, \ - protect, (chg_fcn != 0), chg_fcn, doc) +#define DEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ + install_builtin_variable (name, octave_value (defn), protect, \ + (chg_fcn != 0), chg_fcn, doc) + +// How builtin variables are actually installed. + +#define DEFCONST_INTERNAL(name, sname, defn, protect, doc) \ + install_builtin_constant (name, octave_value (defn), protect, doc) // How mapper functions are actually installed. diff --git a/src/defun.cc b/src/defun.cc --- a/src/defun.cc +++ b/src/defun.cc @@ -101,41 +101,34 @@ sym_rec->protect (); } -static void -install_builtin_variable_as_function (const string& name, - const octave_value& val, - bool protect, bool eternal, - const string& help) +void +install_builtin_constant (const string& name, const octave_value& val, + bool protect, const string& help) { symbol_record *sym_rec = global_sym_tab->lookup (name, true); sym_rec->unprotect (); string tmp_help = help.empty () ? sym_rec->help () : help; - sym_rec->define_as_fcn (val); + sym_rec->define_builtin_const (val); sym_rec->document (tmp_help); if (protect) sym_rec->protect (); - if (eternal) - sym_rec->make_eternal (); + // XXX FIXME XXX -- shouldn't constants be eternal? + // if (eternal) + // sym_rec->make_eternal (); } void install_builtin_variable (const string& name, const octave_value& value, - bool install_as_function, bool protect, bool eternal, symbol_record::change_function chg_fcn, - const string& help_string) + const string& doc) { - if (install_as_function) - install_builtin_variable_as_function (name, value, protect, - eternal, help_string); - else - bind_builtin_variable (name, value, protect, eternal, - chg_fcn, help_string); + bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); } void diff --git a/src/defun.h b/src/defun.h --- a/src/defun.h +++ b/src/defun.h @@ -35,10 +35,6 @@ // // defn is the initial value for the variable. // -// inst_as_fcn is a flag that says whether to install the variable as -// if it were a function (allowing the name to also be used as a -// variable by users, but recover its original definition if cleared). -// // protect is a flag that says whether it should be possible to give // the variable a new value. // @@ -52,27 +48,24 @@ // // doc is the simple help text for this variable. -#define DEFVAR(name, defn, inst_as_fcn, chg_fcn, doc) \ - DEFVAR_INTERNAL (#name, SBV_ ## name, defn, inst_as_fcn, false, chg_fcn, doc) +#define DEFVAR(name, defn, chg_fcn, doc) \ + DEFVAR_INTERNAL (#name, SBV_ ## name, defn, false, chg_fcn, doc) -// Define a builtin-constant `__name__', and a corresponding variable -// `name' that can be redefined. (The variable is actually installed -// in the symbol table as a function, so that it doesn't work like a -// global variable when redefined.) +// Define a builtin constant `name' (which may be redefined, but will +// retain its original value when cleared) and also an alias to it +// called `__name__' (which may not be redefined). #define DEFCONST(name, defn, doc) \ - DEFVAR_INTERNAL (#name, SBV_ ## name, defn, true, false, 0, doc); \ - DEFVAR_INTERNAL ("__" ## #name ## "__", XSBV_ ## name, defn, false, \ - true, 0, doc) + DEFCONST_INTERNAL (#name, SBV_ ## name, defn, false, doc); \ + DEFCONST_INTERNAL ("__" ## #name ## "__", XSBV_ ## name, defn, true, 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, doc) \ - DEFVAR_INTERNAL (name, sname, defn, true, false, 0, doc); \ - DEFVAR_INTERNAL ("__" ## name ## "__", X ## sname, defn, false, true, \ - 0, doc) + DEFCONST_INTERNAL (name, sname, defn, false, doc); \ + DEFCONST_INTERNAL ("__" ## name ## "__", X ## sname, defn, true, doc) // Define a builtin function. // diff --git a/src/error.cc b/src/error.cc --- a/src/error.cc +++ b/src/error.cc @@ -330,7 +330,7 @@ void symbols_of_error (void) { - DEFVAR (beep_on_error, 0.0, 0, beep_on_error, + DEFVAR (beep_on_error, 0.0, beep_on_error, "if true, beep before printing error messages"); DEFCONST (error_text, "", diff --git a/src/fn-cache.h b/src/fn-cache.h --- a/src/fn-cache.h +++ b/src/fn-cache.h @@ -23,8 +23,6 @@ #if !defined (octave_fn_cache_h) #define octave_fn_cache_h 1 -#include - #include #include "Map.h" diff --git a/src/help.cc b/src/help.cc --- a/src/help.cc +++ b/src/help.cc @@ -1063,13 +1063,13 @@ void symbols_of_help (void) { - DEFVAR (INFO_FILE, Vinfo_file, 0, info_file, + DEFVAR (INFO_FILE, Vinfo_file, info_file, "name of the Octave info file"); - DEFVAR (INFO_PROGRAM, Vinfo_prog, 0, info_prog, + DEFVAR (INFO_PROGRAM, Vinfo_prog, info_prog, "name of the Octave info reader"); - DEFVAR (suppress_verbose_help_message, 0.0, 0, suppress_verbose_help_message, + DEFVAR (suppress_verbose_help_message, 0.0, suppress_verbose_help_message, "suppress printing of message pointing to additional help in the\n\ help and usage functions"); } diff --git a/src/input.cc b/src/input.cc --- a/src/input.cc +++ b/src/input.cc @@ -883,19 +883,19 @@ void symbols_of_input (void) { - DEFVAR (PS1, "\\s:\\#> ", 0, ps1, + DEFVAR (PS1, "\\s:\\#> ", ps1, "primary prompt string"); - DEFVAR (PS2, "> ", 0, ps2, + DEFVAR (PS2, "> ", ps2, "secondary prompt string"); - DEFVAR (PS4, "+ ", 0, ps4, + DEFVAR (PS4, "+ ", ps4, "string printed before echoed input (enabled by --echo-input)"); - DEFVAR (completion_append_char, " ", 0, completion_append_char, + DEFVAR (completion_append_char, " ", completion_append_char, "the string to append after successful command-line completion attempts"); - DEFVAR (echo_executing_commands, static_cast (ECHO_OFF), 0, + DEFVAR (echo_executing_commands, static_cast (ECHO_OFF), echo_executing_commands, "echo commands as they are executed"); } diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -2107,7 +2107,7 @@ void symbols_of_lex (void) { - DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, + DEFVAR (whitespace_in_literal_matrix, "", whitespace_in_literal_matrix, "control auto-insertion of commas and semicolons in literal matrices"); } diff --git a/src/load-save.cc b/src/load-save.cc --- a/src/load-save.cc +++ b/src/load-save.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include @@ -43,6 +42,7 @@ #include "lo-mappers.h" #include "mach-info.h" #include "oct-env.h" +#include "oct-time.h" #include "str-vec.h" #include "defun.h" @@ -2450,9 +2450,8 @@ case LS_ASCII: { - time_t now = time (0); - - string time_string = asctime (gmtime (&now)); + octave_gmtime now; + string time_string = now.asctime (); time_string = time_string.substr (0, time_string.length () - 1); os << "# Created by Octave " OCTAVE_VERSION ", " @@ -2751,14 +2750,14 @@ void symbols_of_load_save (void) { - DEFVAR (crash_dumps_octave_core, 1.0, 0, crash_dumps_octave_core, + DEFVAR (crash_dumps_octave_core, 1.0, crash_dumps_octave_core, "write octave-core file if Octave crashes or is killed by a signal"); - DEFVAR (default_save_format, "ascii", 0, default_save_format, + DEFVAR (default_save_format, "ascii", default_save_format, "default format for files created with save, may be one of\n\ \"binary\", \"text\", or \"mat-binary\""); - DEFVAR (save_precision, 15.0, 0, save_precision, + DEFVAR (save_precision, 15.0, save_precision, "number of significant figures kept by the ASCII save command"); } diff --git a/src/oct-hist.cc b/src/oct-hist.cc --- a/src/oct-hist.cc +++ b/src/oct-hist.cc @@ -643,15 +643,15 @@ void symbols_of_oct_hist (void) { - DEFVAR (history_file, default_history_file (), 0, history_file, + DEFVAR (history_file, default_history_file (), history_file, "name of command history file"); double tmp_hist_size = default_history_size (); - DEFVAR (history_size, tmp_hist_size, 0, history_size, + DEFVAR (history_size, tmp_hist_size, history_size, "number of commands to save in the history list"); - DEFVAR (saving_history, 1.0, 0, saving_history, + DEFVAR (saving_history, 1.0, saving_history, "save command history"); } diff --git a/src/oct-procbuf.cc b/src/oct-procbuf.cc --- a/src/oct-procbuf.cc +++ b/src/oct-procbuf.cc @@ -206,7 +206,7 @@ symbols_of_oct_procbuf (void) { DEFVAR (kluge_procbuf_delay, static_cast (Vkluge_procbuf_delay), - 0, kluge_procbuf_delay, + kluge_procbuf_delay, "number of microseconds to delay in the parent after forking"); } diff --git a/src/ov-fcn.h b/src/ov-fcn.h --- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -27,12 +27,11 @@ #pragma interface #endif -#include - #include +#include "oct-time.h" + #include "oct-alloc.h" -#include "oct-time.h" #include "ov-base.h" #include "ov-typeinfo.h" diff --git a/src/ov-usr-fcn.cc b/src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -592,21 +592,21 @@ void symbols_of_ov_usr_fcn (void) { - DEFVAR (default_return_value, Matrix (), 0, 0, + DEFVAR (default_return_value, Matrix (), 0, "the default for value for unitialized variables returned from\n\ functions. Only used if the variable initialize_return_values is\n\ nonzero."); - DEFVAR (define_all_return_values, 0.0, 0, define_all_return_values, + DEFVAR (define_all_return_values, 0.0, define_all_return_values, "control whether values returned from functions should have a\n\ value even if one has not been explicitly assigned. See also\n\ default_return_value"); - DEFVAR (max_recursion_depth, 256.0, 0, max_recursion_depth, + DEFVAR (max_recursion_depth, 256.0, max_recursion_depth, "maximum nesting level for functions called recursively.\n\ The default value is 256."); - DEFVAR (return_last_computed_value, 0.0, 0, return_last_computed_value, + DEFVAR (return_last_computed_value, 0.0, return_last_computed_value, "if a function does not return any values explicitly, return the\n\ last computed value"); } diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -1503,31 +1503,31 @@ void symbols_of_ov (void) { - DEFVAR (do_fortran_indexing, 0.0, 0, do_fortran_indexing, + DEFVAR (do_fortran_indexing, 0.0, do_fortran_indexing, "allow single indices for matrices"); - DEFVAR (implicit_str_to_num_ok, 0.0, 0, implicit_str_to_num_ok, + DEFVAR (implicit_str_to_num_ok, 0.0, implicit_str_to_num_ok, "allow implicit string to number conversion"); - DEFVAR (ok_to_lose_imaginary_part, "warn", 0, ok_to_lose_imaginary_part, + DEFVAR (ok_to_lose_imaginary_part, "warn", ok_to_lose_imaginary_part, "silently convert from complex to real by dropping imaginary part"); - DEFVAR (prefer_column_vectors, 1.0, 0, prefer_column_vectors, + DEFVAR (prefer_column_vectors, 1.0, prefer_column_vectors, "prefer column/row vectors"); - DEFVAR (print_answer_id_name, 1.0, 0, print_answer_id_name, + DEFVAR (print_answer_id_name, 1.0, print_answer_id_name, "set output style to print `var_name = ...'"); - DEFVAR (propagate_empty_matrices, 1.0, 0, propagate_empty_matrices, + DEFVAR (propagate_empty_matrices, 1.0, propagate_empty_matrices, "operations on empty matrices return an empty matrix, not an error"); - DEFVAR (resize_on_range_error, 1.0, 0, resize_on_range_error, + DEFVAR (resize_on_range_error, 1.0, resize_on_range_error, "enlarge matrices on assignment"); - DEFVAR (struct_levels_to_print, 2.0, 0, struct_levels_to_print, + DEFVAR (struct_levels_to_print, 2.0, struct_levels_to_print, "number of levels of structure elements to print"); - DEFVAR (warn_divide_by_zero, 1.0, 0, warn_divide_by_zero, + DEFVAR (warn_divide_by_zero, 1.0, warn_divide_by_zero, "if TRUE, warn about division by zero"); } diff --git a/src/pager.cc b/src/pager.cc --- a/src/pager.cc +++ b/src/pager.cc @@ -507,13 +507,13 @@ void symbols_of_pager (void) { - DEFVAR (PAGER, default_pager (), 0, pager_binary, + DEFVAR (PAGER, default_pager (), pager_binary, "path to pager binary"); - DEFVAR (page_output_immediately, 0.0, 0, page_output_immediately, + DEFVAR (page_output_immediately, 0.0, page_output_immediately, "if paging output, start sending it as soon as it is available"); - DEFVAR (page_screen_output, 1.0, 0, page_screen_output, + DEFVAR (page_screen_output, 1.0, page_screen_output, "if possible, send output intended for the screen through the pager"); } diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -3253,24 +3253,24 @@ void symbols_of_parse (void) { - DEFVAR (default_eval_print_flag, 1.0, 0, default_eval_print_flag, + DEFVAR (default_eval_print_flag, 1.0, default_eval_print_flag, "If the value of this variable is nonzero, Octave will print the\n\ results of commands executed by eval() that do not end with semicolons."); - DEFVAR (warn_assign_as_truth_value, 1.0, 0, warn_assign_as_truth_value, + DEFVAR (warn_assign_as_truth_value, 1.0, warn_assign_as_truth_value, "produce warning for assignments used as truth values"); - DEFVAR (warn_function_name_clash, 1.0, 0, warn_function_name_clash, + DEFVAR (warn_function_name_clash, 1.0, warn_function_name_clash, "produce warning if function name conflicts with file name"); - DEFVAR (warn_future_time_stamp, 1.0, 0, warn_future_time_stamp, + DEFVAR (warn_future_time_stamp, 1.0, warn_future_time_stamp, "warn if a function file has a time stamp that is in the future"); - DEFVAR (warn_missing_semicolon, 0.0, 0, warn_missing_semicolon, + DEFVAR (warn_missing_semicolon, 0.0, warn_missing_semicolon, "produce a warning if a statement in a function file is not\n\ terminated with a semicolon"); - DEFVAR (warn_variable_switch_label, 0.0, 0, warn_variable_switch_label, + DEFVAR (warn_variable_switch_label, 0.0, warn_variable_switch_label, "produce warning for variables used as switch labels"); } diff --git a/src/pr-output.cc b/src/pr-output.cc --- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -1889,19 +1889,19 @@ void symbols_of_pr_output (void) { - DEFVAR (fixed_point_format, 0.0, 0, fixed_point_format, + DEFVAR (fixed_point_format, 0.0, fixed_point_format, "use scaled fixed point format for `format short' and `format long'"); - DEFVAR (output_max_field_width, 10.0, 0, output_max_field_width, + DEFVAR (output_max_field_width, 10.0, output_max_field_width, "maximum width of an output field for numeric output"); - DEFVAR (output_precision, 5.0, 0, output_precision, + DEFVAR (output_precision, 5.0, output_precision, "number of significant figures to display for numeric output"); - DEFVAR (print_empty_dimensions, 1.0, 0, print_empty_dimensions, + DEFVAR (print_empty_dimensions, 1.0, print_empty_dimensions, "also print dimensions of empty matrices"); - DEFVAR (split_long_rows, 1.0, 0, split_long_rows, + DEFVAR (split_long_rows, 1.0, split_long_rows, "split long matrix rows instead of wrapping"); } diff --git a/src/pt-assign.cc b/src/pt-assign.cc --- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -332,7 +332,7 @@ void symbols_of_pt_assign (void) { - DEFVAR (print_rhs_assign_val, 0.0, 0, print_rhs_assign_val, + DEFVAR (print_rhs_assign_val, 0.0, print_rhs_assign_val, "if TRUE, print the right hand side of assignments instead of the left"); } diff --git a/src/pt-decl.cc b/src/pt-decl.cc --- a/src/pt-decl.cc +++ b/src/pt-decl.cc @@ -188,11 +188,11 @@ void symbols_of_pt_decl (void) { - DEFVAR (default_global_variable_value, , 0, 0, + DEFVAR (default_global_variable_value, , 0, "the default for value for otherwise uninitialized global variables.\n\ Only used if the variable initialize_global_variables is nonzero."); - DEFVAR (initialize_global_variables, 0.0, 0, initialize_global_variables, + DEFVAR (initialize_global_variables, 0.0, initialize_global_variables, "control whether otherwise uninitialized global variables are\n\ given a default value. See also default_global_variable_value"); } diff --git a/src/pt-mat.cc b/src/pt-mat.cc --- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -609,13 +609,13 @@ void symbols_of_pt_mat (void) { - DEFVAR (empty_list_elements_ok, "warn", 0, empty_list_elements_ok, + DEFVAR (empty_list_elements_ok, "warn", empty_list_elements_ok, "ignore the empty element in expressions like `a = [[], 1]'"); - DEFVAR (implicit_num_to_str_ok, 0.0, 0, implicit_num_to_str_ok, + DEFVAR (implicit_num_to_str_ok, 0.0, implicit_num_to_str_ok, "make the result of things like `[97, 98, 99, \"123\"]' be a string"); - DEFVAR (string_fill_char, " ", 0, string_fill_char, + DEFVAR (string_fill_char, " ", string_fill_char, "the character to fill with when creating string arrays."); } diff --git a/src/pt-plot.cc b/src/pt-plot.cc --- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -1240,34 +1240,34 @@ void symbols_of_pt_plot (void) { - DEFVAR (automatic_replot, 0.0, 0, automatic_replot, + DEFVAR (automatic_replot, 0.0, automatic_replot, "if true, auto-insert a replot command when a plot changes"); - DEFVAR (gnuplot_binary, "gnuplot", 0, gnuplot_binary, + DEFVAR (gnuplot_binary, "gnuplot", gnuplot_binary, "path to gnuplot binary"); - DEFVAR (gnuplot_command_plot, "pl", 0, gnuplot_command_plot, + DEFVAR (gnuplot_command_plot, "pl", gnuplot_command_plot, ""); - DEFVAR (gnuplot_command_replot, "rep", 0, gnuplot_command_replot, + DEFVAR (gnuplot_command_replot, "rep", gnuplot_command_replot, ""); - DEFVAR (gnuplot_command_splot, "sp", 0, gnuplot_command_splot, + DEFVAR (gnuplot_command_splot, "sp", gnuplot_command_splot, ""); - DEFVAR (gnuplot_command_using, "u", 0, gnuplot_command_using, + DEFVAR (gnuplot_command_using, "u", gnuplot_command_using, ""); - DEFVAR (gnuplot_command_with, "w", 0, gnuplot_command_with, + DEFVAR (gnuplot_command_with, "w", gnuplot_command_with, ""); - DEFVAR (gnuplot_command_axes, "ax", 0, gnuplot_command_axes, + DEFVAR (gnuplot_command_axes, "ax", gnuplot_command_axes, ""); - DEFVAR (gnuplot_command_title, "t", 0, gnuplot_command_title, + DEFVAR (gnuplot_command_title, "t", gnuplot_command_title, ""); - DEFVAR (gnuplot_command_end, "\n", 0, gnuplot_command_end, + DEFVAR (gnuplot_command_end, "\n", gnuplot_command_end, ""); #ifdef GNUPLOT_HAS_FRAMES @@ -1276,7 +1276,7 @@ double with_frames = 0.0; #endif - DEFVAR (gnuplot_has_frames, with_frames, 0, gnuplot_has_frames, + DEFVAR (gnuplot_has_frames, with_frames, gnuplot_has_frames, "true if gnuplot supports multiple plot windows on X11, false otherwise"); #ifdef GNUPLOT_HAS_MULTIPLOT @@ -1285,7 +1285,7 @@ double with_multiplot = 0.0; #endif - DEFVAR (gnuplot_has_multiplot, with_multiplot, 0, gnuplot_has_multiplot, + DEFVAR (gnuplot_has_multiplot, with_multiplot, gnuplot_has_multiplot, "true if gnuplot supports multiplot, false otherwise"); } diff --git a/src/pt-stmt.cc b/src/pt-stmt.cc --- a/src/pt-stmt.cc +++ b/src/pt-stmt.cc @@ -189,7 +189,7 @@ void symbols_of_pt_stmt (void) { - DEFVAR (silent_functions, 0.0, 0, silent_functions, + DEFVAR (silent_functions, 0.0, silent_functions, "suppress printing results in called functions"); } diff --git a/src/symtab.cc b/src/symtab.cc --- a/src/symtab.cc +++ b/src/symtab.cc @@ -73,7 +73,7 @@ { if (! (is_variable () && read_only_error ("redefine"))) { - if (is_function ()) + if (is_function () || is_constant ()) push_def (new symbol_def ()); if (definition->type () == symbol_record::BUILTIN_VARIABLE) @@ -93,13 +93,13 @@ } bool -symbol_record::define_as_fcn (const octave_value& v) +symbol_record::define_builtin_const (const octave_value& v) { bool retval = false; - if (! (is_variable () || read_only_error ("redefine"))) + if (! read_only_error ("redefine")) { - replace_all_defs (new symbol_def (v, symbol_record::BUILTIN_FUNCTION)); + replace_all_defs (new symbol_def (v, symbol_record::BUILTIN_CONSTANT)); retval = true; } @@ -230,16 +230,26 @@ return is_variable () ? def () : foo; } +inline void +symbol_record::link_to_builtin_variable (void) +{ + symbol_record *tmp_sym = global_sym_tab->lookup (name ()); + + if (tmp_sym && tmp_sym->is_builtin_variable ()) + alias (tmp_sym); +} + + octave_lvalue symbol_record::variable_reference (void) { - if (is_function ()) + if (is_function () || is_constant ()) clear (); if (! is_defined ()) { if (! (is_formal_parameter () || is_linked_to_global ())) - link_to_builtin_variable (this); + link_to_builtin_variable (); if (! is_defined ()) { @@ -326,7 +336,7 @@ { if (is_read_only ()) { - if (is_variable ()) + if (is_variable () || is_constant ()) ::error ("can't %s read-only constant `%s'", action, nm.c_str ()); else if (is_function ()) ::error ("can't %s read-only function `%s'", action, nm.c_str ()); diff --git a/src/symtab.h b/src/symtab.h --- a/src/symtab.h +++ b/src/symtab.h @@ -52,6 +52,9 @@ { public: + // If you add or delete an entry here, you'll also need to change + // the with parameter in the declaration for symbol_type below... + enum TYPE { UNKNOWN = 0, @@ -60,7 +63,8 @@ BUILTIN_FUNCTION = 4, TEXT_FUNCTION = 8, MAPPER_FUNCTION = 16, - BUILTIN_VARIABLE = 32 + BUILTIN_VARIABLE = 32, + BUILTIN_CONSTANT = 64 }; private: @@ -78,6 +82,9 @@ ~symbol_def (void) { } + bool is_constant (void) const + { return (symbol_type & symbol_record::BUILTIN_CONSTANT); } + bool is_variable (void) const { return (symbol_type & symbol_record::USER_VARIABLE @@ -102,6 +109,9 @@ bool is_user_function (void) const { return (symbol_type & symbol_record::USER_FUNCTION); } + bool is_builtin_constant (void) const + { return (symbol_type & symbol_record::BUILTIN_CONSTANT); } + bool is_builtin_variable (void) const { return (symbol_type & symbol_record::BUILTIN_VARIABLE); } @@ -155,7 +165,7 @@ static octave_allocator allocator; // The type of this symbol (see the enum above). - unsigned int symbol_type : 6; + unsigned int symbol_type : 7; // Nonzero means this variable cannot be cleared. unsigned int eternal : 1; @@ -225,6 +235,12 @@ bool is_builtin_function (void) const { return definition->is_builtin_function (); } + bool is_constant (void) const + { return definition->is_constant (); } + + bool is_builtin_constant (void) const + { return definition->is_builtin_constant (); } + bool is_variable (void) const { return definition->is_variable (); } @@ -257,7 +273,7 @@ void define_builtin_var (const octave_value& v); - bool define_as_fcn (const octave_value& v); + bool define_builtin_const (const octave_value& v); bool define (octave_function *f, unsigned int sym_type); @@ -323,6 +339,8 @@ void replace_all_defs (symbol_def *sd); + void link_to_builtin_variable (void); + // No copying! symbol_record (const symbol_record& s); @@ -342,7 +360,8 @@ | symbol_record::BUILTIN_FUNCTION \ | symbol_record::TEXT_FUNCTION \ | symbol_record::MAPPER_FUNCTION \ - | symbol_record::BUILTIN_VARIABLE) + | symbol_record::BUILTIN_VARIABLE \ + | symbol_record::BUILTIN_CONSTANT) #define SYMTAB_VARIABLES (symbol_record::USER_VARIABLE \ | symbol_record::BUILTIN_VARIABLE) diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -29,7 +29,6 @@ #include #include #include -#include #include diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -26,7 +26,6 @@ #include #include -#include #include @@ -714,19 +713,10 @@ // Make the definition of the symbol record sr be the same as the // definition of the builtin variable of the same name. -void -link_to_builtin_variable (symbol_record *sr) -{ - symbol_record *tmp_sym = global_sym_tab->lookup (sr->name ()); - - if (tmp_sym && tmp_sym->is_builtin_variable ()) - sr->alias (tmp_sym); -} - // Make the definition of the symbol record sr be the same as the -// definition of the builtin variable or function, or user function of -// the same name, provided that the name has not been used as a formal -// parameter. +// definition of the builtin variable, constant, or function, or user +// function of the same name, provided that the name has not been used +// as a formal parameter. void link_to_builtin_or_function (symbol_record *sr) @@ -734,7 +724,9 @@ symbol_record *tmp_sym = global_sym_tab->lookup (sr->name ()); if (tmp_sym - && (tmp_sym->is_builtin_variable () || tmp_sym->is_function ()) + && (tmp_sym->is_builtin_variable () + || tmp_sym->is_builtin_constant () + || tmp_sym->is_function ()) && ! tmp_sym->is_formal_parameter ()) sr->alias (tmp_sym); } @@ -1207,10 +1199,10 @@ void symbols_of_variables (void) { - DEFVAR (ans, , 0, 0, + DEFVAR (ans, , 0, ""); - DEFVAR (ignore_function_time_stamp, "system", 0, ignore_function_time_stamp, + DEFVAR (ignore_function_time_stamp, "system", ignore_function_time_stamp, "don't check to see if function files have changed since they were\n\ last compiled. Possible values are \"system\" and \"all\""); } diff --git a/src/variables.h b/src/variables.h --- a/src/variables.h +++ b/src/variables.h @@ -84,7 +84,6 @@ extern octave_value builtin_any_variable (const string&); extern void link_to_global_variable (symbol_record *sr); -extern void link_to_builtin_variable (symbol_record *sr); extern void link_to_builtin_or_function (symbol_record *sr); extern void force_link_to_function (const string&);