changeset 2893:9fd1df4b464a

[project @ 1997-04-28 02:07:38 by jwe]
author jwe
date Mon, 28 Apr 1997 02:10:02 +0000
parents aef2d43edbc2
children f1c5f8151397
files PROJECTS src/ChangeLog src/dynamic-ld.cc src/dynamic-ld.h src/symtab.cc src/symtab.h src/sysdep.cc
diffstat 7 files changed, 213 insertions(+), 241 deletions(-) [+]
line wrap: on
line diff
--- a/PROJECTS
+++ b/PROJECTS
@@ -273,6 +273,12 @@
   * Consider making x(:) work no matter what the value of
     do_fortran_indexing.
 
+  * For indexing operations, allow `$' to indicate the last element.
+    For example, b = a (3:$, 1:$-1).  This means b is a, except for
+    its first 2 rows and last column.  Note that `$' must be able to
+    appear in arbitrarily complex expressions, so copying the the
+    current implementation of `:' won't work. 
+
   * If foo.oct and foo.m both exist in the LOADPATH, Octave will
     always find foo.oct, even if foo.m appears earlier in the list of
     directories.  This should be fixed (in the kpathsearch library) to
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,59 @@
+Sun Apr 27 20:17:49 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* dynamic-ld.h (Octave_builtin_fcn): Delete typedef.
+	* dynamic-ld.cc: Simplify via the magic of function pointers.
+
+	* pt-fcn.h pt-fcn.cc pt-fvc.h pt-fvc.cc pt-fvc-base.h pt-fvc-base.cc:
+	Delete obsolete files.
+	* Makefile.in: Remove them from various lists.
+
+	* pt-walk.h (visit_octave_user_function): Rename from visit_function.
+	(visit_builtin): Delete.
+	* pt-pr-code.h, pt-pr-code.cc (visit_octave_user_function):
+	Rename from visit_function.
+	(visit_octave_user_function_header): Rename from visit_function_header.
+	(visit_octave_user_function_trailer): Rename from
+	visit_function_trailer.
+
+	* ov.h, ov.cc (eval): New functions.
+
+	* dassl.cc, fsolve.cc, lsode.cc, npsol.cc, qpsol.cc, quad.cc:
+	Declare user-defined functions as a pointer to an octave_symbol
+	object, not as a pointer to a tree_fvc object.
+
+	* symtab.h, symtab.cc: Use new octave_symbol class.
+	* variables.cc (install_builtin_function, install_builtin_mapper,
+	install_builtin_variable, install_builtin_variable_as_function):
+	Make work with new octave_symbol class and symbol table structure.
+
+	* variables.h: Delete declaration of builtin_function struct.
+	* defun-dld.h (DEFUN_DLD): Simplify.
+	* defun-int.h (DEFINE_FUN_STRUCT): Delete.
+	(DEFINE_FUN_STRUCT_FUN): Rewrite to not use static builtin_function
+	object.
+
+	* mappers.h: Delete declaration of builtin_mapper_function struct.
+	* mappers.cc: Declare wrapper functions static.
+	* defun.h (DEFUN_MAPPER): Simplify.
+
+	* oct-sym.h: New file.  Declare base class for Octave symbols.
+	* ov.h: Derive octave_value class from octave_symbol.
+	* oct-fcn.h, oct-fcn.cc: New files to declare and define
+	base class for functions.
+	* oct-builtin.h, oct-builtin.cc: New files to declare and define
+	class for built-in functions.
+	* oct-mapper.h, oct-mapper.cc: New files to declare and define
+	class for mapper functions.
+	* oct-usr-fcn.h, oct-usr-fcn.cc: New files to declare and define
+	base class for user-defined functions.
+	* Makefile.in: Add new files to appropriate lists.
+
+	* pt-id.h, pt-id.cc: Move tree_identifier class here.
+	* pt-fvc.h, pt-fvc.cc: From here.
+
+	* pt-indir.h, pt-indir.cc: Move tree_indirect_ref class here.
+	* pt-fvc.h, pt-fvc.cc: From here.
+
 Thu Apr 24 03:58:16 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* parse.y (magic_colon): New nonterminal.
--- a/src/dynamic-ld.cc
+++ b/src/dynamic-ld.cc
@@ -50,13 +50,14 @@
 #include "toplev.h"
 #include "pathsearch.h"
 #include "oct-obj.h"
+#include "oct-builtin.h"
 #include "ov.h"
 #include "utils.h"
 #include "variables.h"
 
-typedef builtin_function * (*Octave_builtin_fcn_struct_fcn)(void);
+#if defined (WITH_DYNAMIC_LINKING)
 
-#if defined (WITH_DYNAMIC_LINKING)
+typedef void * (*resolver_fcn) (const string& name, const string& file);
 
 static string
 mangle_octave_oct_file_name (const string& name)
@@ -102,6 +103,8 @@
   return retval;
 }
 
+static resolver_fcn resolve_octave_reference = dl_resolve_octave_reference;
+
 #elif defined (WITH_SHL)
 
 static void *
@@ -138,63 +141,51 @@
   return retval;
 }
 
-#endif
+static resolver_fcn resolve_octave_reference = shl_resolve_octave_reference;
+
 #endif
 
-#if defined (WITH_DYNAMIC_LINKING)
-static void *
-resolve_octave_reference (const string& name, const string& file)
-{
-#if defined (WITH_DL)
-
-  return dl_resolve_octave_reference (name, file);
-
-#elif defined (WITH_SHL)
-
-  return shl_resolve_octave_reference (name, file);
-
-#endif
-}
-#endif
+typedef octave_builtin * (*builtin_obj_fcn) (void);
 
 int
 load_octave_oct_file (const string& name)
 {
   int retval = 0;
 
-#if defined (WITH_DYNAMIC_LINKING)
-
   string oct_file = oct_file_in_path (name);
 
   if (! oct_file.empty ())
     {
       string mangled_name = mangle_octave_oct_file_name (name);
 
-      Octave_builtin_fcn_struct_fcn f =
-	(Octave_builtin_fcn_struct_fcn) resolve_octave_reference
-	  (mangled_name, oct_file);
+      builtin_obj_fcn f
+	= (builtin_obj_fcn) resolve_octave_reference (mangled_name, oct_file);
 
       if (f)
 	{
-	  builtin_function *s = f ();
+	  octave_builtin *obj = f ();
 
-	  if (s)
+	  if (obj)
 	    {
-	      install_builtin_function (*s);
+	      install_builtin_function (obj);
 	      retval = 1;
 	    }
 	}
     }
 
+  return retval;
+}
+
 #else
 
-  (void) name;
+int
+load_octave_oct_file (const string&)
+{
+  return 0;
+}
 
 #endif
 
-  return retval;
-}
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/dynamic-ld.h
+++ b/src/dynamic-ld.h
@@ -27,8 +27,6 @@
 
 class octave_value_list;
 
-typedef octave_value_list (*Octave_builtin_fcn)(const octave_value_list&, int);
-
 extern int load_octave_oct_file (const string& name);
 
 #endif
--- a/src/symtab.cc
+++ b/src/symtab.cc
@@ -34,39 +34,20 @@
 #include "str-vec.h"
 
 #include "error.h"
+#include "oct-sym.h"
+#include "oct-fcn.h"
 #include "pt-const.h"
-#include "pt-fcn.h"
-#include "pt-fvc.h"
 #include "symtab.h"
 #include "utils.h"
 #include "variables.h"
 
 // Variables and functions.
 
-symbol_def::symbol_def (void)
-{
-  init_state ();
-}
-
-symbol_def::symbol_def (tree_constant *t)
+symbol_def::symbol_def (octave_symbol *sym, unsigned int sym_type)
 {
   init_state ();
-  definition = t;
-  type = USER_VARIABLE;
-}
-
-symbol_def::symbol_def (tree_builtin *t, unsigned fcn_type)
-{
-  init_state ();
-  definition = t;
-  type = BUILTIN_FUNCTION | fcn_type;
-}
-
-symbol_def::symbol_def (tree_function *t, unsigned fcn_type)
-{
-  init_state ();
-  definition = t;
-  type = USER_FUNCTION | fcn_type;
+  definition = sym;
+  type = sym_type;
 }
 
 void
@@ -138,33 +119,15 @@
 bool
 symbol_def::is_map_element (const string& /* elts */) const
 {
-  return 0;
+  return false;
 }
 
 void
-symbol_def::define (tree_constant *t)
+symbol_def::define (octave_symbol *s, unsigned int sym_type)
 {
-  if (t)
-    t->maybe_mutate ();
-
-  definition = t;
-
-  if (! is_builtin_variable ())
-    type = USER_VARIABLE;
-}
+  definition = s;
 
-void
-symbol_def::define (tree_builtin *t, unsigned fcn_type)
-{
-  definition = t;
-  type = BUILTIN_FUNCTION | fcn_type;
-}
-
-void
-symbol_def::define (tree_function *t, unsigned fcn_type)
-{
-  definition = t;
-  type = USER_FUNCTION | fcn_type;
+  type = sym_type;
 }
 
 void
@@ -186,7 +149,7 @@
   eternal = 1;
 }
 
-tree_fvc *
+octave_symbol *
 symbol_def::def (void) const
 {
   return definition;
@@ -258,7 +221,7 @@
   return retval;
 }
 
-tree_fvc *
+octave_symbol *
 symbol_record::def (void) const
 {
   return definition ? definition->def () : false;
@@ -325,7 +288,7 @@
   return definition ? definition->is_map_element (elts) : false;
 }
 
-unsigned
+unsigned int
 symbol_record::type (void) const
 {
   return definition ? definition->type : false;
@@ -388,105 +351,53 @@
 }
 
 int
-symbol_record::define (tree_constant *t)
+symbol_record::define (const octave_value& v, unsigned int sym_type)
 {
-  if (is_variable () && read_only_error ("redefine"))
-    return 0;
+  int retval = 0;
 
-  tree_fvc *saved_def = 0;
-  if (! definition)
+  if (! (is_variable () && read_only_error ("redefine")))
     {
-      definition = new symbol_def ();
-      definition->count = 1;
-    }
-  else if (is_function ())
-    {
-      symbol_def *new_def = new symbol_def ();
-      push_def (new_def);
-      definition->count = 1;
-    }
-  else if (is_variable ())
-    {
-      saved_def = definition->def ();
+      octave_symbol *saved_def = 0;
+      unsigned int saved_type = symbol_def::UNKNOWN;
+
+      if (! definition)
+	{
+	  definition = new symbol_def ();
+	  definition->count = 1;
+	}
+      else if (is_function ())
+	{
+	  push_def (new symbol_def ());
+	  definition->count = 1;
+	}
+      else if (is_variable ())
+	{
+	  saved_def = definition->def ();
+	  saved_type = definition->symbol_type ();
+	}
+
+      if (saved_type == symbol_def::BUILTIN_VARIABLE)
+	sym_type = saved_type;
+
+      definition->define (new octave_value (v), sym_type);
+
+      if (sv_fcn && sv_fcn () < 0)
+	definition->define (saved_def, saved_type);
+      else
+	{
+	  retval = 1;
+
+	  delete saved_def;
+	}
     }
 
-  definition->define (t);
-
-  if (sv_fcn && sv_fcn () < 0)
-    {
-      // Would be nice to be able to avoid this cast.  XXX FIXME XXX
-
-      definition->define (static_cast<tree_constant *> (saved_def));
-      return 0;
-    }
-
-  delete saved_def;
-
-  return 1;
-}
-
-int
-symbol_record::define (const octave_value& v)
-{
-  tree_constant *t = new tree_constant (v);
-  return define (t);
+  return retval;
 }
 
 int
-symbol_record::define (tree_builtin *t, bool text_fcn)
+symbol_record::define_builtin_var (const octave_value& v)
 {
-  if (read_only_error ("redefine"))
-    return 0;
-
-  if (is_variable ())
-    {
-      symbol_def *old_def = pop_def ();
-      maybe_delete (old_def);
-    }
-
-  if (is_function ())
-    {
-      symbol_def *old_def = pop_def ();
-      maybe_delete (old_def);
-    }
-
-  unsigned fcn_type = text_fcn ? symbol_def::TEXT_FUNCTION
-    : ((t && t->is_mapper_function ()) ? symbol_def::MAPPER_FUNCTION
-       : symbol_def::UNKNOWN);
-
-  symbol_def *new_def = new symbol_def (t, fcn_type);
-  push_def (new_def);
-  definition->count = 1;
-
-  return 1;
-}
-
-int
-symbol_record::define (tree_function *t, bool text_fcn)
-{
-  if (read_only_error ("redefine"))
-    return 0;
-
-  if (is_variable ())
-    {
-      symbol_def *old_def = pop_def ();
-      maybe_delete (old_def);
-    }
-
-  if (is_function ())
-    {
-      symbol_def *old_def = pop_def ();
-      maybe_delete (old_def);
-    }
-
-  unsigned fcn_type = text_fcn ? symbol_def::TEXT_FUNCTION
-    : symbol_def::UNKNOWN;
-
-  symbol_def *new_def = new symbol_def (t, fcn_type);
-  push_def (new_def);
-  definition->count = 1;
-
-  return 1;
+  return define (v, symbol_def::BUILTIN_VARIABLE);
 }
 
 int
@@ -507,22 +418,36 @@
       maybe_delete (old_def);
     }
 
-  tree_constant *t = new tree_constant (v);
-  symbol_def *new_def = new symbol_def (t);
-  push_def (new_def);
+  push_def (new symbol_def (new octave_value (v),
+			    symbol_def::BUILTIN_FUNCTION));
+
   definition->count = 1;
-  definition->type = symbol_def::BUILTIN_FUNCTION;
 
   return 1;
 }
 
 int
-symbol_record::define_builtin_var (const octave_value& v)
+symbol_record::define (octave_function *f, unsigned int sym_type)
 {
-  tree_constant *t = new tree_constant (v);
-  define (t);
+  if (read_only_error ("redefine"))
+    return 0;
+
   if (is_variable ())
-    definition->type = symbol_def::BUILTIN_VARIABLE;
+    {
+      symbol_def *old_def = pop_def ();
+      maybe_delete (old_def);
+    }
+
+  if (is_function ())
+    {
+      symbol_def *old_def = pop_def ();
+      maybe_delete (old_def);
+    }
+
+  push_def (new symbol_def (f, sym_type));
+
+  definition->count = 1;
+
   return 1;
 }
 
@@ -622,8 +547,8 @@
 
   if (is_variable ())
     {
-      tree_constant *tmp = static_cast<tree_constant *> (def ());
-      retval = tmp->value ();
+      octave_symbol *tmp = def ();
+      retval = tmp->eval ();
     }
 
   return retval;
@@ -641,15 +566,14 @@
 	link_to_builtin_variable (this);
 
       if (! is_defined ())
-	{
-	  tree_constant *tmp = new tree_constant ();
-	  define (tmp);
-	}
+	define (octave_value ());
     }
 
-  tree_constant *tmp = static_cast<tree_constant *> (def ());
+  octave_value *tmp = static_cast<octave_value *> (def ());
 
-  return tmp->reference ();
+  tmp->make_unique ();
+
+  return *tmp;
 }
 
 symbol_record *
@@ -672,7 +596,7 @@
       context.push (definition);
       definition = 0;
 
-      global_link_context.push (static_cast<unsigned> (linked_to_global));
+      global_link_context.push (static_cast<unsigned int> (linked_to_global));
       linked_to_global = 0;
     }
 }
@@ -762,9 +686,9 @@
     {
       // Would be nice to avoid this cast.  XXX FIXME XXX
 
-      tree_constant *tmp = static_cast<tree_constant *> (sr.def ());
+      octave_symbol *tmp = sr.def ();
 
-      octave_value vtmp = tmp->value ();
+      octave_value vtmp = tmp->eval ();
 
       const_type = vtmp.type_name ();
 
@@ -1049,8 +973,8 @@
 
 symbol_record_info *
 symbol_table::long_list (int& count, const string_vector& pats,
-			 int npats, bool sort, unsigned type,
-			 unsigned scope) const 
+			 int npats, bool sort, unsigned int type,
+			 unsigned int scope) const 
 {
   count = 0;
   int n = size ();
@@ -1065,9 +989,9 @@
 	{
 	  assert (count < n);
 
-	  unsigned my_scope = ptr->is_linked_to_global () + 1; // Tricky...
+	  unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky...
 
-	  unsigned my_type = ptr->type ();
+	  unsigned int my_type = ptr->type ();
 
 	  string my_name = ptr->name ();
 
@@ -1089,7 +1013,7 @@
 
 string_vector
 symbol_table::list (int& count, const string_vector& pats, int npats,
-		    bool sort, unsigned type, unsigned scope) const
+		    bool sort, unsigned int type, unsigned int scope) const
 {
   count = 0;
   int n = size ();
@@ -1105,9 +1029,9 @@
 	{
 	  assert (count < n);
 
-	  unsigned my_scope = ptr->is_linked_to_global () + 1; // Tricky...
+	  unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky...
 
-	  unsigned my_type = ptr->type ();
+	  unsigned int my_type = ptr->type ();
 
 	  string my_name = ptr->name ();
 
@@ -1128,8 +1052,8 @@
 }
 
 symbol_record **
-symbol_table::glob (int& count, const string& pat, unsigned type,
-		    unsigned scope) const
+symbol_table::glob (int& count, const string& pat, unsigned int type,
+		    unsigned int scope) const
 {
   count = 0;
   int n = size ();
@@ -1144,9 +1068,9 @@
 	{
 	  assert (count < n);
 
-	  unsigned my_scope = ptr->is_linked_to_global () + 1; // Tricky...
+	  unsigned int my_scope = ptr->is_linked_to_global () + 1; // Tricky...
 
-	  unsigned my_type = ptr->type ();
+	  unsigned int my_type = ptr->type ();
 
 	  glob_match pattern (pat);
 
@@ -1199,8 +1123,8 @@
 unsigned int
 symbol_table::hash (const string& str)
 {
-  unsigned h = 0;
-  for (unsigned i = 0; i < str.length (); i++)
+  unsigned int h = 0;
+  for (unsigned int i = 0; i < str.length (); i++)
     h = h * 33 + str[i];
   return h;
 }
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -39,11 +39,8 @@
 #define HASH_TABLE_SIZE 1024
 #define HASH_MASK (HASH_TABLE_SIZE - 1)
 
-class tree;
-class tree_fvc;
-class tree_builtin;
-class tree_constant;
-class tree_function;
+class octave_symbol;
+class octave_function;
 
 class string_vector;
 
@@ -61,10 +58,7 @@
 
 public:
 
-  symbol_def (void);
-  symbol_def (tree_constant *t);
-  symbol_def (tree_builtin *t, unsigned fcn_type = 0);
-  symbol_def (tree_function *t, unsigned fcn_type = 0);
+  symbol_def (octave_symbol *sym = 0, unsigned int sym_type = 0);
 
   ~symbol_def (void);
 
@@ -78,15 +72,13 @@
   bool is_builtin_function (void) const;
   bool is_map_element (const string& elts) const;
 
-  void define (tree_constant *t);
-  void define (tree_builtin *t, unsigned fcn_type = 0);
-  void define (tree_function *t, unsigned fcn_type = 0);
+  void define (octave_symbol *sym, unsigned int sym_type);
 
   void protect (void);
   void unprotect (void);
   void make_eternal (void);
 
-  tree_fvc *def (void) const;
+  octave_symbol *def (void) const;
   string help (void) const;
   void document (const string& h);
 
@@ -101,16 +93,18 @@
       BUILTIN_VARIABLE = 32
     };
 
+  unsigned int symbol_type (void) { return type; }
+
   friend maybe_delete (symbol_def *def);
 
 private:
 
-  unsigned type : 6;
-  unsigned eternal : 1;
-  unsigned read_only : 1;
+  unsigned int type : 6;
+  unsigned int eternal : 1;
+  unsigned int read_only : 1;
 
   string help_string;
-  tree_fvc *definition;
+  octave_symbol *definition;
   symbol_def *next_elem;
   int count;
 
@@ -135,7 +129,7 @@
 
   string name (void) const;
   string help (void) const; 
-  tree_fvc *def (void) const;
+  octave_symbol *def (void) const;
 
   void rename (const string& new_name);
 
@@ -149,7 +143,7 @@
   bool is_builtin_variable (void) const;
   bool is_map_element (const string& elts) const;
 
-  unsigned type (void) const;
+  unsigned int type (void) const;
 
   bool is_defined (void) const;
   bool is_read_only (void) const;
@@ -161,13 +155,15 @@
 
   void set_sv_function (sv_Function f);
 
-  int define (tree_constant *t);
-  int define (const octave_value& v);
-  int define (tree_builtin *t, bool text_fcn = false);
-  int define (tree_function *t, bool text_fcn = false);
+  int define (const octave_value& v,
+	      unsigned int sym_type = symbol_def::USER_VARIABLE);
+
   int define_as_fcn (const octave_value& v);
+
   int define_builtin_var (const octave_value& v);
 
+  int define (octave_function *f, unsigned int sym_type);
+
   void document (const string& h);
 
   int clear (void);
@@ -195,9 +191,9 @@
 
 private:
 
-  unsigned formal_param : 1;
-  unsigned linked_to_global : 1;
-  unsigned tagged_static : 1;
+  unsigned int formal_param : 1;
+  unsigned int linked_to_global : 1;
+  unsigned int tagged_static : 1;
 
   string nm;
   sv_Function sv_fcn;
@@ -207,7 +203,7 @@
 // This should maybe be one stack with a structure containing all the
 // items we need to save for recursive calls...
   SLStack <symbol_def *> context;
-  SLStack <unsigned> global_link_context;
+  SLStack <unsigned int> global_link_context;
 
   void init_state (void);
 
@@ -258,10 +254,10 @@
   bool initialized;
   int nr;
   int nc;
-  unsigned type : 6;
-  unsigned hides : 2;
-  unsigned eternal : 1;
-  unsigned read_only : 1;
+  unsigned int type : 6;
+  unsigned int hides : 2;
+  unsigned int eternal : 1;
+  unsigned int read_only : 1;
   string nm;
   string const_type;
 };
@@ -303,17 +299,18 @@
   symbol_record_info *
   long_list (int& count, const string_vector& pats = string_vector (),
 	     int npats = 0, bool sort = false,
-	     unsigned type = SYMTAB_ALL_TYPES,
-	     unsigned scope = SYMTAB_ALL_SCOPES) const;
+	     unsigned int type = SYMTAB_ALL_TYPES,
+	     unsigned int scope = SYMTAB_ALL_SCOPES) const;
 
   string_vector
   list (int& count, const string_vector& pats = string_vector (),
-	int npats = 0, bool sort = false, unsigned type = SYMTAB_ALL_TYPES,
-	unsigned scope = SYMTAB_ALL_SCOPES) const;
+	int npats = 0, bool sort = false,
+	unsigned int type = SYMTAB_ALL_TYPES,
+	unsigned int scope = SYMTAB_ALL_SCOPES) const;
 
   symbol_record **glob (int& count, const string& pat = string ("*"),
-			unsigned type = SYMTAB_ALL_TYPES,
-			unsigned scope = SYMTAB_ALL_SCOPES) const;
+			unsigned int type = SYMTAB_ALL_TYPES,
+			unsigned int scope = SYMTAB_ALL_SCOPES) const;
 
   void push_context (void);
   void pop_context (void);
--- a/src/sysdep.cc
+++ b/src/sysdep.cc
@@ -79,6 +79,7 @@
 extern char *term_clrpag;
 extern "C" void _rl_output_character_function ();
 
+#include "lo-mappers.h"
 #include "mach-info.h"
 #include "oct-math.h"
 
@@ -86,7 +87,6 @@
 #include "error.h"
 #include "help.h"
 #include "input.h"
-#include "mappers.h"
 #include "oct-obj.h"
 #include "pathlen.h"
 #include "ov.h"