# HG changeset patch # User jwe # Date 909615677 0 # Node ID 7a5a5da64756e676655bc655928a31bdce8859a0 # Parent bea685644090df20e51e407ed1eacedaecb195a3 [project @ 1998-10-28 22:54:04 by jwe] diff -r bea685644090 -r 7a5a5da64756 src/Makefile.in --- a/src/Makefile.in Wed Oct 28 17:51:09 1998 +0000 +++ b/src/Makefile.in Wed Oct 28 23:01:17 1998 +0000 @@ -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 \ diff -r bea685644090 -r 7a5a5da64756 src/OPERATORS/op-list.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/OPERATORS/op-list.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 +#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: *** +*/ diff -r bea685644090 -r 7a5a5da64756 src/data.cc --- a/src/data.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/data.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 (len); + } + else + print_usage ("length"); + + return retval; +} + DEFUN (size, args, nargout, "[m, n] = size (x): return rows and columns of X\n\ \n\ diff -r bea685644090 -r 7a5a5da64756 src/defaults.cc --- a/src/defaults.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/defaults.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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\ diff -r bea685644090 -r 7a5a5da64756 src/defaults.h.in --- a/src/defaults.h.in Wed Oct 28 17:51:09 1998 +0000 +++ b/src/defaults.h.in Wed Oct 28 23:01:17 1998 +0000 @@ -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; diff -r bea685644090 -r 7a5a5da64756 src/fn-cache.cc --- a/src/fn-cache.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/fn-cache.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 (); diff -r bea685644090 -r 7a5a5da64756 src/help.cc --- a/src/help.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/help.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 (); diff -r bea685644090 -r 7a5a5da64756 src/oct-obj.cc --- a/src/oct-obj.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/oct-obj.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 { diff -r bea685644090 -r 7a5a5da64756 src/oct-obj.h --- a/src/oct-obj.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/oct-obj.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; diff -r bea685644090 -r 7a5a5da64756 src/oct-procbuf.cc --- a/src/oct-procbuf.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/oct-procbuf.cc Wed Oct 28 23:01:17 1998 +0000 @@ -202,7 +202,7 @@ return -1; } -static void +void symbols_of_oct_procbuf (void) { DEFVAR (kluge_procbuf_delay, static_cast (Vkluge_procbuf_delay), diff -r bea685644090 -r 7a5a5da64756 src/octave.cc --- a/src/octave.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/octave.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 (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 (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 diff -r bea685644090 -r 7a5a5da64756 src/ops.h --- a/src/ops.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ops.h Wed Oct 28 23:01:17 1998 +0000 @@ -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) diff -r bea685644090 -r 7a5a5da64756 src/ov-base.cc --- a/src/ov-base.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-base.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 { diff -r bea685644090 -r 7a5a5da64756 src/ov-base.h --- a/src/ov-base.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-base.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-bool-mat.h --- a/src/ov-bool-mat.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-bool-mat.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-bool.h --- a/src/ov-bool.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-bool.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-ch-mat.h --- a/src/ov-ch-mat.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-ch-mat.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-complex.h --- a/src/ov-complex.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-complex.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-cx-mat.h --- a/src/ov-cx-mat.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-cx-mat.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-range.h --- a/src/ov-range.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-range.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-re-mat.h --- a/src/ov-re-mat.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-re-mat.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov-scalar.h --- a/src/ov-scalar.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov-scalar.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; } diff -r bea685644090 -r 7a5a5da64756 src/ov.h --- a/src/ov.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/ov.h Wed Oct 28 23:01:17 1998 +0000 @@ -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; diff -r bea685644090 -r 7a5a5da64756 src/parse.y --- a/src/parse.y Wed Oct 28 17:51:09 1998 +0000 +++ b/src/parse.y Wed Oct 28 23:01:17 1998 +0000 @@ -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. diff -r bea685644090 -r 7a5a5da64756 src/pt-unop.h --- a/src/pt-unop.h Wed Oct 28 17:51:09 1998 +0000 +++ b/src/pt-unop.h Wed Oct 28 23:01:17 1998 +0000 @@ -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) { } diff -r bea685644090 -r 7a5a5da64756 src/utils.cc --- a/src/utils.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/utils.cc Wed Oct 28 23:01:17 1998 +0000 @@ -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 (); diff -r bea685644090 -r 7a5a5da64756 src/xdiv.cc --- a/src/xdiv.cc Wed Oct 28 17:51:09 1998 +0000 +++ b/src/xdiv.cc Wed Oct 28 23:01:17 1998 +0000 @@ -53,7 +53,7 @@ template 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 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. //