Mercurial > hg > octave-terminal
changeset 2975:b9c107cbe388
[project @ 1997-05-15 20:01:00 by jwe]
author | jwe |
---|---|
date | Thu, 15 May 1997 20:02:55 +0000 |
parents | ebbc34ff7f66 |
children | 641689f67673 |
files | src/Makefile.in src/symtab.cc src/symtab.h src/variables.cc src/variables.h |
diffstat | 5 files changed, 139 insertions(+), 287 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -68,20 +68,19 @@ ov-list.h ov-struct.h ov-scalar.h ov-range.h \ ov-complex.h ov-va-args.h ov-colon.h ov-base.h \ ov-str-mat.h ov-bool-mat.h ov-bool.h ov-file.h ov.h \ - ov-typeinfo.h + ov-fcn.h ov-builtin.h ov-mapper.h ov-usr-fcn.h ov-typeinfo.h PT_INCLUDES := pt-base.h pt-cmd.h \ pt-const.h pt-exp-base.h pt-exp.h pt-id.h pt-indir.h \ - pt-mat.h pt-misc.h pt-mvr-base.h pt-mvr.h \ - pt-plot.h pt-pr-code.h pt-walk.h + pt-mat.h pt-misc.h pt-plot.h pt-pr-code.h pt-walk.h INCLUDES := BaseSLList.h Map.h SLList.h SLStack.h Stack.h defun-dld.h \ defun-int.h defun.h dirfns.h dynamic-ld.h error.h file-io.h \ fn-cache.h gripes.h help.h input.h lex.h load-save.h \ - oct-builtin.h oct-fcn.h oct-fstrm.h oct-hist.h oct-iostrm.h \ - oct-map.h oct-mapper.h oct-obj.h oct-prcstrm.h oct-procbuf.h \ - oct-stdstrm.h oct-stream.h oct-strstrm.h oct-sym.h \ - oct-usr-fcn.h oct-var-ref.h oct.h ops.h pager.h parse.h \ + oct-fstrm.h oct-hist.h oct-iostrm.h \ + oct-map.h oct-obj.h oct-prcstrm.h oct-procbuf.h \ + oct-stdstrm.h oct-stream.h oct-strstrm.h \ + oct-var-ref.h oct.h ops.h pager.h parse.h \ pr-output.h procstream.h sighandlers.h symtab.h sysdep.h \ systime.h syswait.h token.h toplev.h unwind-prot.h utils.h \ variables.h version.h xdiv.h xpow.h $(OV_INCLUDES) $(PT_INCLUDES) @@ -107,24 +106,24 @@ OV_SRC := ov-base.cc ov-ch-mat.cc ov-list.cc ov-re-mat.cc \ ov-cx-mat.cc ov-range.cc ov-scalar.cc ov-complex.cc \ ov-str-mat.cc ov-struct.cc ov-va-args.cc ov-colon.cc \ - ov-bool-mat.cc ov-bool.cc ov-file.cc ov.cc ov-typeinfo.cc + ov-bool-mat.cc ov-bool.cc ov-file.cc ov.cc ov-fcn.cc \ + ov-builtin.cc ov-mapper.cc ov-usr-fcn.cc ov-typeinfo.cc PT_SRC := pt-base.cc pt-cmd.cc pt-const.cc pt-exp-base.cc \ pt-exp.cc pt-id.cc pt-indir.cc pt-mat.cc pt-misc.cc \ - pt-mvr-base.cc pt-mvr.cc pt-plot.cc pt-pr-code.cc + pt-plot.cc pt-pr-code.cc SOURCES := BaseSLList.cc Map.cc SLList.cc SLStack.cc Stack.cc \ - data.cc defaults.cc dirfns.cc dynamic-ld.cc error.cc \ - file-io.cc fn-cache.cc gripes.cc help.cc input.cc lex.l \ - load-save.cc mappers.cc oct-fstrm.cc oct-hist.cc \ + data.cc defaults.cc defun.cc dirfns.cc dynamic-ld.cc \ + error.cc file-io.cc fn-cache.cc gripes.cc help.cc input.cc \ + lex.l load-save.cc mappers.cc oct-fstrm.cc oct-hist.cc \ oct-iostrm.cc oct-map.cc oct-obj.cc oct-prcstrm.cc \ oct-procbuf.cc oct-stdstrm.cc oct-stream.cc oct-strstrm.cc \ oct-var-ref.cc pager.cc parse.y pr-output.cc procstream.cc \ sighandlers.cc strcasecmp.c strncase.c strfns.cc \ strftime.c symtab.cc syscalls.cc sysdep.cc token.cc \ toplev.cc unwind-prot.cc utils.cc variables.cc xdiv.cc \ - xpow.cc oct-fcn.cc oct-builtin.cc oct-mapper.cc \ - oct-usr-fcn.cc \ + xpow.cc \ $(OP_SRC) $(OV_SRC) $(PT_SRC) $(TI_SRC) OBJECTS_4 := $(notdir $(SOURCES)) @@ -384,7 +383,7 @@ # Special rules -- these files need special things to be defined. parse.cc : parse.y - @echo "expect 12 shift/reduce conflicts" + @echo "expect 10 shift/reduce conflicts" $(YACC) $(YFLAGS) $< @$(top_srcdir)/move-if-change y.tab.c $(@F)
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -34,19 +34,23 @@ #include "str-vec.h" #include "error.h" -#include "oct-fcn.h" -#include "oct-sym.h" #include "oct-var-ref.h" +#include "ov.h" #include "symtab.h" #include "utils.h" #include "variables.h" // Variables and functions. -symbol_def::symbol_def (octave_symbol *sym, unsigned int sym_type) +symbol_def::symbol_def (void) { init_state (); - definition = sym; +} + +symbol_def::symbol_def (const octave_value& val, unsigned int sym_type) +{ + init_state (); + definition = val; type = sym_type; } @@ -57,16 +61,10 @@ eternal = 0; read_only = 0; - definition = 0; next_elem = 0; count = 0; } -symbol_def::~symbol_def (void) -{ - delete definition; -} - bool symbol_def::is_variable (void) const { @@ -123,9 +121,9 @@ } void -symbol_def::define (octave_symbol *s, unsigned int sym_type) +symbol_def::define (const octave_value& val, unsigned int sym_type) { - definition = s; + definition = val; type = sym_type; } @@ -149,8 +147,8 @@ eternal = 1; } -octave_symbol * -symbol_def::def (void) const +octave_value& +symbol_def::def (void) { return definition; } @@ -221,10 +219,12 @@ return retval; } -octave_symbol * -symbol_record::def (void) const +octave_value& +symbol_record::def (void) { - return definition ? definition->def () : false; + static octave_value foo; + + return definition ? definition->def () : foo; } void @@ -297,7 +297,7 @@ bool symbol_record::is_defined (void) const { - return definition ? (definition->def () != 0) : false; + return (definition != 0); } bool @@ -371,7 +371,7 @@ if (definition->symbol_type () == symbol_def::BUILTIN_VARIABLE) sym_type = symbol_def::BUILTIN_VARIABLE; - definition->define (new octave_value (v), sym_type); + definition->define (v, sym_type); } return retval; @@ -406,8 +406,7 @@ maybe_delete (old_def); } - push_def (new symbol_def (new octave_value (v), - symbol_def::BUILTIN_FUNCTION)); + push_def (new symbol_def (v, symbol_def::BUILTIN_FUNCTION)); definition->count = 1; @@ -432,7 +431,9 @@ maybe_delete (old_def); } - push_def (new symbol_def (f, sym_type)); + octave_value tmp (f); + + push_def (new symbol_def (tmp, sym_type)); definition->count = 1; @@ -502,7 +503,12 @@ void symbol_record::mark_as_linked_to_global (void) { - linked_to_global = 1; + if (is_formal_parameter ()) + error ("can't make function parameter `%s' global", nm.c_str ()); + else if (is_static ()) + error ("can't make static variable `%s' global", nm.c_str ()); + else + linked_to_global = 1; } bool @@ -515,9 +521,9 @@ symbol_record::mark_as_static (void) { if (is_linked_to_global ()) - error ("can't make global variable static"); + error ("can't make global variable `%s' static", nm.c_str ()); else if (is_formal_parameter ()) - error ("can't make formal parameter static"); + error ("can't make formal parameter `%s' static", nm.c_str ()); else tagged_static = 1; } @@ -528,18 +534,12 @@ return tagged_static; } -octave_value -symbol_record::variable_value (void) const +octave_value& +symbol_record::variable_value (void) { - octave_value retval; + static octave_value foo; - if (is_variable ()) - { - octave_symbol *tmp = def (); - retval = tmp->eval (); - } - - return retval; + return is_variable () ? def () : foo; } octave_variable_reference @@ -554,11 +554,13 @@ link_to_builtin_variable (this); if (! is_defined ()) - define (octave_value ()); + { + octave_value tmp; + define (tmp); + } } - return octave_variable_reference - (static_cast<octave_value *> (def ()), sv_fcn); + return octave_variable_reference (&(def ()), sv_fcn); } symbol_record * @@ -662,23 +664,19 @@ hides (SR_INFO_NONE), eternal (0), read_only (0), nm (), const_type () { } -symbol_record_info::symbol_record_info (const symbol_record& sr) +symbol_record_info::symbol_record_info (symbol_record& sr) : initialized (0), nr (-1), nc (-1), type (sr.type ()), hides (SR_INFO_NONE), eternal (0), read_only (0), nm (), const_type () { if (sr.is_variable () && sr.is_defined ()) { - // Would be nice to avoid this cast. XXX FIXME XXX - - octave_symbol *tmp = sr.def (); + octave_value tmp = sr.def (); - octave_value vtmp = tmp->eval (); + const_type = tmp.type_name (); - const_type = vtmp.type_name (); - - nr = vtmp.rows (); - nc = vtmp.columns (); + nr = tmp.rows (); + nc = tmp.columns (); symbol_def *sr_def = sr.definition; symbol_def *hidden_def = sr_def->next_elem;
--- a/src/symtab.h +++ b/src/symtab.h @@ -33,13 +33,12 @@ #include "str-vec.h" +#include "ov.h" + // Must be multiple of 2. #define HASH_TABLE_SIZE 1024 #define HASH_MASK (HASH_TABLE_SIZE - 1) -class octave_symbol; -class octave_function; -class octave_value; class octave_variable_reference; class string_vector; @@ -58,9 +57,11 @@ public: - symbol_def (octave_symbol *sym = 0, unsigned int sym_type = 0); + symbol_def (void); - ~symbol_def (void); + symbol_def (const octave_value& val, unsigned int sym_type = 0); + + ~symbol_def (void) { } bool is_variable (void) const; bool is_function (void) const; @@ -72,13 +73,13 @@ bool is_builtin_function (void) const; bool is_map_element (const string& elts) const; - void define (octave_symbol *sym, unsigned int sym_type); + void define (const octave_value& val, unsigned int sym_type); void protect (void); void unprotect (void); void make_eternal (void); - octave_symbol *def (void) const; + octave_value& def (void); string help (void) const; void document (const string& h); @@ -104,7 +105,7 @@ unsigned int read_only : 1; string help_string; - octave_symbol *definition; + octave_value definition; symbol_def *next_elem; int count; @@ -132,7 +133,8 @@ string name (void) const; string help (void) const; - octave_symbol *def (void) const; + + octave_value& def (void); void rename (const string& new_name); @@ -182,7 +184,7 @@ void mark_as_static (void); bool is_static (void) const; - octave_value variable_value (void) const; + octave_value& variable_value (void); octave_variable_reference variable_reference (void); symbol_record *next (void) const; @@ -226,7 +228,7 @@ public: symbol_record_info (void); - symbol_record_info (const symbol_record& s); + symbol_record_info (symbol_record& s); symbol_record_info (const symbol_record_info& s);
--- a/src/variables.cc +++ b/src/variables.cc @@ -63,9 +63,8 @@ #include "sysdep.h" #include "oct-hist.h" #include "oct-map.h" -#include "oct-mapper.h" +#include "ov-mapper.h" #include "oct-obj.h" -#include "oct-sym.h" #include "ov.h" #include "pager.h" #include "parse.h" @@ -175,10 +174,10 @@ // Is this octave_value a valid function? -octave_symbol * +octave_function * is_valid_function (const octave_value& arg, const string& warn_for, bool warn) { - octave_symbol *ans = 0; + octave_function *ans = 0; string fcn_name; @@ -199,7 +198,10 @@ sr = lookup_by_name (fcn_name); if (sr) - ans = sr->def (); + { + octave_value tmp = sr->def (); + ans = tmp.function_value (true); + } if (! sr || ! ans || ! sr->is_function ()) { @@ -212,12 +214,12 @@ return ans; } -octave_symbol * +octave_function * extract_function (const octave_value& arg, const string& warn_for, const string& fname, const string& header, const string& trailer) { - octave_symbol *retval = 0; + octave_function *retval = 0; retval = is_valid_function (arg, warn_for, 0); @@ -332,28 +334,23 @@ if (sr && sr->is_defined ()) { - octave_symbol *tmp = sr->def (); - - octave_value vtmp; - - if (tmp->is_constant ()) - vtmp = tmp->eval (); + octave_value tmp = sr->def (); // XXX FIXME XXX -- make this work for all types that can do // structure reference operations. - if (vtmp.is_map ()) + if (tmp.is_map ()) { for (int i = 1; i < elts.length (); i++) { - vtmp = vtmp.do_struct_elt_index_op (elts[i], true); + tmp = tmp.do_struct_elt_index_op (elts[i], true); - if (! vtmp.is_map ()) + if (! tmp.is_map ()) break; } - if (vtmp.is_map ()) + if (tmp.is_map ()) { - Octave_map m = vtmp.map_value (); + Octave_map m = tmp.map_value (); names = m.make_name_list (); } @@ -379,23 +376,18 @@ if (sr && sr->is_defined ()) { - octave_symbol *tmp = sr->def (); - - octave_value vtmp; - - if (tmp->is_constant ()) - vtmp = tmp->eval (); + octave_value tmp = sr->def (); // XXX FIXME XXX -- should this work for all types that can do // structure reference operations? - if (vtmp.is_map ()) + if (tmp.is_map ()) { for (int i = 1; i < elts.length (); i++) { - vtmp = vtmp.do_struct_elt_index_op (elts[i], true); + tmp = tmp.do_struct_elt_index_op (elts[i], true); - if (! vtmp.is_map ()) + if (! tmp.is_map ()) { retval = false; break; @@ -538,22 +530,27 @@ if (Vignore_function_time_stamp != 2 && sr) { - octave_symbol *ans = sr->def (); - if (ans) + octave_value ans = sr->def (); + + if (! Vignore_function_time_stamp && ans.is_defined ()) { - string ff = ans->fcn_file_name (); - if (! ff.empty () - && ! (Vignore_function_time_stamp - && ans->is_system_fcn_file ())) + octave_function *tmp = ans.function_value (true); + + if (tmp && tmp->is_system_fcn_file ()) { - time_t tp = ans->time_parsed (); + string ff = tmp->fcn_file_name (); - string fname = fcn_file_in_path (ff); + if (! ff.empty ()) + { + time_t tp = tmp->time_parsed (); - int status = file_stat::is_newer (fname, tp); + string fname = fcn_file_in_path (ff); + + int status = file_stat::is_newer (fname, tp); - if (status > 0) - retval = true; + if (status > 0) + retval = true; + } } } } @@ -945,11 +942,9 @@ if (sr) { - octave_symbol *sr_def = sr->def (); + octave_value sr_def = sr->def (); - if (sr_def) - retval = sr_def->eval (); - else + if (sr_def.is_undefined ()) error ("get_global_by_name: undefined symbol `%s'", nm.c_str ()); } else @@ -1007,15 +1002,10 @@ string retval; - octave_symbol *defn = sr->def (); + octave_value val = sr->def (); - if (defn) - { - octave_value val = defn->eval (); - - if (! error_state && val.is_string ()) - retval = val.string_value (); - } + if (! error_state && val.is_string ()) + retval = val.string_value (); return retval; } @@ -1034,17 +1024,12 @@ assert (sr); - octave_symbol *defn = sr->def (); - - if (defn) - { - octave_value val = defn->eval (); + octave_value val = sr->def (); - if (! error_state && val.is_scalar_type ()) - { - d = val.double_value (); - status = 1; - } + if (! error_state && val.is_scalar_type ()) + { + d = val.double_value (); + status = 1; } return status; @@ -1055,20 +1040,13 @@ octave_value builtin_any_variable (const string& name) { - octave_value retval; - symbol_record *sr = global_sym_tab->lookup (name); // It is a prorgramming error to look for builtins that aren't. assert (sr); - octave_symbol *defn = sr->def (); - - if (defn) - retval = defn->eval (); - - return retval; + return sr->def (); } // Global stuff and links to builtin variables and functions. @@ -1080,49 +1058,31 @@ void link_to_global_variable (symbol_record *sr) { - if (sr->is_linked_to_global ()) - return; - - string nm = sr->name (); - - symbol_record *gsr = global_sym_tab->lookup (nm, true); - - if (sr->is_formal_parameter ()) + if (! sr->is_linked_to_global ()) { - error ("can't make function parameter `%s' global", nm.c_str ()); - return; - } + sr->mark_as_linked_to_global (); - if (sr->is_static ()) - { - error ("can't make static variable `%s' global", nm.c_str ()); - return; - } + if (! error_state) + { + string nm = sr->name (); - // There must be a better way to do this. XXX FIXME XXX + symbol_record *gsr = global_sym_tab->lookup (nm, true); + + // There must be a better way to do this. XXX FIXME XXX - if (sr->is_variable ()) - { - octave_symbol *tmp = sr->def (); + if (sr->is_variable ()) + gsr->define (sr->def ()); + else + sr->clear (); - octave_value vtmp; + // Make sure this symbol is a variable. - if (tmp) - vtmp = tmp->eval (); + if (! gsr->is_variable ()) + gsr->define (octave_value ()); - gsr->define (vtmp); + sr->alias (gsr, 1); + } } - else - sr->clear (); - - // If the global symbol is currently defined as a function, we need - // to hide it with a variable. - - if (gsr->is_function ()) - gsr->define (octave_value ()); - - sr->alias (gsr, 1); - sr->mark_as_linked_to_global (); } // Make the definition of the symbol record sr be the same as the @@ -1502,94 +1462,6 @@ return retval; } -// Install variables and functions in the symbol tables. - -void -install_builtin_mapper (octave_mapper *mf) -{ - symbol_record *sym_rec = global_sym_tab->lookup (mf->name (), true); - - unsigned int t - = symbol_def::BUILTIN_FUNCTION | symbol_def::MAPPER_FUNCTION; - - sym_rec->unprotect (); - sym_rec->define (mf, t); - sym_rec->document (mf->doc_string ()); - sym_rec->make_eternal (); - sym_rec->protect (); -} - -void -install_builtin_function (octave_builtin *f, bool is_text_fcn) -{ - symbol_record *sym_rec = global_sym_tab->lookup (f->name (), true); - - unsigned int t - = symbol_def::BUILTIN_FUNCTION | symbol_def::MAPPER_FUNCTION; - - if (is_text_fcn) - t |= symbol_def::TEXT_FUNCTION; - - sym_rec->unprotect (); - sym_rec->define (f, t); - sym_rec->document (f->doc_string ()); - sym_rec->make_eternal (); - sym_rec->protect (); -} - -void -install_builtin_variable (const string& name, const octave_value& value, - bool install_as_function, bool protect, - bool eternal, symbol_record::sv_function sv_fcn, - const string& help_string) -{ - 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); -} - -void -install_builtin_variable_as_function (const string& name, - const octave_value& val, - bool protect, bool eternal, - 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->document (tmp_help); - - if (protect) - sym_rec->protect (); - - if (eternal) - sym_rec->make_eternal (); -} - -void -alias_builtin (const string& alias, const string& name) -{ - symbol_record *sr_name = global_sym_tab->lookup (name); - - if (! sr_name) - panic ("can't alias to undefined name!"); - - symbol_record *sr_alias = global_sym_tab->lookup (alias, true); - - if (sr_alias) - sr_alias->alias (sr_name); - else - panic ("can't find symbol record for builtin function `%s'", - alias.c_str ()); -} - // Defining variables. void
--- a/src/variables.h +++ b/src/variables.h @@ -23,7 +23,7 @@ #if !defined (octave_variables_h) #define octave_variables_h 1 -class octave_symbol; +class octave_function; class symbol_record; class symbol_table; @@ -38,6 +38,7 @@ #include <string> #include "ov.h" +#include "ov-builtin.h" #include "symtab.h" typedef octave_value_list (*Octave_builtin_fcn)(const octave_value_list&, int); @@ -71,10 +72,10 @@ extern bool is_builtin_function_name (const string&); extern bool is_globally_visible (const string&); -extern octave_symbol * +extern octave_function * is_valid_function (const octave_value&, const string&, bool warn = false); -extern octave_symbol * +extern octave_function * extract_function (const octave_value& arg, const string& warn_for, const string& fname, const string& header, const string& trailer); @@ -91,26 +92,6 @@ extern string_vector make_name_list (void); -extern void -install_builtin_mapper (octave_mapper *mf); - -extern void -install_builtin_function (octave_builtin *f, bool is_text_fcn = false); - -extern void -install_builtin_variable (const string& n, const octave_value& v, - bool iaf, bool p, bool e, - symbol_record::sv_function svf, const string& h); - -extern void -install_builtin_variable_as_function (const string& name, - const octave_value& val, - bool protect = false, - bool eternal = false, - const string& help = string ()); - -extern void alias_builtin (const string& alias, const string& name); - extern void bind_ans (const octave_value& val, bool print); extern void bind_global_error_variable (void);