changeset 3977:95663a3a2682

[project @ 2002-07-05 17:43:37 by jwe]
author jwe
date Fri, 05 Jul 2002 17:43:38 +0000
parents 4038f12b8eea
children 10bc4c350d61
files src/ChangeLog src/Makefile.in src/ov-base.h src/ov-cell.cc src/ov.cc src/ov.h src/pt-arg-list.cc src/pt-arg-list.h src/pt-assign.cc
diffstat 9 files changed, 136 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,23 @@
+2002-07-05  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* pt-assign.cc (tree_multi_assignment::rvalue): Call
+	lhs->nargout_count, not lhs->length.
+
+	* pt-arg-list.cc (tree_argument_list::convert_to_const_vector):
+	Handle cs-list objects here.
+	(tree_argument_list::nargout_count): New function.
+	* pt-arg-list.h: Provide decl.
+
+	* ov-cs-list.h, ov-cs-list.cc: New files.
+	* Makefile.in: Add them to the appropriate lists.
+
+	* ov.cc: Include ov-cs-list.h.
+	New arg, is_cs_list for constructor taking octave_value_list arg.
+	(install_types): Register ov_cs_list.
+	* ov.h (octave_value::is_cs_list): New function.
+	* ov-base.h (octave_base_value::is_cs_list): Likewise.
+	* ov-cell.cc (octave_cell::subsref): Return cs-list for "{" indexing.
+
 2002-07-04  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* pt-mat.cc (Vempty_list_elements_ok): Default value is now 1.
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -64,7 +64,7 @@
   DLD_STATIC_OBJ := $(DLD_OBJ)
 endif
 
-OV_INCLUDES := ov-re-mat.h ov-cx-mat.h ov-ch-mat.h ov-list.h \
+OV_INCLUDES := ov-re-mat.h ov-cx-mat.h ov-ch-mat.h ov-cs-list.h 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-base-mat.h ov-base-scalar.h \
 	ov-str-mat.h ov-bool-mat.h ov-bool.h ov-file.h ov-cell.h ov.h \
@@ -108,7 +108,8 @@
 OP_SRC := $(addprefix OPERATORS/, $(OP_XSRC))
 
 OV_SRC := ov-base.cc ov-base-mat.cc ov-base-scalar.cc ov-ch-mat.cc \
-	ov-list.cc ov-re-mat.cc ov-cx-mat.cc ov-range.cc ov-scalar.cc \
+	ov-cs-list.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-cell.cc \
 	ov.cc ov-fcn.cc ov-builtin.cc ov-dld-fcn.cc ov-mapper.cc \
--- a/src/ov-base.h
+++ b/src/ov-base.h
@@ -120,6 +120,8 @@
 
   bool is_stream (void) const { return false; }
 
+  bool is_cs_list (void) const { return false; }
+
   bool is_list (void) const { return false; }
 
   bool is_magic_colon (void) const { return false; }
--- a/src/ov-cell.cc
+++ b/src/ov-cell.cc
@@ -79,7 +79,7 @@
 	    for (int j = 0; j < nc; j++)
 	      for (int i = 0; i < nr; i++)
 		lst(k++) = tcell(i,j);
-	    retval = lst;
+	    retval = octave_value (lst, true);
 	  }
       }
       break;
--- a/src/ov.cc
+++ b/src/ov.cc
@@ -47,6 +47,7 @@
 #include "ov-struct.h"
 #include "ov-file.h"
 #include "ov-list.h"
+#include "ov-cs-list.h"
 #include "ov-colon.h"
 #include "ov-va-args.h"
 #include "ov-builtin.h"
@@ -489,9 +490,14 @@
   rep->count = 1;
 }
 
-octave_value::octave_value (const octave_value_list& l)
-  : rep (new octave_list (l))
+octave_value::octave_value (const octave_value_list& l, bool is_cs_list)
+  : rep (0)
 {
+  if (is_cs_list)
+    rep = new octave_cs_list (l);
+  else
+    new octave_list (l);
+
   rep->count = 1;
 }
 
@@ -1530,6 +1536,7 @@
   octave_struct::register_type ();
   octave_file::register_type ();
   octave_list::register_type ();
+  octave_cs_list::register_type ();
   octave_all_va_args::register_type ();
   octave_magic_colon::register_type ();
   octave_builtin::register_type ();
--- a/src/ov.h
+++ b/src/ov.h
@@ -179,7 +179,7 @@
   octave_value (const Octave_map& m);
   octave_value (const octave_stream& s, int n);
   octave_value (octave_function *f);
-  octave_value (const octave_value_list& m);
+  octave_value (const octave_value_list& m, bool is_cs_list = false);
   octave_value (octave_value::magic_colon);
   octave_value (octave_value::all_va_args);
 
@@ -336,6 +336,9 @@
   virtual bool is_stream (void) const
     { return rep->is_stream (); }
 
+  virtual bool is_cs_list (void) const
+    { return rep->is_cs_list (); }
+
   virtual bool is_list (void) const
     { return rep->is_list (); }
 
--- a/src/pt-arg-list.cc
+++ b/src/pt-arg-list.cc
@@ -55,6 +55,25 @@
     }
 }
 
+int
+tree_argument_list::nargout_count (void) const
+{
+  int retval = 0;
+
+  for (Pix p = first (); p != 0; next (p))
+    {
+      tree_expression *elt = this->operator () (p);
+
+      // XXX FIXME XXX -- need to be able to determine whether elt is
+      // an expression that could evaluate to a cs-list object, and if
+      // so, how many elements are in that list.  Ugly!
+
+      retval++;
+    }
+
+  return retval;
+}
+
 bool
 tree_argument_list::all_elements_are_constant (void) const
 {
@@ -79,7 +98,8 @@
   // token.
 
   octave_value_list args;
-  args.resize (len);
+  int args_len = len;
+  args.resize (args_len);
 
   Pix p = first ();
   int j = 0;
@@ -106,6 +126,8 @@
 		      octave_value_list tva;
 		      tva = curr_function->octave_all_va_args ();
 		      int n = tva.length ();
+		      args_len += n - 1;
+		      args.resize (args_len);
 		      for (int i = 0; i < n; i++)
 			args(j++) = tva(i);
 		    }
@@ -116,6 +138,15 @@
 		      break;
 		    }
 		}
+	      else if (tmp.is_cs_list ())
+		{
+		  octave_value_list tl = tmp.list_value ();
+		  int n = tl.length ();
+		  args_len += n - 1;
+		  args.resize (args_len);
+		  for (int i = 0; i < n; i++)
+		    args(j++) = tl(i);
+		}
 	      else
 		args(j++) = tmp;
 	    }
--- a/src/pt-arg-list.h
+++ b/src/pt-arg-list.h
@@ -53,6 +53,8 @@
 
   ~tree_argument_list (void);
 
+  int nargout_count (void) const;
+
   bool all_elements_are_constant (void) const;
 
   octave_value_list convert_to_const_vector (void);
--- a/src/pt-assign.cc
+++ b/src/pt-assign.cc
@@ -208,84 +208,86 @@
 
   if (rhs)
     {
-      int n_out = lhs->length ();
+      int n_out = lhs->nargout_count ();
+
+      if (error_state)
+	return retval;
 
       octave_value_list rhs_val = rhs->rvalue (n_out);
 
-      if (! error_state)
-	{
-	  if (rhs_val.empty ())
-	    {
-	      error ("value on right hand side of assignment is undefined");
-	      eval_error ();
-	    }
-	  else
-	    {
-	      int k = 0;
-
-	      int n = rhs_val.length ();
+      if (error_state)
+	return retval;
 
-	      retval.resize (n, octave_value ());
-
-	      for (Pix p = lhs->first (); p != 0; lhs->next (p))
-		{
-		  tree_expression *lhs_elt = lhs->operator () (p);
+      if (rhs_val.empty ())
+	{
+	  error ("value on right hand side of assignment is undefined");
+	  eval_error ();
+	}
+      else
+	{
+	  int k = 0;
 
-		  if (lhs_elt)
-		    {
-		      octave_lvalue ult = lhs_elt->lvalue ();
+	  int n = rhs_val.length ();
 
-		      if (error_state)
-			eval_error ();
-		      else if (k < n)
-			{
-			  ult.assign (etype, rhs_val(k));
+	  retval.resize (n, octave_value ());
 
-			  if (! error_state)
-			    {
-			      if (etype == octave_value::op_asn_eq)
-				retval(k) = rhs_val(k);
-			      else
-				retval(k) = ult.value ();
-			    }
-			}
-		      else
-			error ("element number %d undefined in return list",
-			       k+1);
+	  for (Pix p = lhs->first (); p != 0; lhs->next (p))
+	    {
+	      tree_expression *lhs_elt = lhs->operator () (p);
+
+	      if (lhs_elt)
+		{
+		  octave_lvalue ult = lhs_elt->lvalue ();
 
-		      if (error_state)
-			eval_error ();
-		      else if (print_result ())
+		  if (error_state)
+		    eval_error ();
+		  else if (k < n)
+		    {
+		      ult.assign (etype, rhs_val(k));
+
+		      if (! error_state)
 			{
-			  if (Vprint_rhs_assign_val)
-			    retval(k).print_with_name
-			      (octave_stdout, lhs_elt->str_print_code ());
+			  if (etype == octave_value::op_asn_eq)
+			    retval(k) = rhs_val(k);
 			  else
-			    {
-			      // We clear any index here so that we can
-			      // get the new value of the referenced
-			      // object below, instead of the indexed
-			      // value (which should be the same as the
-			      // right hand side value).
-
-			      ult.clear_index ();
-
-			      octave_value lhs_val = ult.value ();
-
-			      if (! error_state)
-				lhs_val.print_with_name (octave_stdout,
-							 lhs_elt->name ());
-			    }
+			    retval(k) = ult.value ();
 			}
 		    }
 		  else
-		    eval_error ();
+		    error ("element number %d undefined in return list", k+1);
 
 		  if (error_state)
-		    break;
+		    eval_error ();
+		  else if (print_result ())
+		    {
+		      if (Vprint_rhs_assign_val)
+			retval(k).print_with_name
+			  (octave_stdout, lhs_elt->str_print_code ());
+		      else
+			{
+			  // We clear any index here so that we can
+			  // get the new value of the referenced
+			  // object below, instead of the indexed
+			  // value (which should be the same as the
+			  // right hand side value).
+
+			  ult.clear_index ();
 
-		  k++;
+			  octave_value lhs_val = ult.value ();
+
+			  if (! error_state)
+			    lhs_val.print_with_name (octave_stdout,
+						     lhs_elt->name ());
+			}
+		    }
 		}
+	      else
+		eval_error ();
+
+	      if (error_state)
+		break;
+
+	      k++;
 	    }
 	}
     }