Mercurial > hg > octave-thorsten
changeset 4245:610671be8792
[project @ 2002-12-28 04:02:31 by jwe]
author | jwe |
---|---|
date | Sat, 28 Dec 2002 04:02:31 +0000 |
parents | 189df16144fc |
children | 0253850a08d7 |
files | src/ChangeLog src/ov-usr-fcn.cc src/parse.y src/variables.cc src/variables.h |
diffstat | 5 files changed, 89 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2002-12-27 John W. Eaton <jwe@bevo.che.wisc.edu> + + * parse.y (Fevalin): New function. + + * variables.cc (curr_caller_sym_tab): New global variable. + * variables.h: Provide decl. + (initialize_symbol_tables): Initialize it. + * ov-usr-fcn.cc (octave_user_function::do_multi_index_op): + Protect and set it here. + 2002-12-26 John W. Eaton <jwe@bevo.che.wisc.edu> * utils.cc (search_path_for_file): Second arg now string_vector.
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -400,6 +400,9 @@ // Save old and set current symbol table context, for // eval_undefined_error(). + unwind_protect_ptr (curr_caller_sym_tab); + curr_caller_sym_tab = curr_sym_tab; + unwind_protect_ptr (curr_sym_tab); curr_sym_tab = sym_tab;
--- a/src/parse.y +++ b/src/parse.y @@ -3732,6 +3732,75 @@ return retval; } +DEFUN (evalin, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ +Like @code{eval}, except that the expressions are evaluated in the\n\ +context @var{context}, which may be either @code{\"caller\"} or\n\ +@code{\"base\"}. +@end deftypefn") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin > 1) + { + std::string context = args(0).string_value (); + + if (! error_state) + { + unwind_protect::begin_frame ("Fevalin"); + + unwind_protect_ptr (curr_sym_tab); + + if (context == "caller") + curr_sym_tab = curr_caller_sym_tab; + else if (context == "base") + curr_sym_tab = top_level_sym_tab; + else + error ("evalin: context must be \"caller\" or \"base\""); + + if (nargin > 2) + { + unwind_protect_bool (buffer_error_messages); + buffer_error_messages = true; + } + + int parse_status = 0; + + retval = eval_string (args(1), ! Vdefault_eval_print_flag, + parse_status, nargout); + + if (nargin > 2 && (parse_status != 0 || error_state)) + { + error_state = 0; + + // Set up for letting the user print any messages from + // errors that occurred in the first part of this eval(). + + buffer_error_messages = false; + + bind_global_error_variable (); + + unwind_protect::add (clear_global_error_variable, 0); + + eval_string (args(2), 0, parse_status, nargout); + + retval = octave_value_list (); + } + + unwind_protect::run_frame ("Fevalin"); + } + else + error ("evalin: expecting string as first argument"); + } + else + print_usage ("evalin"); + + return retval; +} + static int default_eval_print_flag (void) {
--- a/src/variables.cc +++ b/src/variables.cc @@ -65,6 +65,9 @@ // Symbol table for the current scope. symbol_table *curr_sym_tab = 0; +// Symbol table for the current caller scope. +symbol_table *curr_caller_sym_tab = 0; + // Symbol table for global symbols. symbol_table *global_sym_tab = 0; @@ -94,7 +97,7 @@ if (! top_level_sym_tab) top_level_sym_tab = new symbol_table (4096, "TOP"); - curr_sym_tab = top_level_sym_tab; + curr_caller_sym_tab = curr_sym_tab = top_level_sym_tab; } // Attributes of variables and functions.
--- a/src/variables.h +++ b/src/variables.h @@ -116,6 +116,9 @@ // Symbol table for the current scope. extern symbol_table *curr_sym_tab; +// Symbol table for the current caller scope. +extern symbol_table *curr_caller_sym_tab; + // Symbol table for global symbols. extern symbol_table *global_sym_tab;