changeset 3195:7a5a5da64756

[project @ 1998-10-28 22:54:04 by jwe]
author jwe
date Wed, 28 Oct 1998 23:01:17 +0000
parents bea685644090
children 3ac3e8edc258
files src/Makefile.in src/OPERATORS/op-list.cc src/data.cc src/defaults.cc src/defaults.h.in src/fn-cache.cc src/help.cc src/oct-obj.cc src/oct-obj.h src/oct-procbuf.cc src/octave.cc src/ops.h src/ov-base.cc src/ov-base.h src/ov-bool-mat.h src/ov-bool.h src/ov-ch-mat.h src/ov-complex.h src/ov-cx-mat.h src/ov-range.h src/ov-re-mat.h src/ov-scalar.h src/ov.h src/parse.y src/pt-unop.h src/utils.cc src/xdiv.cc
diffstat 27 files changed, 279 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -96,7 +96,7 @@
 
 OP_XSRC := op-b-b.cc op-bm-bm.cc op-cm-cm.cc op-cm-cs.cc \
 	op-cm-m.cc op-cm-s.cc op-cs-cm.cc op-cs-cs.cc op-cs-m.cc \
-	op-cs-s.cc op-m-cm.cc op-m-cs.cc op-m-m.cc op-m-s.cc \
+	op-cs-s.cc op-list.cc op-m-cm.cc op-m-cs.cc op-m-m.cc op-m-s.cc \
 	op-s-cm.cc op-s-cs.cc op-s-m.cc op-s-s.cc op-str-str.cc \
 	op-fil-b.cc op-fil-bm.cc op-fil-cm.cc op-fil-cs.cc \
 	op-fil-m.cc op-fil-s.cc op-fil-lis.cc op-fil-rec.cc \
new file mode 100644
--- /dev/null
+++ b/src/OPERATORS/op-list.cc
@@ -0,0 +1,51 @@
+/*
+
+Copyright (C) 1996, 1997 John W. Eaton
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option) any
+later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+*/
+
+#if defined (__GNUG__)
+#pragma implementation
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gripes.h"
+#include "ov.h"
+#include "ov-list.h"
+#include "ov-typeinfo.h"
+#include "ops.h"
+
+// list ops.
+
+DEFASSIGNANYOP_FN (assign, list, assign);
+
+void
+install_list_ops (void)
+{
+  INSTALL_ASSIGNANYOP (asn_eq, octave_list, assign);
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
--- a/src/data.cc
+++ b/src/data.cc
@@ -598,6 +598,30 @@
   return retval;
 }
 
+DEFUN (length, args, ,
+  "length (x): return the `length' of the object X\n\
+\n\
+For matrix objects, the length is the number of rows or columns,\n\
+whichever is greater (this odd definition is used for compatibility\n\
+with Matlab).\n\
+\n\
+See also: size, rows, columns, is_scalar, is_vector, is_matrix")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    {
+      int len = args(0).length ();
+
+      if (! error_state)
+	retval = static_cast<double> (len);
+    }
+  else
+    print_usage ("length");
+
+  return retval;
+}
+
 DEFUN (size, args, nargout,
   "[m, n] = size (x): return rows and columns of X\n\
 \n\
--- a/src/defaults.cc
+++ b/src/defaults.cc
@@ -68,7 +68,7 @@
 
 // Load path specified on command line.
 // (--path path; -p path)
-string Vload_path;
+static string Vload_path;
 
 // The default load path with OCTAVE_HOME appropriately substituted.
 static string Vdefault_load_path;
@@ -176,11 +176,6 @@
     Vexec_path = string (octave_exec_path);
 }
 
-// Handle OCTAVE_PATH from the environment like TeX handles TEXINPUTS.
-// If the path starts with `:', prepend the standard path.  If it ends
-// with `:' append the standard path.  If it begins and ends with
-// `:', do both (which is useless, but the luser asked for it...).
-
 static void
 set_default_path (void)
 {
@@ -188,10 +183,9 @@
 
   string oct_path = octave_env::getenv ("OCTAVE_PATH");
 
-  Vload_path = oct_path.empty ()
-    ? Vdefault_load_path : maybe_add_default_path (oct_path);
+  Vload_path = oct_path.empty () ? string (":") : oct_path;
 
-  Vload_path_dir_path = dir_path (Vload_path);
+  Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path);
 }
 
 static void
@@ -410,9 +404,9 @@
     }
   else
     {
-      Vload_path = maybe_add_default_load_path (s);
+      Vload_path = s;
 
-      Vload_path_dir_path = dir_path (Vload_path);
+      Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path);
     }
 
   return status;
@@ -427,7 +421,7 @@
   DEFVAR (EXEC_PATH, Vexec_path, 0, exec_path,
     "colon separated list of directories to search for programs to run");
 
-  DEFVAR (LOADPATH, ":", 0, octave_loadpath,
+  DEFVAR (LOADPATH, ":", 0, 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\
--- a/src/defaults.h.in
+++ b/src/defaults.h.in
@@ -130,10 +130,6 @@
 // (--exec-path path)
 extern string Vexec_path;
 
-// Load path specified on command line.
-// (--path path; -p path)
-extern string Vload_path;
-
 // And the cached directory path corresponding to Vload_path.
 extern dir_path Vload_path_dir_path;
 
--- a/src/fn-cache.cc
+++ b/src/fn-cache.cc
@@ -48,7 +48,7 @@
 {
   bool something_changed = false;
 
-  dir_path p = path.empty () ? dir_path (Vload_path) : dir_path (path);
+  dir_path p = path.empty () ? Vload_path_dir_path : dir_path (path);
 
   string_vector dirs = p.all_directories ();
 
@@ -111,7 +111,7 @@
 
   int total_len = 0;
 
-  dir_path p = path.empty () ? dir_path (Vload_path) : dir_path (path);
+  dir_path p = path.empty () ? Vload_path_dir_path : dir_path (path);
 
   string_vector dirs = p.all_directories ();
 
--- a/src/help.cc
+++ b/src/help.cc
@@ -552,9 +552,7 @@
 
   // Also need to search octave_path for script files.
 
-  dir_path p (Vload_path);
-
-  string_vector dirs = p.all_directories ();
+  string_vector dirs = Vload_path_dir_path.all_directories ();
 
   int len = dirs.length ();
 
--- a/src/oct-obj.cc
+++ b/src/oct-obj.cc
@@ -93,6 +93,46 @@
   return *this;
 }
 
+octave_value_list
+octave_value_list::splice (int offset, int rep_length,
+			   const octave_value_list& lst) const
+{ 
+  octave_value_list retval;
+
+  int len = length ();
+
+  if (offset < 0 || offset >= len)
+    {
+      error ("octave_value_list::splice: invalid OFFSET");
+      return retval;
+    }
+
+  if (rep_length < 0 || rep_length + offset > len)
+    {
+      error ("octave_value_list::splice: invalid LENGTH");
+      return retval;
+    }
+
+  int lst_len = lst.length ();
+
+  int new_len = len - rep_length + lst_len;
+
+  retval.resize (new_len);
+
+  int k = 0;
+
+  for (int i = 0; i < offset; i++)
+    retval(k++) = elem (i);
+
+  for (int i = 0; i < lst_len; i++)
+    retval(k++) = lst(i);
+
+  for (int i = offset + rep_length; i < len; i++)
+    retval(k++) = elem (i);
+
+  return retval;
+}
+
 bool
 octave_value_list::all_strings_p (void) const
 {
--- a/src/oct-obj.h
+++ b/src/oct-obj.h
@@ -133,6 +133,9 @@
 
   octave_value_list& reverse (void);
 
+  octave_value_list splice (int offset, int length,
+			    const octave_value_list& lst) const;
+
   bool all_strings_p (void) const;
 
   string_vector make_argv (const string&) const;
--- a/src/oct-procbuf.cc
+++ b/src/oct-procbuf.cc
@@ -202,7 +202,7 @@
   return -1;
 }
 
-static void
+void
 symbols_of_oct_procbuf (void)
 {
   DEFVAR (kluge_procbuf_delay, static_cast<double> (Vkluge_procbuf_delay),
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -58,6 +58,7 @@
 #include "input.h"
 #include "lex.h"
 #include "oct-hist.h"
+#include "oct-obj.h"
 #include "ops.h"
 #include "toplev.h"
 #include "parse.h"
@@ -153,17 +154,20 @@
 static void
 intern_argv (int argc, char **argv)
 {
+  bind_builtin_variable ("nargin", static_cast<double> (argc-1), 1, 1, 0);
+
+  octave_value_list octave_argv;
+
   if (argc > 1)
     {
       // Skip program name in argv.
-
-      octave_argv = string_vector (argv+1, argc-1);
+      while (--argc > 0)
+	octave_argv(argc-1) = octave_value (*(argv+argc));
 
-      bind_builtin_variable ("argv", octave_argv, 1, 1, 0);
-      bind_builtin_variable ("__argv__", octave_argv, 1, 1, 0);
     }
 
-  bind_builtin_variable ("nargin", static_cast<double> (argc-1), 1, 1, 0);
+  bind_builtin_variable ("argv", octave_argv, 1, 1, 0);
+  bind_builtin_variable ("__argv__", octave_argv, 1, 1, 0);
 }
 
 static void
--- a/src/ops.h
+++ b/src/ops.h
@@ -33,6 +33,10 @@
   octave_value_typeinfo::register_assign_op \
     (octave_value::op, t1::static_type_id (), t2::static_type_id (), f);
 
+#define INSTALL_ASSIGNANYOP(op, t1, f) \
+  octave_value_typeinfo::register_assignany_op \
+    (octave_value::op, t1::static_type_id (), f);
+
 #define INSTALL_ASSIGNCONV(t1, t2, tr) \
   octave_value_typeinfo::register_pref_assign_conv \
     (t1::static_type_id (), t2::static_type_id (), tr::static_type_id ());
@@ -134,6 +138,15 @@
     return octave_value (); \
   }
 
+#define DEFASSIGNANYOP_FN(name, t1, f) \
+  ASSIGNOPDECL (name) \
+  { \
+    octave_ ## t1& v1 = DYNAMIC_CAST (octave_ ## t1&, a1); \
+ \
+    v1.f (idx, a2); \
+    return octave_value (); \
+  }
+
 #define CONVDECL(name) \
   static octave_value * \
   name (const octave_value& a)
--- a/src/ov-base.cc
+++ b/src/ov-base.cc
@@ -124,13 +124,13 @@
 void
 octave_base_value::print (ostream&, bool) const
 {
-  gripe_wrong_type_arg ("octave_base_value::print()", type_name ());
+  gripe_wrong_type_arg ("octave_base_value::print ()", type_name ());
 }
 
 void
 octave_base_value::print_raw (ostream&, bool) const
 {
-  gripe_wrong_type_arg ("octave_base_value::print_raw()", type_name ());
+  gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ());
 }
 
 bool
@@ -143,6 +143,30 @@
   return true;
 }
 
+int
+octave_base_value::rows (void) const
+{
+  int retval = -1;
+  gripe_wrong_type_arg ("octave_base_value::rows ()", type_name ());
+  return retval;
+}
+
+int
+octave_base_value::columns (void) const
+{
+  int retval = -1;
+  gripe_wrong_type_arg ("octave_base_value::columns ()", type_name ());
+  return retval;
+}
+
+int
+octave_base_value::length (void) const
+{
+  int retval = -1;
+  gripe_wrong_type_arg ("octave_base_value::length ()", type_name ());
+  return retval;
+}
+
 double
 octave_base_value::double_value (bool) const
 {
--- a/src/ov-base.h
+++ b/src/ov-base.h
@@ -84,9 +84,10 @@
 
   octave_lvalue struct_elt_ref (octave_value *parent, const string& nm);
 
-  int rows (void) const { return -1; }
+  int rows (void) const;
+  int columns (void) const;
 
-  int columns (void) const { return -1; }
+  int length (void) const;
 
   bool is_defined (void) const { return false; }
 
--- a/src/ov-bool-mat.h
+++ b/src/ov-bool-mat.h
@@ -84,6 +84,14 @@
   int rows (void) const { return matrix.rows (); }
   int columns (void) const { return matrix.columns (); }
 
+  int length (void) const
+  {
+    int r = rows ();
+    int c = columns ();
+
+    return r > c ? r : c;
+  }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-bool.h
+++ b/src/ov-bool.h
@@ -81,6 +81,8 @@
   int rows (void) const { return 1; }
   int columns (void) const { return 1; }
 
+  int length (void) const { return 1; }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-ch-mat.h
+++ b/src/ov-ch-mat.h
@@ -87,6 +87,14 @@
   int rows (void) const { return matrix.rows (); }
   int columns (void) const { return matrix.columns (); }
 
+  int length (void) const
+  {
+    int r = rows ();
+    int c = columns ();
+
+    return r > c ? r : c;
+  }
+
   bool is_constant (void) const { return true; }
 
   bool is_defined (void) const { return true; }
--- a/src/ov-complex.h
+++ b/src/ov-complex.h
@@ -79,6 +79,14 @@
   int rows (void) const { return 1; }
   int columns (void) const { return 1; }
 
+  int length (void) const
+  {
+    int r = rows ();
+    int c = columns ();
+
+    return r > c ? r : c;
+  }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-cx-mat.h
+++ b/src/ov-cx-mat.h
@@ -90,6 +90,14 @@
   int rows (void) const { return matrix.rows (); }
   int columns (void) const { return matrix.columns (); }
 
+  int length (void) const
+  {
+    int r = rows ();
+    int c = columns ();
+
+    return r > c ? r : c;
+  }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-range.h
+++ b/src/ov-range.h
@@ -98,6 +98,8 @@
   int rows (void) const { return (columns () > 0); }
   int columns (void) const { return range.nelem (); }
 
+  int length (void) const { return range.nelem (); }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-re-mat.h
+++ b/src/ov-re-mat.h
@@ -105,6 +105,14 @@
   int rows (void) const { return matrix.rows (); }
   int columns (void) const { return matrix.columns (); }
 
+  int length (void) const
+  {
+    int r = rows ();
+    int c = columns ();
+
+    return r > c ? r : c;
+  }
+
   bool is_defined (void) const { return true; }
 
   bool is_constant (void) const { return true; }
--- a/src/ov-scalar.h
+++ b/src/ov-scalar.h
@@ -80,6 +80,8 @@
   int rows (void) const { return 1; }
   int columns (void) const { return 1; }
 
+  int length (void) const { return 1; }
+
   bool is_constant (void) const { return true; }
 
   bool is_defined (void) const { return true; }
--- a/src/ov.h
+++ b/src/ov.h
@@ -258,6 +258,9 @@
   virtual int columns (void) const
     { return rep->columns (); }
 
+  virtual int length (void) const
+    { return rep->length (); }
+
   // Does this constant have a type?  Both of these are provided since
   // it is sometimes more natural to write is_undefined() instead of
   // ! is_defined().
@@ -553,6 +556,10 @@
 // Allow divide by zero errors to be suppressed.
 extern bool Vwarn_divide_by_zero;
 
+// If TRUE, resize matrices when performing and indexed assignment and
+// the indices are outside the current bounds.
+extern bool Vresize_on_range_error;
+
 // Indentation level for structures.
 extern int struct_indent;
 
--- a/src/parse.y
+++ b/src/parse.y
@@ -1872,7 +1872,7 @@
 
   // XXX FIXME XXX -- what about constant folding here?
 
-  return new tree_prefix_expression (t, op1, l, c);
+  return new tree_prefix_expression (op1, l, c, t);
 }
 
 // Build a postfix expression.
@@ -1910,7 +1910,7 @@
 
   // XXX FIXME XXX -- what about constant folding here?
 
-  return new tree_postfix_expression (t, op1, l, c);
+  return new tree_postfix_expression (op1, l, c, t);
 }
 
 // Build an unwind-protect command.
--- a/src/pt-unop.h
+++ b/src/pt-unop.h
@@ -85,8 +85,8 @@
   tree_prefix_expression (int l = -1, int c = -1)
     : tree_unary_expression (l, c), etype (unknown) { }
 
-  tree_prefix_expression (type t = unknown, tree_expression *e,
-			  int l = -1, int c = -1)
+  tree_prefix_expression (tree_expression *e, int l = -1, int c = -1,
+			  type t = unknown)
     : tree_unary_expression (e, l, c), etype (t) { }
 
   ~tree_prefix_expression (void) { }
@@ -135,8 +135,8 @@
   tree_postfix_expression (int l = -1, int c = -1)
     : tree_unary_expression (l, c), etype (unknown) { }
 
-  tree_postfix_expression (type t = unknown, tree_expression *e,
-			   int l = -1, int c = -1)
+  tree_postfix_expression (tree_expression *e, int l = -1, int c = -1,
+			   type t = unknown)
     : tree_unary_expression (e, l, c), etype (t) { }
 
   ~tree_postfix_expression (void) { }
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -235,6 +235,29 @@
   return octave_env::make_absolute (p.find (name), octave_env::getcwd ());
 }
 
+DEFUN (file_in_loadpath, args, ,
+  "file_in_loadpath (NAME)\n\
+\n\
+Look up NAME in LOADPATH.  See also file_in_path")
+{
+  octave_value_list retval;
+
+  int argc = args.length () + 1;
+
+  string_vector argv = args.make_argv ("file_in_loadpath");
+
+  if (error_state)
+    return retval;
+
+  if (argc == 3)
+    retval = octave_env::make_absolute (Vload_path_dir_path.find (argv[1]),
+					octave_env::getcwd ());
+  else
+    print_usage ("file_in_loadpath");
+
+  return retval;
+}
+
 DEFUN (file_in_path, args, ,
   "file_in_path (PATH, NAME)")
 {
@@ -249,9 +272,7 @@
 
   if (argc == 3)
     {
-      string path = maybe_add_default_load_path (argv[1]);
-
-      string fname = search_path_for_file (path, argv[2]);
+      string fname = search_path_for_file (argv[1], argv[2]);
 
       if (fname.empty ())
 	retval = Matrix ();
--- a/src/xdiv.cc
+++ b/src/xdiv.cc
@@ -53,7 +53,7 @@
 
 template <class T1, class T2>
 bool
-mx_leftdiv_conform (T1 a, T2 b)
+mx_leftdiv_conform (const T1& a, const T2& b)
 {
   int a_nr = a.rows ();
   int b_nr = b.rows ();
@@ -70,14 +70,17 @@
   return true;
 }
 
-template bool mx_leftdiv_conform (Matrix&, Matrix&);
-template bool mx_leftdiv_conform (Matrix&, ComplexMatrix&);
-template bool mx_leftdiv_conform (ComplexMatrix&, ComplexMatrix&);
-template bool mx_leftdiv_conform (ComplexMatrix&, Matrix&);
+#define INSTANTIATE_MX_LEFTDIV_CONFORM(T1, T2) \
+  template bool mx_leftdiv_conform (const T1&, const T2&)
+
+INSTANTIATE_MX_LEFTDIV_CONFORM (Matrix, Matrix);
+INSTANTIATE_MX_LEFTDIV_CONFORM (Matrix, ComplexMatrix);
+INSTANTIATE_MX_LEFTDIV_CONFORM (ComplexMatrix, Matrix);
+INSTANTIATE_MX_LEFTDIV_CONFORM (ComplexMatrix, ComplexMatrix);
 
 template <class T1, class T2>
 bool
-mx_div_conform (T1 a, T2 b)
+mx_div_conform (const T1& a, const T2& b)
 {
   int a_nc = a.cols ();
   int b_nc = b.cols ();
@@ -94,10 +97,13 @@
   return true;
 }
 
-template bool mx_div_conform (Matrix&, Matrix&);
-template bool mx_div_conform (Matrix&, ComplexMatrix&);
-template bool mx_div_conform (ComplexMatrix&, ComplexMatrix&);
-template bool mx_div_conform (ComplexMatrix&, Matrix&);
+#define INSTANTIATE_MX_DIV_CONFORM(T1, T2) \
+  template bool mx_div_conform (const T1&, const T2&)
+
+INSTANTIATE_MX_DIV_CONFORM (Matrix, Matrix);
+INSTANTIATE_MX_DIV_CONFORM (Matrix, ComplexMatrix);
+INSTANTIATE_MX_DIV_CONFORM (ComplexMatrix, Matrix);
+INSTANTIATE_MX_DIV_CONFORM (ComplexMatrix, ComplexMatrix);
 
 // Right division functions.
 //