Mercurial > hg > octave-lojdl
changeset 2943:e6dfc3ea6299
[project @ 1997-05-08 02:31:59 by jwe]
author | jwe |
---|---|
date | Thu, 08 May 1997 02:37:21 +0000 |
parents | 026f342c2019 |
children | e9c24f32f175 |
files | src/oct-obj.h src/oct-usr-fcn.cc src/oct-usr-fcn.h src/pt-id.h |
diffstat | 4 files changed, 36 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -27,11 +27,10 @@ #pragma interface #endif -class string_vector; - #include <string> #include "Array.h" +#include "str-vec.h" #include "ov.h" @@ -129,10 +128,18 @@ string_vector make_argv (const string&) const; + void stash_name_tags (const string_vector& nm) { names = nm; } + + string_vector name_tags (void) const { return names; } + private: Array<octave_value> data; + // This list of strings can be used to tag each element of data with + // a name. By default, it is empty. + string_vector names; + // This constructor is private with no definition to keep statements // like //
--- a/src/oct-usr-fcn.cc +++ b/src/oct-usr-fcn.cc @@ -28,6 +28,8 @@ #include <config.h> #endif +#include "str-vec.h" + #include <defaults.h> #include "defun.h" #include "error.h" @@ -73,9 +75,10 @@ sym_tab (st), file_name (), fcn_name (), t_parsed (0), system_fcn_file (false), call_depth (0), num_named_args (0), args_passed (), num_args_passed (0), curr_va_arg_number (0), - vr_list (0), symtab_entry (0), nargin_sr (0), nargout_sr (0) + vr_list (0), symtab_entry (0), argn_sr (0), nargin_sr (0), + nargout_sr (0) { - install_nargin_and_nargout (); + install_automatic_vars (); if (param_list) { @@ -302,6 +305,8 @@ args_passed = args; + string_vector arg_names = args.name_tags (); + unwind_protect_int (num_args_passed); num_args_passed = nargin; @@ -328,7 +333,7 @@ // variables. { - bind_nargin_and_nargout (nargin, nargout); + bind_automatic_vars (arg_names, nargin, nargout); bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); @@ -414,15 +419,20 @@ } void -octave_user_function::install_nargin_and_nargout (void) +octave_user_function::install_automatic_vars (void) { + argn_sr = sym_tab->lookup ("argn", true); nargin_sr = sym_tab->lookup ("nargin", true); nargout_sr = sym_tab->lookup ("nargout", true); } void -octave_user_function::bind_nargin_and_nargout (int nargin, int nargout) +octave_user_function::bind_automatic_vars + (const string_vector& arg_names, int nargin, int nargout) { + if (! arg_names.empty ()) + argn_sr->define (arg_names); + nargin_sr->define (static_cast<double> (nargin)); nargout_sr->define (static_cast<double> (nargout)); }
--- a/src/oct-usr-fcn.h +++ b/src/oct-usr-fcn.h @@ -34,6 +34,8 @@ #include "oct-fcn.h" #include "oct-obj.h" +class string_vector; + class octave_value; class tree_parameter_list; class tree_statement_list; @@ -111,7 +113,6 @@ void accept (tree_walker& tw); - private: octave_user_function (void); @@ -167,6 +168,9 @@ // The symbol record for this function. symbol_record *symtab_entry; + // The symbol record for argn in the local symbol table. + symbol_record *argn_sr; + // The symbol record for nargin in the local symbol table. symbol_record *nargin_sr; @@ -177,9 +181,10 @@ void print_code_function_trailer (void); - void install_nargin_and_nargout (void); + void install_automatic_vars (void); - void bind_nargin_and_nargout (int nargin, int nargout); + void bind_automatic_vars (const string_vector& arg_names, int nargin, + int nargout); }; #endif
--- a/src/pt-id.h +++ b/src/pt-id.h @@ -31,6 +31,8 @@ #include <string> +class octave_value; +class octave_value_list; class octave_symbol; class octave_function; class symbol_record; @@ -96,8 +98,8 @@ octave_value eval (bool print = false); - octave_value_list eval (bool print, int nargout, - const octave_value_list& args); + octave_value_list + eval (bool print, int nargout, const octave_value_list& args); void eval_undefined_error (void);