Mercurial > hg > octave-nkf
changeset 4954:ed0f3cb6d3d4
[project @ 2004-09-01 21:24:53 by jwe]
author | jwe |
---|---|
date | Wed, 01 Sep 2004 21:24:54 +0000 |
parents | 7a3a480e8645 |
children | af7a5459bcec |
files | src/ChangeLog src/DLD-FUNCTIONS/quad.cc src/dynamic-ld.cc src/ov-base.h src/ov-fcn-inline.cc src/ov-fcn-inline.h src/ov.h src/variables.cc src/variables.h |
diffstat | 9 files changed, 74 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2004-09-01 David Bateman <dbateman@free.fr> + + * DLD-FUNCTION/quad.cc: Allow function handle and inline functions. + Use a unique function name and delete it on exit. + + * ov.h (is_inline_function): New virtual function. + * ov-fcn-inline.h (is_inline_function): New function. + * ov-base.h (is_inline_function): New function. + + * ov-fcn-inline.cc (octave_fcn_handle::octave_fcn_handle): + Use unique_symbol_name and clear_function instead of manipulating + symbol table directly. + + * variables.cc (unique_symbol_name): New function. + (clear_function): New function. + * variables.h: Provide decls. + + * dynamic-ld.cc (do_clear_function): Rename from clear_function. + 2004-09-01 John W. Eaton <jwe@octave.org> * OPERATORS/op-i8-i8.cc, OPERATORS/op-i16-i16.cc,
--- a/src/DLD-FUNCTIONS/quad.cc +++ b/src/DLD-FUNCTIONS/quad.cc @@ -105,6 +105,8 @@ #define QUAD_ABORT() \ do \ { \ + if (fcn_name.length()) \ + clear_function (fcn_name); \ unwind_protect::run_frame ("Fquad"); \ return retval; \ } \ @@ -130,8 +132,9 @@ "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{v}, @var{ier}, @var{nfun}, @var{err}] =} quad (@var{f}, @var{a}, @var{b}, @var{tol}, @var{sing})\n\ Integrate a nonlinear function of one variable using Quadpack.\n\ -The first argument is the name of the function to call to compute the\n\ -value of the integrand. It must have the form\n\ +The first argument is the name of the function, the function handle or\n\ +the inline function to call to compute the value of the integrand. It\n\ +must have the form\n\ \n\ @example\n\ y = f (x)\n\ @@ -165,6 +168,8 @@ { octave_value_list retval; + std::string fcn_name; + warned_imaginary = false; unwind_protect::begin_frame ("Fquad"); @@ -179,9 +184,18 @@ if (nargin > 2 && nargin < 6 && nargout < 5) { - quad_fcn = extract_function (args(0), "quad", "__quad_fcn__", - "function y = __quad_fcn__ (x) y = ", - "; endfunction"); + if (args(0).is_function_handle () || args(0).is_inline_function ()) + quad_fcn = args(0).function_value (); + else + { + fcn_name = unique_symbol_name ("__quad__fcn__"); + std::string fname = "function y = "; + fname.append (fcn_name); + fname.append ("(x) y = "); + quad_fcn = extract_function (args(0), "quad", fcn_name, fname, + "; endfunction"); + } + if (! quad_fcn) QUAD_ABORT (); @@ -289,6 +303,9 @@ retval(2) = static_cast<double> (nfun); retval(1) = static_cast<double> (ier); retval(0) = val; + + if (fcn_name.length()) + clear_function (fcn_name); } else print_usage ("quad");
--- a/src/dynamic-ld.cc +++ b/src/dynamic-ld.cc @@ -195,7 +195,7 @@ } static -void clear_function (const std::string& fcn_name) +void do_clear_function (const std::string& fcn_name) { if (Vwarn_reload_forces_clear) warning (" %s", fcn_name.c_str ()); @@ -235,7 +235,7 @@ warning ("reloading %s clears the following functions:", oct_file.file_name().c_str ()); - oct_file.close (clear_function); + oct_file.close (do_clear_function); function = 0; }
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -171,6 +171,8 @@ bool is_function_handle (void) const { return false; } + bool is_inline_function (void) const { return false; } + bool is_function (void) const { return false; } bool is_builtin_function (void) const { return false; }
--- a/src/ov-fcn-inline.cc +++ b/src/ov-fcn-inline.cc @@ -55,11 +55,7 @@ : octave_fcn_handle (0, n), iftext (f), ifargs (a) { // Find a function name that isn't already in the symbol table. - - std::string fname = "__inline__"; - - while (symbol_exist (fname)) - fname.append ("X"); + std::string fname = unique_symbol_name ("__inline__"); // Form a string representing the function. @@ -91,10 +87,7 @@ { fcn = tmp; - // XXX FIXME XXX -- probably shouldn't be directly altering the - // symbol table here. - - fbi_sym_tab->clear_function (fname); + clear_function (fname); } else error ("inline: unable to define function");
--- a/src/ov-fcn-inline.h +++ b/src/ov-fcn-inline.h @@ -57,6 +57,8 @@ ~octave_fcn_inline (void) { } + bool is_inline_function (void) const { return true; } + octave_fcn_inline *fcn_inline_value (bool = false) { return this; } std::string fcn_text (void) const { return iftext; }
--- a/src/ov.h +++ b/src/ov.h @@ -484,6 +484,9 @@ virtual bool is_function_handle (void) const { return rep->is_function_handle (); } + virtual bool is_inline_function (void) const + { return rep->is_inline_function (); } + virtual bool is_function (void) const { return rep->is_function (); }
--- a/src/variables.cc +++ b/src/variables.cc @@ -662,6 +662,16 @@ return retval; } +std::string +unique_symbol_name (const std::string& basename) +{ + // XXX FIXME XXX Can we be smarter than just adding characters? + std::string name = basename; + while (symbol_exist (name, "any")) + name.append ("X"); + return name; +} + DEFUN (exist, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ @@ -1897,6 +1907,13 @@ } \ while (0) + +bool +clear_function (const std::string& nm) +{ + return do_clear_function (nm); +} + DEFCMD (clear, args, , "-*- texinfo -*-\n\ @deffn {Command} clear [-x] pattern @dots{}\n\
--- a/src/variables.h +++ b/src/variables.h @@ -77,6 +77,9 @@ extern int symbol_exist (const std::string& name, const std::string& type = "any"); +extern std::string +unique_symbol_name (const std::string& basename); + extern bool lookup (symbol_record *s, bool exec_script = true); extern symbol_record * @@ -116,6 +119,8 @@ extern void munlock (const std::string&); extern bool mislocked (const std::string&); +extern bool clear_function (const std::string& nm); + // Symbol table for symbols at the top level. extern symbol_table *top_level_sym_tab;