Mercurial > hg > octave-nkf
changeset 497:88614b380d6e
[project @ 1994-07-08 02:00:57 by jwe]
author | jwe |
---|---|
date | Fri, 08 Jul 1994 02:08:37 +0000 |
parents | e7c5b23b34d3 |
children | 2e1353465468 |
files | src/balance.cc src/chol.cc src/colloc.cc src/dassl.cc src/det.cc src/dynamic-ld.h src/eig.cc src/expm.cc src/fft.cc src/file-io.cc src/file-io.h src/fsolve.cc src/fsqp.cc src/givens.cc src/hess.cc src/ifft.cc src/inv.cc src/lpsolve.cc src/lsode.cc src/lu.cc src/npsol.cc src/qpsol.cc src/qr.cc src/quad.cc src/qzval.cc src/rand.cc src/schur.cc src/svd.cc src/syl.cc src/symtab.h src/variables.h |
diffstat | 31 files changed, 686 insertions(+), 765 deletions(-) [+] |
line wrap: on
line diff
--- a/src/balance.cc +++ b/src/balance.cc @@ -42,24 +42,24 @@ #include "f-balance.h" #ifdef WITH_DLD -tree_constant * -builtin_balance_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_balance_2 (const Octave_object& args, int nargin, int nargout) { return balance (args, nargin, nargout); } #endif -tree_constant * -balance (const tree_constant *args, int nargin, int nargout) +Octave_object +balance (const Octave_object& args, int nargin, int nargout) { char *bal_job; int my_nargin; // # args w/o optional string arg - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; // determine if balancing option is listed // set my_nargin to the number of matrix inputs - if (args[nargin-1].const_type () == tree_constant_rep::string_constant ){ - bal_job = args[nargin-1].string_value (); + if (args(nargin-1).const_type () == tree_constant_rep::string_constant ){ + bal_job = args(nargin-1).string_value (); my_nargin = nargin-2; } else @@ -68,7 +68,7 @@ my_nargin = nargin-1; } - tree_constant arg = args[1].make_numeric (); + tree_constant arg = args(1).make_numeric (); int a_nr = arg.rows (); int a_nc = arg.columns (); @@ -81,9 +81,9 @@ { if (flag < 0) warning ("balance: argument is empty matrix"); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval.resize (2); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); } else error ("balance: empty matrix is invalid as argument"); @@ -131,29 +131,29 @@ // Algebraic eigenvalue problem. - retval = new tree_constant[nargout+1]; + retval.resize (nargout ? nargout : 1); if (arg.is_complex_type ()) { ComplexAEPBALANCE result (caa, bal_job); - if (nargout == 1) - retval[0] = tree_constant(result.balanced_matrix ()); + if (nargout == 0 || nargout == 1) + retval(0) = tree_constant(result.balanced_matrix ()); else { - retval[0] = tree_constant (result.balancing_matrix ()); - retval[1] = tree_constant (result.balanced_matrix ()); + retval(0) = tree_constant (result.balancing_matrix ()); + retval(1) = tree_constant (result.balanced_matrix ()); } } else { AEPBALANCE result (aa, bal_job); - if (nargout == 1) - retval[0] = tree_constant (result.balanced_matrix ()); + if (nargout == 0 || nargout == 1) + retval(0) = tree_constant (result.balanced_matrix ()); else { - retval[0] = tree_constant (result.balancing_matrix ()); - retval[1] = tree_constant (result.balanced_matrix ()); + retval(0) = tree_constant (result.balancing_matrix ()); + retval(1) = tree_constant (result.balanced_matrix ()); } } break; @@ -162,11 +162,11 @@ // Generalized eigenvalue problem. { - retval = new tree_constant[nargout+1]; + retval.resize (nargout ? nargout : 1); // 1st we have to check argument 2 dimensions and type... - tree_constant brg = args[2].make_numeric (); + tree_constant brg = args(2).make_numeric (); int b_nr = brg.rows (); int b_nc = brg.columns (); @@ -238,17 +238,17 @@ { case 1: warning ("balance: should use two output arguments"); - retval[0] = tree_constant (caa); + retval(0) = tree_constant (caa); break; case 2: - retval[0] = tree_constant (caa); - retval[1] = tree_constant (cbb); + retval(0) = tree_constant (caa); + retval(1) = tree_constant (cbb); break; case 4: - retval[0] = tree_constant (result.left_balancing_matrix ()); - retval[1] = tree_constant (result.right_balancing_matrix ()); - retval[2] = tree_constant (caa); - retval[3] = tree_constant (cbb); + retval(0) = tree_constant (result.left_balancing_matrix ()); + retval(1) = tree_constant (result.right_balancing_matrix ()); + retval(2) = tree_constant (caa); + retval(3) = tree_constant (cbb); break; default: error ("balance: illegal number of output arguments"); @@ -260,14 +260,14 @@ switch (nargout) { case 2: - retval[0] = tree_constant (result.balanced_a_matrix ()); - retval[1] = tree_constant (result.balanced_b_matrix ()); + retval(0) = tree_constant (result.balanced_a_matrix ()); + retval(1) = tree_constant (result.balanced_b_matrix ()); break; case 4: - retval[0] = tree_constant (result.left_balancing_matrix ()); - retval[1] = tree_constant (result.right_balancing_matrix ()); - retval[2] = tree_constant (result.balanced_a_matrix ()); - retval[3] = tree_constant (result.balanced_b_matrix ()); + retval(0) = tree_constant (result.left_balancing_matrix ()); + retval(1) = tree_constant (result.right_balancing_matrix ()); + retval(2) = tree_constant (result.balanced_a_matrix ()); + retval(3) = tree_constant (result.balanced_b_matrix ()); break; default: error ("balance: illegal number of output arguments");
--- a/src/chol.cc +++ b/src/chol.cc @@ -35,19 +35,21 @@ #include "f-chol.h" #ifdef WITH_DLD -tree_constant * -builtin_chol_2 (const tree_constant *args, int nargin, int nargout) +Octave_object* +builtin_chol_2 (const Octave_object& args, int nargin, int nargout) { - return chol (args, nargin, nargout); + Octave_object retval (1); + retval(0) = chol (args(1)); + return retval; } #endif -tree_constant * -chol (const tree_constant *a, int nargin, int nargout) +tree_constant +chol (const tree_constant& a) { - tree_constant *retval = new tree_constant [2]; + tree_constant retval; - tree_constant tmp = a[1].make_numeric ();; + tree_constant tmp = a.make_numeric ();; int nr = tmp.rows (); int nc = tmp.columns (); @@ -60,9 +62,7 @@ if (flag < 0) gripe_empty_arg ("chol", 0); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval = tree_constant (m); } else gripe_empty_arg ("chol", 1); @@ -80,7 +80,7 @@ if (info != 0) error ("chol: matrix not positive definite"); else - retval[0] = tree_constant (fact.chol_matrix ()); + retval = tree_constant (fact.chol_matrix ()); } break; case tree_constant_rep::complex_matrix_constant: @@ -91,19 +91,19 @@ if (info != 0) error ("chol: matrix not positive definite"); else - retval[0] = tree_constant (fact.chol_matrix ()); + retval = tree_constant (fact.chol_matrix ()); } break; case tree_constant_rep::scalar_constant: { double d = tmp.double_value (); - retval[0] = tree_constant (d); + retval = tree_constant (d); } break; case tree_constant_rep::complex_scalar_constant: { Complex c = tmp.complex_value (); - retval[0] = tree_constant (c); + retval = tree_constant (c); } break; default:
--- a/src/colloc.cc +++ b/src/colloc.cc @@ -1,7 +1,7 @@ // f-colloc.cc -*- C++ -*- /* -Copyright (C) 1993 John W. Eaton +Copyright (C) 1993, 1994 John W. Eaton This file is part of Octave. @@ -33,26 +33,26 @@ #include "f-colloc.h" #ifdef WITH_DLD -tree_constant * -builtin_colloc_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_colloc_2 (const Octave_object& args, int nargin, int nargout) { return collocation_weights (args, nargin); } #endif -tree_constant * -collocation_weights (const tree_constant *args, int nargin) +Octave_object +collocation_weights (const Octave_object& args, int nargin) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - if (args[1].const_type () != tree_constant_rep::complex_scalar_constant - && args[1].const_type () != tree_constant_rep::scalar_constant) + if (args(1).const_type () != tree_constant_rep::complex_scalar_constant + && args(1).const_type () != tree_constant_rep::scalar_constant) { error ("colloc: first argument must be a scalar"); return retval; } - int ncol = NINT (args[1].double_value ()); + int ncol = NINT (args(1).double_value ()); if (ncol < 0) { error ("colloc: first argument must be non-negative"); @@ -65,15 +65,15 @@ for (int i = 2; i < nargin; i++) { - if (args[i].is_defined ()) + if (args(i).is_defined ()) { - if (! args[i].is_string_type ()) + if (! args(i).is_string_type ()) { error ("colloc: expecting string argument"); return retval; } - char *s = args[i].string_value (); + char *s = args(i).string_value (); if (s != (char *) NULL && (((*s == 'R' || *s == 'r') && strlen (s) == 1) || strcmp (s, "right") == 0)) @@ -113,13 +113,12 @@ Matrix B = wts.second (); ColumnVector q = wts.quad_weights (); - retval = new tree_constant [5]; + retval.resize (4); - retval[0] = tree_constant (r); - retval[1] = tree_constant (A); - retval[2] = tree_constant (B); - retval[3] = tree_constant (q); - retval[4] = tree_constant (); + retval(0) = tree_constant (r); + retval(1) = tree_constant (A); + retval(2) = tree_constant (B); + retval(3) = tree_constant (q); return retval; }
--- a/src/dassl.cc +++ b/src/dassl.cc @@ -41,14 +41,14 @@ static tree_fvc *dassl_fcn; #ifdef WITH_DLD -tree_constant * -builtin_dassl_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_dassl_2 (const Octave_object& args, int nargin, int nargout) { return dassl (args, nargin, nargout); } -tree_constant * -builtin_dassl_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_dassl_options_2 (const Octave_object& args, int nargin, int nargout) { return dassl_options (args, nargin, nargout); } @@ -66,9 +66,9 @@ assert (nstates == xdot.capacity ()); // tree_constant name (dassl_fcn->name ()); - tree_constant *args = new tree_constant [4]; -// args[0] = name; - args[3] = tree_constant (t); + Octave_object args (4); +// args(0) = name; + args(3) = tree_constant (t); if (nstates > 1) { @@ -81,8 +81,8 @@ } tree_constant state (m1); tree_constant deriv (m2); - args[1] = state; - args[2] = deriv; + args(1) = state; + args(2) = deriv; } else { @@ -90,15 +90,13 @@ double d2 = xdot.elem (0); tree_constant state (d1); tree_constant deriv (d2); - args[1] = state; - args[2] = deriv; + args(1) = state; + args(2) = deriv; } if (dassl_fcn != (tree_fvc *) NULL) { - tree_constant *tmp = dassl_fcn->eval (0, 1, args, 4); - - delete [] args; + Octave_object tmp = dassl_fcn->eval (0, 1, args, 4); if (error_state) { @@ -106,45 +104,40 @@ return retval; } - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) + if (tmp.length () > 0 && tmp(0).is_defined ()) { - retval = tmp[0].to_vector (); - - delete [] tmp; + retval = tmp(0).to_vector (); if (retval.length () == 0) gripe_user_supplied_eval ("dassl"); } else - { - delete [] tmp; - gripe_user_supplied_eval ("dassl"); - } + gripe_user_supplied_eval ("dassl"); } return retval; } -tree_constant * -dassl (const tree_constant *args, int nargin, int nargout) +Octave_object +dassl (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - dassl_fcn = is_valid_function (args[1], "dassl", 1); + dassl_fcn = is_valid_function (args(1), "dassl", 1); if (dassl_fcn == (tree_fvc *) NULL || takes_correct_nargs (dassl_fcn, 4, "dassl", 1) != 1) return retval; - ColumnVector state = args[2].to_vector (); - ColumnVector deriv = args[3].to_vector (); - ColumnVector out_times = args[4].to_vector (); + ColumnVector state = args(2).to_vector (); + ColumnVector deriv = args(3).to_vector (); + ColumnVector out_times = args(4).to_vector (); ColumnVector crit_times; int crit_times_set = 0; if (nargin > 5) { - crit_times = args[5].to_vector (); + crit_times = args(5).to_vector (); crit_times_set = 1; } @@ -168,9 +161,9 @@ else output = dae.integrate (out_times, deriv_output); - retval = new tree_constant [3]; - retval[0] = tree_constant (output); - retval[1] = tree_constant (deriv_output); + retval.resize (2); + retval(0) = tree_constant (output); + retval(1) = tree_constant (deriv_output); return retval; } @@ -179,7 +172,7 @@ #define MAX_TOKENS 3 -struct ODE_OPTIONS +struct DAE_OPTIONS { char *keyword; char *kw_tok[MAX_TOKENS + 1]; @@ -189,7 +182,7 @@ d_get_opt_mf d_get_fcn; }; -static ODE_OPTIONS dassl_option_table[] = +static DAE_OPTIONS dassl_option_table [] = { { "absolute tolerance", { "absolute", "tolerance", NULL, NULL, }, @@ -233,7 +226,7 @@ << " keyword value\n" << " ------- -----\n\n"; - ODE_OPTIONS *list = dassl_option_table; + DAE_OPTIONS *list = dassl_option_table; char *keyword; while ((keyword = list->keyword) != (char *) NULL) @@ -257,7 +250,7 @@ static void do_dassl_option (char *keyword, double val) { - ODE_OPTIONS *list = dassl_option_table; + DAE_OPTIONS *list = dassl_option_table; while (list->keyword != (char *) NULL) { @@ -274,30 +267,26 @@ warning ("dassl_options: no match for `%s'", keyword); } -tree_constant * -dassl_options (const tree_constant *args, int nargin, int nargout) +Octave_object +dassl_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) - { - print_dassl_option_list (); - } + print_dassl_option_list (); else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_dassl_option (keyword, val); } else print_usage ("dassl_options"); } else - { - print_usage ("dassl_options"); - } + print_usage ("dassl_options"); return retval; }
--- a/src/det.cc +++ b/src/det.cc @@ -35,11 +35,11 @@ #include "f-det.h" #ifdef WITH_DLD -tree_constant * -builtin_det_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_det_2 (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = new tree_constant [2]; - retval[0] = determinant (args[1]); + Octave_object retval (1); + retval(0) = determinant (args(1)); return retval; } #endif
--- a/src/dynamic-ld.h +++ b/src/dynamic-ld.h @@ -24,9 +24,9 @@ #if !defined (octave_dynamic_ld_h) #define octave_dynamic_ld_h 1 -class tree_constant; +#include "oct-obj.h" -typedef tree_constant* (*builtin_fcn_ptr) (tree_constant*, int, int); +typedef Octave_object (*builtin_fcn_ptr) (const Octave_object&, int, int); extern void octave_dld_tc2_unlink_by_symbol (const char *name, int hard = 1); @@ -36,11 +36,11 @@ const char *fcn, const char *object); -extern tree_constant *octave_dld_tc2_and_go (tree_constant *args, - int nargin, int nargout, - const char *name, - const char *fcn, - const char *object); +extern Octave_object octave_dld_tc2_and_go (const Octave_object&, + int nargin, int nargout, + const char *name, + const char *fcn, + const char *object); #endif
--- a/src/eig.cc +++ b/src/eig.cc @@ -34,19 +34,19 @@ #include "f-eig.h" #ifdef WITH_DLD -tree_constant * -builtin_eig_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_eig_2 (const Octave_object& args, int nargin, int nargout) { return eig (args, nargin, nargout); } #endif -tree_constant * -eig (const tree_constant *args, int nargin, int nargout) +Octave_object +eig (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arg = args[1].make_numeric (); + tree_constant arg = args(1).make_numeric (); int a_nr = arg.rows (); int a_nc = arg.columns (); @@ -59,9 +59,9 @@ if (flag < 0) gripe_empty_arg ("eig", 0); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval.resize (2); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); } else gripe_empty_arg ("eig", 1); @@ -103,10 +103,10 @@ break; } - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (result.eigenvalues (), 1); + retval.resize (1); + retval(0) = tree_constant (result.eigenvalues (), 1); } else { @@ -114,9 +114,9 @@ ComplexDiagMatrix d (result.eigenvalues ()); - retval = new tree_constant [3]; - retval[0] = tree_constant (result.eigenvectors ()); - retval[1] = tree_constant (d); + retval.resize (2); + retval(0) = tree_constant (result.eigenvectors ()); + retval(1) = tree_constant (d); } return retval;
--- a/src/expm.cc +++ b/src/expm.cc @@ -43,11 +43,11 @@ #include "f-expm.h" #ifdef WITH_DLD -tree_constant * -builtin_matrix_exp_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_matrix_exp_2 (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = new tree_constant [2]; - retval[0] = matrix_exp (args[1]); + Octave_object retval (1); + retval(0) = matrix_exp (args(1)); return retval; } #endif @@ -69,7 +69,7 @@ // Constants for matrix exponential calculation. - static double padec[] = + static double padec [] = { 5.0000000000000000e-1, 1.1666666666666667e-1,
--- a/src/fft.cc +++ b/src/fft.cc @@ -35,11 +35,11 @@ #include "f-fft.h" #ifdef WITH_DLD -tree_constant * -builtin_fft_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_fft_2 (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = new tree_constant [2]; - retval[0] = fft (args[1]); + Octave_object retval (1); + retval(0) = fft (args(1)); return retval; } #endif
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -275,12 +275,12 @@ return p; } -tree_constant * -fclose_internal (const tree_constant *args) +Octave_object +fclose_internal (const Octave_object& args) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = return_valid_file (args[1]); + Pix p = return_valid_file (args(1)); if (p == (Pix) NULL) return retval; @@ -297,24 +297,24 @@ file_list.del (p); file_count--; - retval = new tree_constant[2]; + retval.resize (1); if (success == 0) - retval[0] = tree_constant (1.0); // succeeded + retval(0) = tree_constant (1.0); // succeeded else { error ("fclose: error on closing file"); - retval[0] = tree_constant (0.0); // failed + retval(0) = tree_constant (0.0); // failed } return retval; } -tree_constant * -fflush_internal (const tree_constant *args) +Octave_object +fflush_internal (const Octave_object& args) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = return_valid_file (args[1]); + Pix p = return_valid_file (args(1)); if (p == (Pix) NULL) return retval; @@ -334,13 +334,13 @@ else success = fflush (file.fptr ()); - retval = new tree_constant[2]; + retval.resize (1); if (success == 0) - retval[0] = tree_constant (1.0); // succeeded + retval(0) = tree_constant (1.0); // succeeded else { error ("fflush: write error"); - retval[0] = tree_constant (0.0); // failed + retval(0) = tree_constant (0.0); // failed } return retval; @@ -361,20 +361,20 @@ return 0; } -tree_constant * -fgets_internal (const tree_constant *args, int nargout) +Octave_object +fgets_internal (const Octave_object& args, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "r", "fgets"); + Pix p = file_io_get_file (args(1), "r", "fgets"); if (p == (Pix) NULL) return retval; int length = 0; - if (args[2].is_scalar_type ()) + if (args(2).is_scalar_type ()) { - length = (int) args[2].double_value (); + length = (int) args(2).double_value (); if ((double) NINT (length) != length) { error ("fgets: length not an integer value"); @@ -389,56 +389,56 @@ if (success == (char *) NULL) { - retval = new tree_constant[2]; - retval[0] = tree_constant (-1.0); + retval.resize (1); + retval(0) = tree_constant (-1.0); return retval; } if (nargout == 2) { - retval = new tree_constant[3]; - retval[1] = tree_constant ((double) strlen (string)); + retval.resize (2); + retval(1) = tree_constant ((double) strlen (string)); } else - retval = new tree_constant[2]; + retval.resize (1); - retval[0] = tree_constant (string); + retval(0) = tree_constant (string); return retval; } -tree_constant * -fopen_internal (const tree_constant *args) +Octave_object +fopen_internal (const Octave_object& args) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; Pix p; - if (! args[1].is_string_type ()) + if (! args(1).is_string_type ()) { error ("fopen: file name must be a string"); return retval; } - p = return_valid_file (args[1]); + p = return_valid_file (args(1)); if (p != (Pix) NULL) { file_info file = file_list (p); - retval = new tree_constant[2]; - retval[0] = tree_constant ((double) file.number ()); + retval.resize (1); + retval(0) = tree_constant ((double) file.number ()); return retval; } - if (! args[2].is_string_type ()) + if (! args(2).is_string_type ()) { error ("fopen: file mode must be a string"); return retval; } - char *name = args[1].string_value (); - char *mode = args[2].string_value (); + char *name = args(1).string_value (); + char *mode = args(2).string_value (); if (! valid_mode (mode)) { @@ -466,16 +466,16 @@ file_info file (number, name, file_ptr, mode); file_list.append (file); - retval = new tree_constant[2]; - retval[0] = tree_constant ((double) number); + retval.resize (1); + retval(0) = tree_constant ((double) number); return retval; } -tree_constant * +Octave_object freport_internal (void) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; Pix p = file_list.first (); ostrstream output_buf; @@ -495,12 +495,12 @@ return retval; } -tree_constant * -frewind_internal (const tree_constant *args) +Octave_object +frewind_internal (const Octave_object& args) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "a+", "frewind"); + Pix p = file_io_get_file (args(1), "a+", "frewind"); if (p != (Pix) NULL) { @@ -511,21 +511,21 @@ return retval; } -tree_constant * -fseek_internal (const tree_constant *args, int nargin) +Octave_object +fseek_internal (const Octave_object& args, int nargin) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "a+", "fseek"); + Pix p = file_io_get_file (args(1), "a+", "fseek"); if (p == (Pix) NULL) return retval; long origin = SEEK_SET; long offset = 0; - if (args[2].is_scalar_type ()) + if (args(2).is_scalar_type ()) { - offset = (long) args[2].double_value (); + offset = (long) args(2).double_value (); if ((double) NINT (offset) != offset) { error ("fseek: offset not an integer value"); @@ -533,9 +533,9 @@ } } - if (nargin == 4 && args[3].is_scalar_type ()) + if (nargin == 4 && args(3).is_scalar_type ()) { - origin = (long) args[3].double_value (); + origin = (long) args(3).double_value (); if (origin == -1) origin = SEEK_CUR; else if (origin == -2) @@ -552,32 +552,32 @@ file_info file = file_list (p); int success = fseek (file.fptr (), offset, origin); - retval = new tree_constant[2]; + retval.resize (1); if (success == 0) - retval[0] = tree_constant (1.0); // succeeded + retval(0) = tree_constant (1.0); // succeeded else { error ("fseek: file error"); - retval[0] = tree_constant (0.0); // failed + retval(0) = tree_constant (0.0); // failed } return retval; } -tree_constant * -ftell_internal (const tree_constant *args) +Octave_object +ftell_internal (const Octave_object& args) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "a+", "ftell"); + Pix p = file_io_get_file (args(1), "a+", "ftell"); if (p != (Pix) NULL) { file_info file = file_list (p); long offset = ftell (file.fptr ()); - retval = new tree_constant[2]; - retval[0] = tree_constant ((double) offset); + retval.resize (1); + retval(0) = tree_constant ((double) offset); if (offset == -1L) error ("ftell: write error"); @@ -605,7 +605,7 @@ } static int -process_printf_format (const char *s, const tree_constant *args, +process_printf_format (const char *s, const Octave_object& args, ostrstream& sb, const char *type, int nargin) { ostrstream fmt; @@ -639,14 +639,14 @@ return -1; } - if (args[fmt_arg_count].const_type () + if (args(fmt_arg_count).const_type () != tree_constant_rep::scalar_constant) { error ("%s: `*' must be replaced by an integer", type); return -1; } - fmt << NINT (args[fmt_arg_count++].double_value ()); + fmt << NINT (args(fmt_arg_count++).double_value ()); s++; chars_from_fmt_str++; } @@ -679,14 +679,14 @@ return -1; } - if (args[fmt_arg_count].const_type () + if (args(fmt_arg_count).const_type () != tree_constant_rep::scalar_constant) { error ("%s: `*' must be replaced by an integer", type); return -1; } - fmt << NINT (args[fmt_arg_count++].double_value ()); + fmt << NINT (args(fmt_arg_count++).double_value ()); s++; chars_from_fmt_str++; } @@ -717,7 +717,7 @@ return -1; } - arg_type = args[fmt_arg_count].const_type (); + arg_type = args(fmt_arg_count).const_type (); switch (*s) { @@ -729,7 +729,7 @@ { chars_from_fmt_str++; fmt << *s << ends; - double d = args[fmt_arg_count++].double_value (); + double d = args(fmt_arg_count++).double_value (); if ((int) d != d) goto invalid_conversion; else @@ -750,7 +750,7 @@ chars_from_fmt_str++; fmt << *s << ends; char *s = fmt.str (); - sb.form (s, args[fmt_arg_count++].double_value ()); + sb.form (s, args(fmt_arg_count++).double_value ()); delete [] s; return chars_from_fmt_str; } @@ -764,7 +764,7 @@ chars_from_fmt_str++; fmt << *s << ends; char *s = fmt.str (); - sb.form (s, args[fmt_arg_count++].string_value ()); + sb.form (s, args(fmt_arg_count++).string_value ()); delete [] s; return chars_from_fmt_str; } @@ -777,7 +777,7 @@ { chars_from_fmt_str++; fmt << *s << ends; - char *str = args[fmt_arg_count++].string_value (); + char *str = args(fmt_arg_count++).string_value (); if (strlen (str) != 1) goto invalid_conversion; else @@ -803,20 +803,20 @@ } -tree_constant * -do_printf (const char *type, const tree_constant *args, int nargin, +Octave_object +do_printf (const char *type, const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; fmt_arg_count = 1; char *fmt; file_info file; if (strcmp (type, "fprintf") == 0) { - if (args[2].is_string_type ()) + if (args(2).is_string_type ()) { - fmt = args[2].string_value (); + fmt = args(2).string_value (); fmt_arg_count++; } else @@ -825,7 +825,7 @@ return retval; } - Pix p = file_io_get_file (args[1], "a+", type); + Pix p = file_io_get_file (args(1), "a+", type); if (p == (Pix) NULL) return retval; @@ -838,13 +838,13 @@ return retval; } - fmt = args[2].string_value (); + fmt = args(2).string_value (); fmt_arg_count++; } - else if (args[1].is_string_type ()) + else if (args(1).is_string_type ()) { - fmt = args[1].string_value (); + fmt = args(1).string_value (); fmt_arg_count++; } else @@ -903,9 +903,9 @@ } else if (strcmp (type, "sprintf") == 0) { - retval = new tree_constant [2]; + retval.resize (1); char *msg = output_buf.str (); - retval[0] = tree_constant (msg); + retval(0) = tree_constant (msg); delete [] msg; } @@ -915,7 +915,7 @@ static int process_scanf_format (const char *s, ostrstream& fmt, const char *type, int nargout, FILE* fptr, - tree_constant *values) + Octave_object& values) { fmt << "%"; @@ -961,7 +961,7 @@ // Even if we don't have a place to store them, attempt to convert // everything specified by the format string. - if (fmt_arg_count >= nargout) + if (fmt_arg_count >= (nargout ? nargout : 1)) store_value = 0; switch (*s) @@ -975,7 +975,7 @@ success = fscanf (fptr, str, &temp); delete [] str; if (success > 0 && store_value) - values[fmt_arg_count++] = tree_constant ((double) temp); + values(fmt_arg_count++) = tree_constant ((double) temp); } break; case 'e': case 'E': case 'f': case 'g': case 'G': @@ -987,7 +987,7 @@ success = fscanf (fptr, str, &temp); delete [] str; if (success > 0 && store_value) - values[fmt_arg_count++] = tree_constant (temp); + values(fmt_arg_count++) = tree_constant (temp); } break; case 's': @@ -1023,7 +1023,7 @@ success = fscanf (fptr, str, temp); delete [] str; if (success && store_value) - values[fmt_arg_count++] = tree_constant (temp); + values(fmt_arg_count++) = tree_constant (temp); } break; case 'c': @@ -1039,7 +1039,7 @@ delete [] str; temp[string_width] = '\0'; if (success > 0 && store_value) - values[fmt_arg_count++] = tree_constant (temp); + values(fmt_arg_count++) = tree_constant (temp); } break; default: @@ -1068,10 +1068,10 @@ return -1; } -tree_constant * -do_scanf (const char *type, const tree_constant *args, int nargin, int nargout) +Octave_object +do_scanf (const char *type, const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; char *scanf_fmt = (char *) NULL; char *tmp_file = (char *) NULL; int tmp_file_open = 0; @@ -1082,8 +1082,8 @@ if (strcmp (type, "scanf") != 0) { - if (args[2].is_string_type ()) - scanf_fmt = args[2].string_value (); + if (args(2).is_string_type ()) + scanf_fmt = args(2).string_value (); else { error ("%s: format must be a string", type); @@ -1095,7 +1095,7 @@ if (doing_fscanf) { - Pix p = file_io_get_file (args[1], "r", type); + Pix p = file_io_get_file (args(1), "r", type); if (p == (Pix) NULL) return retval; @@ -1111,13 +1111,13 @@ fptr = file.fptr (); } - if ((fptr == (FILE *) NULL && args[1].is_string_type ()) + if ((fptr == (FILE *) NULL && args(1).is_string_type ()) || (doing_fscanf && file.number () == 0)) { char *string; if (strcmp (type, "scanf") == 0) - scanf_fmt = args[1].string_value (); + scanf_fmt = args(1).string_value (); if (strcmp (type, "scanf") == 0 || (doing_fscanf && file.number () == 0)) @@ -1127,7 +1127,7 @@ maybe_save_history (string); } else - string = args[1].string_value (); + string = args(1).string_value (); tmp_file = tmpnam ((char *) NULL); @@ -1162,7 +1162,7 @@ // Scan scanf_fmt for % escapes and assign the arguments. - retval = new tree_constant[nargout+1]; + retval.resize (nargout ? nargout : 1); char *ptr = scanf_fmt; @@ -1191,10 +1191,7 @@ if (status < 0) { if (fmt_arg_count == 0) - { - delete [] retval; - retval = NULL_TREE_CONST; - } + retval.resize (0); break; } @@ -1273,12 +1270,12 @@ * data : output data * count : number of elements read */ -tree_constant * -fread_internal (const tree_constant *args, int nargin, int nargout) +Octave_object +fread_internal (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "r", "fread"); + Pix p = file_io_get_file (args(1), "r", "fread"); if (p == (Pix) NULL) return retval; @@ -1287,8 +1284,8 @@ char *prec = "uchar"; if (nargin > 3) { - if (args[3].is_string_type ()) - prec = args[3].string_value (); + if (args(3).is_string_type ()) + prec = args(3).string_value (); else { error ("fread: precision must be a specified as a string"); @@ -1312,15 +1309,15 @@ if (nargin > 2) { - if (args[2].is_scalar_type ()) + if (args(2).is_scalar_type ()) { - tree_constant tmpa = args[2].make_numeric (); + tree_constant tmpa = args(2).make_numeric (); dnr = tmpa.double_value (); dnc = 1.0; } - else if (args[2].is_matrix_type ()) + else if (args(2).is_matrix_type ()) { - ColumnVector tmp = args[2].to_vector (); + ColumnVector tmp = args(2).to_vector (); if (tmp.length () == 2) { @@ -1380,13 +1377,13 @@ if (nargout > 1) { - retval = new tree_constant[3]; - retval[1] = tree_constant ((double) count); + retval.resize (2); + retval(1) = tree_constant ((double) count); } else - retval = new tree_constant[2]; + retval.resize (1); - retval[0] = tree_constant (m); + retval(0) = tree_constant (m); return retval; } @@ -1407,12 +1404,12 @@ * * count : the number of elements written */ -tree_constant * -fwrite_internal (const tree_constant *args, int nargin, int nargout) +Octave_object +fwrite_internal (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - Pix p = file_io_get_file (args[1], "a+", "fwrite"); + Pix p = file_io_get_file (args(1), "a+", "fwrite"); if (p == (Pix) NULL) return retval; @@ -1421,8 +1418,8 @@ char *prec = "uchar"; if (nargin > 3) { - if (args[3].is_string_type ()) - prec = args[3].string_value (); + if (args(3).is_string_type ()) + prec = args(3).string_value (); else { error ("fwrite: precision must be a specified as a string"); @@ -1432,12 +1429,12 @@ file_info file = file_list (p); - Matrix m = args[2].to_matrix (); + Matrix m = args(2).to_matrix (); int count = m.write (file.fptr (), prec); - retval = new tree_constant[2]; - retval[0] = tree_constant ((double) count); + retval.resize (1); + retval(0) = tree_constant ((double) count); return retval; } @@ -1450,21 +1447,21 @@ * fid : file id from fopen * eof : non zero for an end of file condition */ -tree_constant * -feof_internal (const tree_constant *args, int nargin, int nargout) +Octave_object +feof_internal (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; // Get file info. - Pix p = return_valid_file (args[1]); + Pix p = return_valid_file (args(1)); if (p == (Pix) NULL) return retval; file_info file = file_list (p); - retval = new tree_constant[2]; - retval[0] = tree_constant (feof (file.fptr ())); + retval.resize (1); + retval(0) = tree_constant (feof (file.fptr ())); return retval; } @@ -1478,13 +1475,13 @@ * message : system error message * errnum : error number */ -tree_constant * -ferror_internal (const tree_constant *args, int nargin, int nargout) +Octave_object +ferror_internal (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; // Get file info. - Pix p = return_valid_file (args[1]); + Pix p = return_valid_file (args(1)); if (p == (Pix) NULL) return retval; @@ -1495,13 +1492,13 @@ if (nargout > 1) { - retval = new tree_constant[3]; - retval[1] = tree_constant ((double) ierr); + retval.resize (2); + retval(1) = tree_constant ((double) ierr); } else - retval = new tree_constant[2]; + retval.resize (1); - retval[0] = tree_constant (strsave (strerror (ierr))); + retval(0) = tree_constant (strsave (strerror (ierr))); return retval; }
--- a/src/file-io.h +++ b/src/file-io.h @@ -28,36 +28,36 @@ #include <Pix.h> -class tree_constant; +#include "oct-obj.h" extern Pix return_valid_file (const tree_constant& arg); -extern tree_constant *fclose_internal (const tree_constant *args); -extern tree_constant *feof_internal (const tree_constant *args, +extern Octave_object fclose_internal (const Octave_object& args); +extern Octave_object feof_internal (const Octave_object& args, + int nargin, int nargout); +extern Octave_object ferror_internal (const Octave_object& args, + int nargin, int nargout); +extern Octave_object fflush_internal (const Octave_object& args); +extern Octave_object fgets_internal (const Octave_object& args, int nargout); +extern Octave_object fopen_internal (const Octave_object& args); +extern Octave_object fread_internal (const Octave_object& args, int nargin, int nargout); -extern tree_constant *ferror_internal (const tree_constant *args, - int nargin, int nargout); -extern tree_constant *fflush_internal (const tree_constant *args); -extern tree_constant *fgets_internal (const tree_constant *args, int nargout); -extern tree_constant *fopen_internal (const tree_constant *args); -extern tree_constant *fread_internal (const tree_constant *args, +extern Octave_object freport_internal (void); +extern Octave_object frewind_internal (const Octave_object& args); +extern Octave_object fseek_internal (const Octave_object& args, int nargin); +extern Octave_object ftell_internal (const Octave_object& args); +extern Octave_object fwrite_internal (const Octave_object& args, int nargin, int nargout); -extern tree_constant *freport_internal (void); -extern tree_constant *frewind_internal (const tree_constant *args); -extern tree_constant *fseek_internal (const tree_constant *args, int nargin); -extern tree_constant *ftell_internal (const tree_constant *args); -extern tree_constant *fwrite_internal (const tree_constant *args, - int nargin, int nargout); extern void initialize_file_io (void); extern void close_files (void); -extern tree_constant *do_printf (const char *type, const tree_constant *args, - int nargin, int nargout); +extern Octave_object do_printf (const char *type, const Octave_object& args, + int nargin, int nargout); -extern tree_constant *do_scanf (const char *type, const tree_constant *args, - int nargin, int nargout); +extern Octave_object do_scanf (const char *type, const Octave_object& args, + int nargin, int nargout); #endif
--- a/src/fsolve.cc +++ b/src/fsolve.cc @@ -41,14 +41,14 @@ static tree_fvc *fsolve_fcn; #ifdef WITH_DLD -tree_constant * -builtin_fsolve_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_fsolve_2 (const Octave_object& args, int nargin, int nargout) { return fsolve (args, nargin, nargout); } -tree_constant * -builtin_fsolve_options (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_fsolve_options (const Octave_object& args, int nargin, int nargout) { return fsolve_options (args, nargin, nargout); } @@ -92,8 +92,8 @@ int n = x.capacity (); // tree_constant name = tree_constant (fsolve_fcn->name ()); - tree_constant *args = new tree_constant [2]; -// args[0] = name; + Octave_object args (2); +// args(0) = name; if (n > 1) { @@ -101,51 +101,45 @@ for (int i = 0; i < n; i++) m (i, 0) = x.elem (i); tree_constant vars (m); - args[1] = vars; + args(1) = vars; } else { double d = x.elem (0); tree_constant vars (d); - args[1] = vars; + args(1) = vars; } if (fsolve_fcn != (tree_fvc *) NULL) { - tree_constant *tmp = fsolve_fcn->eval (0, 1, args, 2); - delete [] args; - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) + Octave_object tmp = fsolve_fcn->eval (0, 1, args, 2); + if (tmp.length () > 0 && tmp(0).is_defined ()) { - retval = tmp[0].to_vector (); - - delete [] tmp; + retval = tmp(0).to_vector (); if (retval.length () <= 0) gripe_user_supplied_eval ("fsolve"); } else - { - delete [] tmp; - gripe_user_supplied_eval ("fsolve"); - } + gripe_user_supplied_eval ("fsolve"); } return retval; } -tree_constant * -fsolve (const tree_constant *args, int nargin, int nargout) +Octave_object +fsolve (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - fsolve_fcn = is_valid_function (args[1], "fsolve", 1); + fsolve_fcn = is_valid_function (args(1), "fsolve", 1); if (fsolve_fcn == (tree_fvc *) NULL || takes_correct_nargs (fsolve_fcn, 2, "fsolve", 1) != 1) return retval; - ColumnVector x = args[2].to_vector (); + ColumnVector x = args(2).to_vector (); if (nargin > 3) warning ("fsolve: ignoring extra arguments"); @@ -162,14 +156,14 @@ info = hybrd_info_to_fsolve_info (info); - retval = new tree_constant [nargout+1]; - retval[0] = tree_constant (soln, 1); + retval.resize (nargout ? nargout : 1); + retval(0) = tree_constant (soln, 1); if (nargout > 1) - retval[1] = tree_constant ((double) info); + retval(1) = tree_constant ((double) info); if (nargout > 2) - retval[2] = tree_constant (); + retval(2) = tree_constant (); return retval; } @@ -189,7 +183,7 @@ d_get_opt_mf d_get_fcn; }; -static NLEQN_OPTIONS fsolve_option_table[] = +static NLEQN_OPTIONS fsolve_option_table [] = { { "tolerance", { "tolerance", NULL, }, @@ -256,30 +250,26 @@ warning ("fsolve_options: no match for `%s'", keyword); } -tree_constant * -fsolve_options (const tree_constant *args, int nargin, int nargout) +Octave_object +fsolve_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) - { - print_fsolve_option_list (); - } + print_fsolve_option_list (); else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_fsolve_option (keyword, val); } else print_usage ("fsolve_options"); } else - { - print_usage ("fsolve_options"); - } + print_usage ("fsolve_options"); return retval; }
--- a/src/fsqp.cc +++ b/src/fsqp.cc @@ -38,14 +38,14 @@ // static tree *fsqp_constraints; #ifdef WITH_DLD -tree_constant * -builtin_fsqp_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_fsqp_2 (const Octave_object& args, int nargin, int nargout) { return fsqp (args, nargin, nargout); } -tree_constant * -builtin_fsqp_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_fsqp_options_2 (const Octave_object& args, int nargin, int nargout) { return fsqp_options (args, nargin, nargout); } @@ -64,8 +64,8 @@ return retval; } -tree_constant * -fsqp (const tree_constant *args, int nargin, int nargout) +Octave_object +fsqp (const Octave_object& args, int nargin, int nargout) { /* @@ -84,17 +84,17 @@ // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; error ("fsqp: not implemented yet"); return retval; } -tree_constant * -fsqp_options (const tree_constant *args, int nargin, int nargout) +Octave_object +fsqp_options (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; error ("fsqp_options: not implemented yet"); return retval; }
--- a/src/givens.cc +++ b/src/givens.cc @@ -57,21 +57,21 @@ #endif #ifdef WITH_DLD -tree_constant * -builtin_givens_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_givens_2 (const Octave_object& args, int nargin, int nargout) { return givens (args, nargin, nargout); } #endif -tree_constant * -givens (const tree_constant *args, int nargin, int nargout) +Octave_object +givens (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arga = args[1].make_numeric (); - tree_constant argb = args[2].make_numeric (); + tree_constant arga = args(1).make_numeric (); + tree_constant argb = args(2).make_numeric (); if (! arga.is_scalar_type () && argb.is_scalar_type ()) { @@ -79,8 +79,7 @@ } else { - - retval = new tree_constant [nargout+1]; + retval.resize (nargout ? nargout : 1); Complex cx, cy; double x, y; @@ -120,13 +119,13 @@ g.elem (0, 1) = cs; g.elem (1, 0) = -conj (cs); - retval[0] = tree_constant (g); + retval(0) = tree_constant (g); } break; case 2: // output scalar values - retval[0] = tree_constant(cc); - retval[1] = tree_constant(cs); + retval(0) = tree_constant(cc); + retval(1) = tree_constant(cs); break; default: @@ -150,13 +149,13 @@ g.elem (0, 1) = s; g.elem (1, 0) = -s; - retval[0] = tree_constant (g); + retval(0) = tree_constant (g); } break; case 2: // output scalar values - retval[0] = tree_constant (cc); - retval[1] = tree_constant (s); + retval(0) = tree_constant (cc); + retval(1) = tree_constant (s); break; default:
--- a/src/hess.cc +++ b/src/hess.cc @@ -35,19 +35,19 @@ #include "f-hess.h" #ifdef WITH_DLD -tree_constant * -builtin_hess_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_hess_2 (const Octave_object& args, int nargin, int nargout) { return hess (args, nargin, nargout); } #endif -tree_constant * -hess (const tree_constant *args, int nargin, int nargout) +Octave_object +hess (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arg = args[1].make_numeric (); + tree_constant arg = args(1).make_numeric (); int a_nr = arg.rows (); int a_nc = arg.columns (); @@ -60,9 +60,9 @@ if (flag < 0) warning ("hess: argument is empty matrix"); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval.resize (2); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); } else error ("hess: empty matrix is invalid as argument"); @@ -87,16 +87,16 @@ HESS result (tmp); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (result.hess_matrix ()); + retval.resize (1); + retval(0) = tree_constant (result.hess_matrix ()); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (result.unitary_hess_matrix ()); - retval[1] = tree_constant (result.hess_matrix ()); + retval.resize (2); + retval(0) = tree_constant (result.unitary_hess_matrix ()); + retval(1) = tree_constant (result.hess_matrix ()); } } break; @@ -106,48 +106,48 @@ ComplexHESS result (ctmp); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (result.hess_matrix ()); + retval.resize (1); + retval(0) = tree_constant (result.hess_matrix ()); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (result.unitary_hess_matrix ()); - retval[1] = tree_constant (result.hess_matrix ()); + retval.resize (2); + retval(0) = tree_constant (result.unitary_hess_matrix ()); + retval(1) = tree_constant (result.hess_matrix ()); } } break; case tree_constant_rep::scalar_constant: { double d = arg.double_value (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (d); + retval.resize (1); + retval(0) = tree_constant (d); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (1); - retval[1] = tree_constant (d); + retval.resize (2); + retval(0) = tree_constant (1); + retval(1) = tree_constant (d); } } break; case tree_constant_rep::complex_scalar_constant: { Complex c = arg.complex_value (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (c); + retval.resize (1); + retval(0) = tree_constant (c); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (1); - retval[1] = tree_constant (c); + retval.resize (2); + retval(0) = tree_constant (1); + retval(1) = tree_constant (c); } } break;
--- a/src/ifft.cc +++ b/src/ifft.cc @@ -35,11 +35,11 @@ #include "f-ifft.h" #ifdef WITH_DLD -tree_constant * -builtin_ifft_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_ifft_2 (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = new tree_constant [2]; - retval[0] = ifft (args[1]); + Octave_object retval (1); + retval(0) = ifft (args(1)); return retval; } #endif
--- a/src/inv.cc +++ b/src/inv.cc @@ -35,11 +35,11 @@ #include "f-inv.h" #ifdef WITH_DLD -tree_constant * -builtin_inv_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_inv_2 (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = new tree_constant [2]; - retval[0] = inverse (args[1]); + Octave_object retval (1); + retval(0) = inverse (args(1)); return retval; } #endif
--- a/src/lpsolve.cc +++ b/src/lpsolve.cc @@ -1,7 +1,7 @@ // f-lpsolve.cc -*- C++ -*- /* -Copyright (C) 1993 John W. Eaton +Copyright (C) 1993, 1994 John W. Eaton This file is part of Octave. @@ -32,35 +32,35 @@ #include "f-lpsolve.h" #ifdef WITH_DLD -tree_constant * -builtin_lpsolve_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_lpsolve_2 (const Octave_object& args, int nargin, int nargout) { return lpsolve (args, nargin, nargout); } -tree_constant * -builtin_lpsolve_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_lpsolve_options_2 (const Octave_object& args, int nargin, int nargout) { return lpsolve_options (args, nargin, nargout); } #endif -tree_constant * -lpsolve (const tree_constant *args, int nargin, int nargout) +Octave_object +lpsolve (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; error ("lpsolve: not implemented yet"); return retval; } -tree_constant * -lpsolve_options (const tree_constant *args, int nargin, int nargout) +Octave_object +lpsolve_options (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; error ("lpsolve_options: not implemented yet"); return retval; }
--- a/src/lsode.cc +++ b/src/lsode.cc @@ -41,14 +41,14 @@ static tree_fvc *lsode_fcn; #ifdef WITH_DLD -tree_constant * -builtin_lsode_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_lsode_2 (const Octave_object& args, int nargin, int nargout) { return lsode (args, nargin, nargout); } -tree_constant * -builtin_lsode_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_lsode_options_2 (const Octave_object& args, int nargin, int nargout) { return lsode_options (args, nargin, nargout); } @@ -64,9 +64,9 @@ int nstates = x.capacity (); // tree_constant name (lsode_fcn->name ()); - tree_constant *args = new tree_constant [3]; -// args[0] = name; - args[2] = tree_constant (t); + Octave_object args (3); +// args(0) = name; + args(2) = tree_constant (t); if (nstates > 1) { @@ -74,20 +74,18 @@ for (int i = 0; i < nstates; i++) m (i, 0) = x.elem (i); tree_constant state (m); - args[1] = state; + args(1) = state; } else { double d = x.elem (0); tree_constant state (d); - args[1] = state; + args(1) = state; } if (lsode_fcn != (tree_fvc *) NULL) { - tree_constant *tmp = lsode_fcn->eval (0, 1, args, 3); - - delete [] args; + Octave_object tmp = lsode_fcn->eval (0, 1, args, 3); if (error_state) { @@ -95,44 +93,39 @@ return retval; } - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) + if (tmp.length () > 0 && tmp(0).is_defined ()) { - retval = tmp[0].to_vector (); - - delete [] tmp; + retval = tmp(0).to_vector (); if (retval.length () == 0) gripe_user_supplied_eval ("lsode"); } else - { - delete [] tmp; - gripe_user_supplied_eval ("lsode"); - } + gripe_user_supplied_eval ("lsode"); } return retval; } -tree_constant * -lsode (const tree_constant *args, int nargin, int nargout) +Octave_object +lsode (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - lsode_fcn = is_valid_function (args[1], "lsode", 1); + lsode_fcn = is_valid_function (args(1), "lsode", 1); if (lsode_fcn == (tree_fvc *) NULL || takes_correct_nargs (lsode_fcn, 3, "lsode", 1) != 1) return retval; - ColumnVector state = args[2].to_vector (); - ColumnVector out_times = args[3].to_vector (); + ColumnVector state = args(2).to_vector (); + ColumnVector out_times = args(3).to_vector (); ColumnVector crit_times; int crit_times_set = 0; if (nargin > 4) { - crit_times = args[4].to_vector (); + crit_times = args(4).to_vector (); crit_times_set = 1; } @@ -151,8 +144,8 @@ else output = ode.integrate (out_times); - retval = new tree_constant [2]; - retval[0] = tree_constant (output); + retval.resize (1); + retval(0) = tree_constant (output); return retval; } @@ -171,7 +164,7 @@ d_get_opt_mf d_get_fcn; }; -static ODE_OPTIONS lsode_option_table[] = +static ODE_OPTIONS lsode_option_table [] = { { "absolute tolerance", { "absolute", "tolerance", NULL, NULL, }, @@ -262,30 +255,26 @@ warning ("lsode_options: no match for `%s'", keyword); } -tree_constant * -lsode_options (const tree_constant *args, int nargin, int nargout) +Octave_object +lsode_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) - { - print_lsode_option_list (); - } + print_lsode_option_list (); else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_lsode_option (keyword, val); } else print_usage ("lsode_options"); } else - { - print_usage ("lsode_options"); - } + print_usage ("lsode_options"); return retval; }
--- a/src/lu.cc +++ b/src/lu.cc @@ -34,17 +34,17 @@ #include "f-lu.h" #ifdef WITH_DLD -tree_constant * -builtin_lu_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_lu_2 (const Octave_object& args, int nargin, int nargout) { - return lu (args[1], nargout); + return lu (args(1), nargout); } #endif -tree_constant * +Octave_object lu (const tree_constant& a, int nargout) { - tree_constant *retval = new tree_constant [4]; + Octave_object retval (3); tree_constant tmp = a.make_numeric ();; @@ -56,10 +56,9 @@ if (flag < 0) gripe_empty_arg ("lu", 0); Matrix m; - retval = new tree_constant [4]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); - retval[2] = tree_constant (m); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); + retval(2) = tree_constant (m); return retval; } else @@ -81,15 +80,15 @@ { Matrix P = fact.P (); Matrix L = P.transpose () * fact.L (); - retval[0] = tree_constant (L); - retval[1] = tree_constant (fact.U ()); + retval(0) = tree_constant (L); + retval(1) = tree_constant (fact.U ()); } break; case 3: default: - retval[0] = tree_constant (fact.L ()); - retval[1] = tree_constant (fact.U ()); - retval[2] = tree_constant (fact.P ()); + retval(0) = tree_constant (fact.L ()); + retval(1) = tree_constant (fact.U ()); + retval(2) = tree_constant (fact.P ()); break; } } @@ -110,15 +109,15 @@ { ComplexMatrix P = fact.P (); ComplexMatrix L = P.transpose () * fact.L (); - retval[0] = tree_constant (L); - retval[1] = tree_constant (fact.U ()); + retval(0) = tree_constant (L); + retval(1) = tree_constant (fact.U ()); } break; case 3: default: - retval[0] = tree_constant (fact.L ()); - retval[1] = tree_constant (fact.U ()); - retval[2] = tree_constant (fact.P ()); + retval(0) = tree_constant (fact.L ()); + retval(1) = tree_constant (fact.U ()); + retval(2) = tree_constant (fact.P ()); break; } } @@ -129,17 +128,17 @@ case tree_constant_rep::scalar_constant: { double d = tmp.double_value (); - retval[0] = tree_constant (1.0); - retval[1] = tree_constant (d); - retval[2] = tree_constant (1.0); + retval(0) = tree_constant (1.0); + retval(1) = tree_constant (d); + retval(2) = tree_constant (1.0); } break; case tree_constant_rep::complex_scalar_constant: { Complex c = tmp.complex_value (); - retval[0] = tree_constant (1.0); - retval[1] = tree_constant (c); - retval[2] = tree_constant (1.0); + retval(0) = tree_constant (1.0); + retval(1) = tree_constant (c); + retval(2) = tree_constant (1.0); } break; default:
--- a/src/npsol.cc +++ b/src/npsol.cc @@ -45,14 +45,14 @@ static tree_fvc *npsol_constraints; #ifdef WITH_DLD -tree_constant * -builtin_npsol_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_npsol_2 (const Octave_object& args, int nargin, int nargout) { return npsol (args, nargin, nargout); } -tree_constant * -builtin_npsol_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_npsol_options_2 (const Octave_object& args, int nargin, int nargout) { return npsol_options (args, nargin, nargout); } @@ -80,9 +80,9 @@ } // tree_constant name = tree_constant (npsol_objective->name ()); - tree_constant *args = new tree_constant [2]; -// args[0] = name; - args[1] = decision_vars; + Octave_object args (2); +// args(0) = name; + args(1) = decision_vars; static double retval; retval = 0.0; @@ -90,26 +90,19 @@ tree_constant objective_value; if (npsol_objective != (tree_fvc *) NULL) { - tree_constant *tmp = npsol_objective->eval (0, 1, args, 2); - - delete [] args; + Octave_object tmp = npsol_objective->eval (0, 1, args, 2); if (error_state) { error ("npsol: error evaluating objective function"); npsol_objective_error = 1; // XXX FIXME XXX - delete [] tmp; return retval; } - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) - { - objective_value = tmp[0]; - delete [] tmp; - } + if (tmp.length () > 0 && tmp(0).is_defined ()) + objective_value = tmp(0); else { - delete [] tmp; error ("npsol: error evaluating objective function"); npsol_objective_error = 1; // XXX FIXME XXX return retval; @@ -164,37 +157,29 @@ } // tree_constant name = tree_constant (npsol_constraints->name ()); - tree_constant *args = new tree_constant [2]; -// args[0] = name; - args[1] = decision_vars; + Octave_object args (2); +// args(0) = name; + args(1) = decision_vars; if (npsol_constraints != (tree_fvc *)NULL) { - tree_constant *tmp = npsol_constraints->eval (0, 1, args, 2); - - delete [] args; + Octave_object tmp = npsol_constraints->eval (0, 1, args, 2); if (error_state) { - delete [] tmp; error ("npsol: error evaluating constraints"); return retval; } - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) + if (tmp.length () > 0 && tmp(0).is_defined ()) { - retval = tmp[0].to_vector (); - - delete [] tmp; + retval = tmp(0).to_vector (); if (retval.length () <= 0) error ("npsol: error evaluating constraints"); } else - { - delete [] tmp; - error ("npsol: error evaluating constraints"); - } + error ("npsol: error evaluating constraints"); } return retval; @@ -260,8 +245,8 @@ return ok; } -tree_constant * -npsol (const tree_constant *args, int nargin, int nargout) +Octave_object +npsol (const Octave_object& args, int nargin, int nargout) { /* @@ -280,9 +265,9 @@ // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - ColumnVector x = args[1].to_vector (); + ColumnVector x = args(1).to_vector (); if (x.capacity () == 0) { @@ -290,7 +275,7 @@ return retval; } - npsol_objective = is_valid_function (args[2], "npsol", 1); + npsol_objective = is_valid_function (args(2), "npsol", 1); if (npsol_objective == (tree_fvc *) NULL || takes_correct_nargs (npsol_objective, 2, "npsol", 1) != 1) return retval; @@ -302,8 +287,8 @@ Bounds bounds; if (nargin == 5 || nargin == 8 || nargin == 11) { - ColumnVector lb = args[3].to_vector (); - ColumnVector ub = args[4].to_vector (); + ColumnVector lb = args(3).to_vector (); + ColumnVector ub = args(4).to_vector (); int lb_len = lb.capacity (); int ub_len = ub.capacity (); @@ -347,15 +332,15 @@ npsol_constraints = (tree_fvc *) NULL; if (nargin == 6 || nargin == 8 || nargin == 9 || nargin == 11) - npsol_constraints = is_valid_function (args[nargin-2], "npsol", 0); + npsol_constraints = is_valid_function (args(nargin-2), "npsol", 0); if (nargin == 8 || nargin == 6) { if (npsol_constraints == (tree_fvc *) NULL) { - ColumnVector lub = args[nargin-1].to_vector (); - Matrix c = args[nargin-2].to_matrix (); - ColumnVector llb = args[nargin-3].to_vector (); + ColumnVector lub = args(nargin-1).to_vector (); + Matrix c = args(nargin-2).to_matrix (); + ColumnVector llb = args(nargin-3).to_vector (); if (llb.capacity () == 0 || lub.capacity () == 0) { @@ -390,8 +375,8 @@ { if (takes_correct_nargs (npsol_constraints, 2, "npsol", 1)) { - ColumnVector nlub = args[nargin-1].to_vector (); - ColumnVector nllb = args[nargin-3].to_vector (); + ColumnVector nlub = args(nargin-1).to_vector (); + ColumnVector nllb = args(nargin-3).to_vector (); NLFunc const_func (npsol_constraint_function); @@ -427,14 +412,14 @@ if (npsol_constraints == (tree_fvc *) NULL) { // Produce error message. - is_valid_function (args[nargin-2], "npsol", 1); + is_valid_function (args(nargin-2), "npsol", 1); } else { if (takes_correct_nargs (npsol_constraints, 2, "npsol", 1)) { - ColumnVector nlub = args[nargin-1].to_vector (); - ColumnVector nllb = args[nargin-3].to_vector (); + ColumnVector nlub = args(nargin-1).to_vector (); + ColumnVector nllb = args(nargin-3).to_vector (); NLFunc const_func (npsol_constraint_function); @@ -444,9 +429,9 @@ NLConst nonlinear_constraints (nllb, const_func, nlub); - ColumnVector lub = args[nargin-4].to_vector (); - Matrix c = args[nargin-5].to_matrix (); - ColumnVector llb = args[nargin-6].to_vector (); + ColumnVector lub = args(nargin-4).to_vector (); + Matrix c = args(nargin-5).to_matrix (); + ColumnVector llb = args(nargin-6).to_vector (); if (llb.capacity () == 0 || lub.capacity () == 0) { @@ -486,14 +471,14 @@ solved: - retval = new tree_constant [nargout+1]; - retval[0] = tree_constant (soln, 1); + retval.resize (nargout ? nargout : 1); + retval(0) = tree_constant (soln, 1); if (nargout > 1) - retval[1] = tree_constant (objf); + retval(1) = tree_constant (objf); if (nargout > 2) - retval[2] = tree_constant ((double) inform); + retval(2) = tree_constant ((double) inform); if (nargout > 3) - retval[3] = tree_constant (lambda); + retval(3) = tree_constant (lambda); return retval; } @@ -517,7 +502,7 @@ i_get_opt_mf i_get_fcn; }; -static NPSOL_OPTIONS npsol_option_table[] = +static NPSOL_OPTIONS npsol_option_table [] = { { "central difference interval", { "central", "difference", "interval", NULL, NULL, NULL, }, @@ -710,10 +695,10 @@ warning ("npsol_options: no match for `%s'", keyword); } -tree_constant * -npsol_options (const tree_constant *args, int nargin, int nargout) +Octave_object +npsol_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) { @@ -721,10 +706,10 @@ } else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_npsol_option (keyword, val); } else
--- a/src/qpsol.cc +++ b/src/qpsol.cc @@ -47,14 +47,14 @@ int warn); #ifdef WITH_DLD -tree_constant * -builtin_qpsol_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_qpsol_2 (const Octave_object& args, int nargin, int nargout) { return qpsol (args, nargin, nargout); } -tree_constant * -builtin_qpsol_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_qpsol_options_2 (const Octave_object& args, int nargin, int nargout) { return qpsol_options (args, nargin, nargout); } @@ -62,8 +62,8 @@ static QPSOL_options qpsol_opts; -tree_constant * -qpsol (const tree_constant *args, int nargin, int nargout) +Octave_object +qpsol (const Octave_object& args, int nargin, int nargout) { /* @@ -78,23 +78,23 @@ // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - ColumnVector x = args[1].to_vector (); + ColumnVector x = args(1).to_vector (); if (x.capacity () == 0) { error ("qpsol: expecting vector as first argument"); return retval; } - Matrix H = args[2].to_matrix (); + Matrix H = args(2).to_matrix (); if (H.rows () != H.columns () || H.rows () != x.capacity ()) { error ("qpsol: H must be a square matrix consistent with the size of x"); return retval; } - ColumnVector c = args[3].to_vector (); + ColumnVector c = args(3).to_vector (); if (c.capacity () != x.capacity ()) { error ("qpsol: c must be a vector the same size as x"); @@ -104,8 +104,8 @@ Bounds bounds; if (nargin == 6 || nargin == 9) { - ColumnVector lb = args[4].to_vector (); - ColumnVector ub = args[5].to_vector (); + ColumnVector lb = args(4).to_vector (); + ColumnVector ub = args(5).to_vector (); int lb_len = lb.capacity (); int ub_len = ub.capacity (); @@ -150,9 +150,9 @@ if (nargin == 7 || nargin == 9) { - ColumnVector lub = args[nargin-1].to_vector (); - Matrix A = args[nargin-2].to_matrix (); - ColumnVector llb = args[nargin-3].to_vector (); + ColumnVector lub = args(nargin-1).to_vector (); + Matrix A = args(nargin-2).to_matrix (); + ColumnVector llb = args(nargin-3).to_vector (); if (llb.capacity () == 0 || lub.capacity () == 0) { @@ -188,14 +188,14 @@ solved: - retval = new tree_constant [nargout+1]; - retval[0] = tree_constant (soln, 1); + retval.resize (nargout ? nargout : 1); + retval(0) = tree_constant (soln, 1); if (nargout > 1) - retval[1] = tree_constant (objf); + retval(1) = tree_constant (objf); if (nargout > 2) - retval[2] = tree_constant ((double) inform); + retval(2) = tree_constant ((double) inform); if (nargout > 3) - retval[3] = tree_constant (lambda); + retval(3) = tree_constant (lambda); return retval; } @@ -219,7 +219,7 @@ i_get_opt_mf i_get_fcn; }; -static QPSOL_OPTIONS qpsol_option_table[] = +static QPSOL_OPTIONS qpsol_option_table [] = { { "feasibility tolerance", { "feasibility", "tolerance", NULL, }, @@ -316,10 +316,10 @@ warning ("qpsol_options: no match for `%s'", keyword); } -tree_constant * -qpsol_options (const tree_constant *args, int nargin, int nargout) +Octave_object +qpsol_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) { @@ -327,10 +327,10 @@ } else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_qpsol_option (keyword, val); } else
--- a/src/qr.cc +++ b/src/qr.cc @@ -34,17 +34,17 @@ #include "f-qr.h" #ifdef WITH_DLD -tree_constant * -builtin_qr_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_qr_2 (const Octave_object& args, int nargin, int nargout) { - return qr (args[1], nargout); + return qr (args(1), nargout); } #endif -tree_constant * +Octave_object qr (const tree_constant& a, int nargout) { - tree_constant *retval = new tree_constant [3]; + Octave_object retval (2); tree_constant tmp = a.make_numeric ();; @@ -59,9 +59,8 @@ if (flag < 0) gripe_empty_arg ("qr", 0); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); } else gripe_empty_arg ("qr", 1); @@ -75,30 +74,30 @@ { Matrix m = tmp.matrix_value (); QR fact (m); - retval[0] = tree_constant (fact.Q ()); - retval[1] = tree_constant (fact.R ()); + retval(0) = tree_constant (fact.Q ()); + retval(1) = tree_constant (fact.R ()); } break; case tree_constant_rep::complex_matrix_constant: { ComplexMatrix m = tmp.complex_matrix_value (); ComplexQR fact (m); - retval[0] = tree_constant (fact.Q ()); - retval[1] = tree_constant (fact.R ()); + retval(0) = tree_constant (fact.Q ()); + retval(1) = tree_constant (fact.R ()); } break; case tree_constant_rep::scalar_constant: { double d = tmp.double_value (); - retval[0] = tree_constant (1.0); - retval[1] = tree_constant (d); + retval(0) = tree_constant (1.0); + retval(1) = tree_constant (d); } break; case tree_constant_rep::complex_scalar_constant: { Complex c = tmp.complex_value (); - retval[0] = tree_constant (1.0); - retval[1] = tree_constant (c); + retval(0) = tree_constant (1.0); + retval(1) = tree_constant (c); } break; default:
--- a/src/quad.cc +++ b/src/quad.cc @@ -42,14 +42,14 @@ static tree_fvc *quad_fcn; #ifdef WITH_DLD -tree_constant * -builtin_quad_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_quad_2 (const Octave_object& args, int nargin, int nargout) { return do_quad (args, nargin, nargout); } -tree_constant * -builtin_quad_options_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_quad_options_2 (const Octave_object& args, int nargin, int nargout) { return quad_options (args, nargin, nargout); } @@ -63,32 +63,25 @@ double retval = 0.0; // tree_constant name = tree_constant (quad_fcn->name ()); - tree_constant *args = new tree_constant [2]; -// args[0] = name; - args[1] = tree_constant (x); + Octave_object args (2); +// args(0) = name; + args(1) = tree_constant (x); if (quad_fcn != (tree_fvc *) NULL) { - tree_constant *tmp = quad_fcn->eval (0, 1, args, 2); - - delete [] args; + Octave_object tmp = quad_fcn->eval (0, 1, args, 2); if (error_state) { - delete [] tmp; quad_integration_error = 1; // XXX FIXME XXX gripe_user_supplied_eval ("quad"); return retval; } - if (tmp != NULL_TREE_CONST && tmp[0].is_defined ()) - { - retval = tmp[0].to_scalar (); - delete [] tmp; - } + if (tmp.length () && tmp(0).is_defined ()) + retval = tmp(0).to_scalar (); else { - delete [] tmp; quad_integration_error = 1; // XXX FIXME XXX gripe_user_supplied_eval ("quad"); } @@ -97,20 +90,20 @@ return retval; } -tree_constant * -do_quad (const tree_constant *args, int nargin, int nargout) +Octave_object +do_quad (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - quad_fcn = is_valid_function (args[1], "fsolve", 1); + quad_fcn = is_valid_function (args(1), "fsolve", 1); if (quad_fcn == (tree_fvc *) NULL || takes_correct_nargs (quad_fcn, 2, "fsolve", 1) != 1) return retval; - double a = args[2].to_scalar (); - double b = args[3].to_scalar (); + double a = args(2).to_scalar (); + double b = args(3).to_scalar (); int indefinite = 0; IndefQuad::IntegralType indef_type = IndefQuad::doubly_infinite; @@ -151,9 +144,9 @@ return retval; } have_sing = 1; - sing = args[5].to_vector (); + sing = args(5).to_vector (); case 5: - tol = args[4].to_vector (); + tol = args(4).to_vector (); switch (tol.capacity ()) { case 2: @@ -193,12 +186,12 @@ break; } - retval = new tree_constant [5]; + retval.resize (4); - retval[0] = tree_constant (val); - retval[1] = tree_constant ((double) ier); - retval[2] = tree_constant ((double) nfun); - retval[3] = tree_constant (abserr); + retval(0) = tree_constant (val); + retval(1) = tree_constant ((double) ier); + retval(2) = tree_constant ((double) nfun); + retval(3) = tree_constant (abserr); return retval; } @@ -218,7 +211,7 @@ d_get_opt_mf d_get_fcn; }; -static QUAD_OPTIONS quad_option_table[] = +static QUAD_OPTIONS quad_option_table [] = { { "absolute tolerance", { "absolute", "tolerance", NULL, }, @@ -291,30 +284,26 @@ warning ("quad_options: no match for `%s'", keyword); } -tree_constant * -quad_options (const tree_constant *args, int nargin, int nargout) +Octave_object +quad_options (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; if (nargin == 1) - { - print_quad_option_list (); - } + print_quad_option_list (); else if (nargin == 3) { - if (args[1].is_string_type ()) + if (args(1).is_string_type ()) { - char *keyword = args[1].string_value (); - double val = args[2].double_value (); + char *keyword = args(1).string_value (); + double val = args(2).double_value (); do_quad_option (keyword, val); } else print_usage ("quad_options"); } else - { - print_usage ("quad_options"); - } + print_usage ("quad_options"); return retval; }
--- a/src/qzval.cc +++ b/src/qzval.cc @@ -53,20 +53,20 @@ } #ifdef WITH_DLD -tree_constant * -builtin_qzvalue_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_qzvalue_2 (const Octave_object& args, int nargin, int nargout) { return qzvalue (args, nargin, nargout); } #endif -tree_constant * -qzvalue (const tree_constant *args, int nargin, int nargout) +Octave_object +qzvalue (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arga = args[1].make_numeric (); - tree_constant argb = args[2].make_numeric(); + tree_constant arga = args(1).make_numeric (); + tree_constant argb = args(2).make_numeric(); if (arga.is_empty () || argb.is_empty ()) retval = vector_of_empties (nargout, "qzvalue"); @@ -93,7 +93,7 @@ // Dimensions look o.k., let's solve the problem. - retval = new tree_constant[nargout+1]; + retval.resize (nargout ? nargout : 1); if (arga.is_complex_type () || argb.is_complex_type ()) error ("qzvalue: cannot yet do complex matrix arguments\n"); @@ -155,7 +155,7 @@ cx (cnt) = (alfr (i) + Im * alfi (i)) / beta (i); } } - retval[0] = tree_constant (cx); + retval(0) = tree_constant (cx); } } return retval;
--- a/src/rand.cc +++ b/src/rand.cc @@ -1,7 +1,7 @@ // f-rand.cc -*- C++ -*- /* -Copyright (C) 1993 John W. Eaton +Copyright (C) 1993, 1994 John W. Eaton This file is part of Octave. @@ -46,8 +46,8 @@ } #ifdef WITH_DLD -tree_constant * -builtin_rand_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_rand_2 (const Octave_object& args, int nargin, int nargout) { return rand_internal (args, nargin, nargout); } @@ -102,12 +102,12 @@ } } -tree_constant * -rand_internal (const tree_constant *args, int nargin, int nargout) +Octave_object +rand_internal (const Octave_object& args, int nargin, int nargout) { // Assumes that we have been given the correct number of arguments. - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; static int initialized = 0; if (! initialized) @@ -144,49 +144,45 @@ } else if (nargin == 2) { - switch (args[1].const_type ()) + switch (args(1).const_type ()) { case tree_constant_rep::string_constant: - char *s_arg = args[1].string_value (); + char *s_arg = args(1).string_value (); if (strcmp (s_arg, "dist") == 0) { - retval = new tree_constant [2]; + retval.resize (1); char *s = curr_rand_dist (); - retval[0] = tree_constant (s); + retval(0) = tree_constant (s); } else if (strcmp (s_arg, "seed") == 0) { - retval = new tree_constant [2]; + retval.resize (1); double d = curr_rand_seed (); - retval[0] = tree_constant (d); + retval(0) = tree_constant (d); } else if (strcmp (s_arg, "uniform") == 0) current_distribution = uniform; else if (strcmp (s_arg, "normal") == 0) current_distribution = normal; else - { - delete [] retval; - retval = NULL_TREE_CONST; - error ("rand: unrecognized string argument"); - } + error ("rand: unrecognized string argument"); break; case tree_constant_rep::scalar_constant: case tree_constant_rep::complex_scalar_constant: - n = NINT (args[1].double_value ()); + n = NINT (args(1).double_value ()); m = n; goto gen_matrix; case tree_constant_rep::range_constant: { - Range r = args[1].range_value (); + Range r = args(1).range_value (); n = 1; m = NINT (r.nelem ()); } goto gen_matrix; case tree_constant_rep::matrix_constant: case tree_constant_rep::complex_matrix_constant: - n = NINT (args[1].rows ()); - m = NINT (args[1].columns ()); + n = NINT (args(1).rows ()); + m = NINT (args(1).columns ()); goto gen_matrix; default: panic_impossible (); @@ -195,16 +191,16 @@ } else if (nargin == 3) { - if (args[1].is_string_type () - && strcmp (args[1].string_value (), "seed") == 0) + if (args(1).is_string_type () + && strcmp (args(1).string_value (), "seed") == 0) { - double d = args[2].to_scalar (); + double d = args(2).to_scalar (); set_rand_seed (d); } else { - n = NINT (args[1].to_scalar ()); - m = NINT (args[2].to_scalar ()); + n = NINT (args(1).to_scalar ()); + m = NINT (args(2).to_scalar ()); goto gen_matrix; } } @@ -215,13 +211,13 @@ if (n == 0 || m == 0) { - retval = new tree_constant [2]; + retval.resize (1); Matrix m (0, 0); - retval[0] = tree_constant (m); + retval(0) = tree_constant (m); } else if (n > 0 && m > 0) { - retval = new tree_constant [2]; + retval.resize (1); Matrix rand_mat (n, m); for (int j = 0; j < m; j++) for (int i = 0; i < n; i++) @@ -245,7 +241,7 @@ } } - retval[0] = tree_constant (rand_mat); + retval(0) = tree_constant (rand_mat); } else error ("rand: invalid negative argument");
--- a/src/schur.cc +++ b/src/schur.cc @@ -35,34 +35,34 @@ #include "f-schur.h" #ifdef WITH_DLD -tree_constant * -builtin_schur_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_schur_2 (const Octave_object& args, int nargin, int nargout) { return schur (args, nargin, nargout); } #endif -tree_constant * -schur (const tree_constant *args, int nargin, int nargout) +Octave_object +schur (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arg = args[1].make_numeric (); + tree_constant arg = args(1).make_numeric (); char *ord; if (nargin != 3) ord = "U"; else - ord = args[2].string_value (); + ord = args(2).string_value (); if (*ord != 'U' && *ord != 'A' && *ord != 'D' && *ord != 'u' && *ord != 'a' && *ord != 'd') { warning ("schur: incorrect ordered schur argument `%c'", *ord); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval.resize (2); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); return retval; } int a_nr = arg.rows (); @@ -76,9 +76,9 @@ if (flag < 0) warning ("schur: argument is empty matrix"); Matrix m; - retval = new tree_constant [3]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); + retval.resize (2); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); } else error ("schur: empty matrix is invalid as argument"); @@ -102,16 +102,16 @@ SCHUR result (tmp,ord); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (result.schur_matrix ()); + retval.resize (1); + retval(0) = tree_constant (result.schur_matrix ()); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (result.unitary_matrix ()); - retval[1] = tree_constant (result.schur_matrix ()); + retval.resize (2); + retval(0) = tree_constant (result.unitary_matrix ()); + retval(1) = tree_constant (result.schur_matrix ()); } } break; @@ -121,48 +121,48 @@ ComplexSCHUR result (ctmp,ord); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (result.schur_matrix ()); + retval.resize (1); + retval(0) = tree_constant (result.schur_matrix ()); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (result.unitary_matrix ()); - retval[1] = tree_constant (result.schur_matrix ()); + retval.resize (2); + retval(0) = tree_constant (result.unitary_matrix ()); + retval(1) = tree_constant (result.schur_matrix ()); } } break; case tree_constant_rep::scalar_constant: { double d = arg.double_value (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (d); + retval.resize (1); + retval(0) = tree_constant (d); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (1); - retval[1] = tree_constant (d); + retval.resize (2); + retval(0) = tree_constant (1); + retval(1) = tree_constant (d); } } break; case tree_constant_rep::complex_scalar_constant: { Complex c = arg.complex_value (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (c); + retval.resize (1); + retval(0) = tree_constant (c); } else { - retval = new tree_constant [3]; - retval[0] = tree_constant (1); - retval[1] = tree_constant (c); + retval.resize (2); + retval(0) = tree_constant (1); + retval(1) = tree_constant (c); } } break;
--- a/src/svd.cc +++ b/src/svd.cc @@ -35,19 +35,19 @@ #include "f-svd.h" #ifdef WITH_DLD -tree_constant * -builtin_svd_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_svd_2 (const Octave_object& args, int nargin, int nargout) { return svd (args, nargin, nargout); } #endif -tree_constant * -svd (const tree_constant *args, int nargin, int nargout) +Octave_object +svd (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arg = args[1].make_numeric (); + tree_constant arg = args(1).make_numeric (); if (arg.rows () == 0 || arg.columns () == 0) { @@ -57,10 +57,10 @@ if (flag < 0) gripe_empty_arg ("svd", 0); Matrix m; - retval = new tree_constant [4]; - retval[0] = tree_constant (m); - retval[1] = tree_constant (m); - retval[2] = tree_constant (m); + retval.resize (3); + retval(0) = tree_constant (m); + retval(1) = tree_constant (m); + retval(2) = tree_constant (m); } else gripe_empty_arg ("svd", 1); @@ -100,17 +100,17 @@ DiagMatrix sigma = result.singular_values (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (sigma.diag (), 1); + retval.resize (1); + retval(0) = tree_constant (sigma.diag (), 1); } else { - retval = new tree_constant [4]; - retval[0] = tree_constant (result.left_singular_matrix ()); - retval[1] = tree_constant (sigma); - retval[2] = tree_constant (result.right_singular_matrix ()); + retval.resize (3); + retval(0) = tree_constant (result.left_singular_matrix ()); + retval(1) = tree_constant (sigma); + retval(2) = tree_constant (result.right_singular_matrix ()); } } break; @@ -121,17 +121,17 @@ DiagMatrix sigma = result.singular_values (); - if (nargout == 1) + if (nargout == 0 || nargout == 1) { - retval = new tree_constant [2]; - retval[0] = tree_constant (sigma.diag (), 1); + retval.resize (1); + retval(0) = tree_constant (sigma.diag (), 1); } else { - retval = new tree_constant [4]; - retval[0] = tree_constant (result.left_singular_matrix ()); - retval[1] = tree_constant (sigma); - retval[2] = tree_constant (result.right_singular_matrix ()); + retval.resize (3); + retval(0) = tree_constant (result.left_singular_matrix ()); + retval(1) = tree_constant (sigma); + retval(2) = tree_constant (result.right_singular_matrix ()); } } break;
--- a/src/syl.cc +++ b/src/syl.cc @@ -55,21 +55,21 @@ } #ifdef WITH_DLD -tree_constant * -builtin_syl_2 (const tree_constant *args, int nargin, int nargout) +Octave_object +builtin_syl_2 (const Octave_object& args, int nargin, int nargout) { return syl (args, nargin, nargout); } #endif -tree_constant * -syl (const tree_constant *args, int nargin, int nargout) +Octave_object +syl (const Octave_object& args, int nargin, int nargout) { - tree_constant *retval = NULL_TREE_CONST; + Octave_object retval; - tree_constant arga = args[1].make_numeric (); - tree_constant argb = args[2].make_numeric (); - tree_constant argc = args[3].make_numeric (); + tree_constant arga = args(1).make_numeric (); + tree_constant argb = args(2).make_numeric (); + tree_constant argc = args(3).make_numeric (); if (arga.is_empty () || argb.is_empty () || argc.is_empty ()) retval = vector_of_empties (nargout, "syl"); @@ -98,7 +98,7 @@ // Dimensions look o.k., let's solve the problem. - retval = new tree_constant[nargout+1]; + retval.resize (nargout ? nargout : 1); if (arga.is_complex_type () || argb.is_complex_type () || argc.is_complex_type ()) @@ -138,7 +138,7 @@ cx = -ua * cx * ub.hermitian (); - retval[0] = tree_constant (cx); + retval(0) = tree_constant (cx); } else { @@ -180,7 +180,7 @@ cx = -ua*cx*ub.transpose (); - retval[0] = tree_constant (cx); + retval(0) = tree_constant (cx); } } return retval;
--- a/src/symtab.h +++ b/src/symtab.h @@ -35,12 +35,7 @@ #include "SLStack.h" -#ifndef SV_FUNCTION_TYPEDEFS -#define SV_FUNCTION_TYPEDEFS 1 - -typedef int (*sv_Function)(void); - -#endif +#include "builtins.h" #define HASH_TABLE_SIZE 1024 /* Must be multiple of 2 */ #define HASH_MASK (HASH_TABLE_SIZE - 1)
--- a/src/variables.h +++ b/src/variables.h @@ -36,12 +36,7 @@ struct builtin_general_functions; struct builtin_string_variables; -#ifndef SV_FUNCTION_TYPEDEFS -#define SV_FUNCTION_TYPEDEFS 1 - -typedef int (*sv_Function)(void); - -#endif +#include "builtins.h" extern void initialize_symbol_tables (void);