# HG changeset patch # User John W. Eaton # Date 1554060939 0 # Node ID daab1b311a9815509e1326a0569b471741e665e5 # Parent b37c1656aa420ca1d661867f29f0d1bd5d7ec408 move core of assignin function to evaluator * pt-eval.h, pt-eval.cc (tree_evaluator::assignin): Move innter workings of assignin function here from oct-parse.yy. * interpreter.h, interpreter.cc (interpreter::assignin): New function. * oct-parse.yy (Fassignin): Extract arguments and call interpreter::assignin. diff -r b37c1656aa42 -r daab1b311a98 libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc Tue Apr 02 14:49:58 2019 -0700 +++ b/libinterp/corefcn/interpreter.cc Sun Mar 31 19:35:39 2019 +0000 @@ -1232,6 +1232,13 @@ m_evaluator.assign (name, val); } + void interpreter::assignin (const std::string& context, + const std::string& name, + const octave_value& val) + { + m_evaluator.assignin (context, name, val); + } + bool interpreter::at_top_level (void) const { return m_evaluator.at_top_level (); diff -r b37c1656aa42 -r daab1b311a98 libinterp/corefcn/interpreter.h --- a/libinterp/corefcn/interpreter.h Tue Apr 02 14:49:58 2019 -0700 +++ b/libinterp/corefcn/interpreter.h Sun Mar 31 19:35:39 2019 +0000 @@ -273,6 +273,9 @@ void assign (const std::string& name, const octave_value& val = octave_value ()); + void assignin (const std::string& context, const std::string& varname, + const octave_value& val = octave_value ()); + bool at_top_level (void) const; bool isglobal (const std::string& name) const; diff -r b37c1656aa42 -r daab1b311a98 libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy Tue Apr 02 14:49:58 2019 -0700 +++ b/libinterp/parse-tree/oct-parse.yy Sun Mar 31 19:35:39 2019 +0000 @@ -5567,44 +5567,18 @@ @seealso{evalin} @end deftypefn */) { - octave_value_list retval; - if (args.length () != 3) print_usage (); - std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string"); - - octave::unwind_protect frame; - - octave::call_stack& cs = interp.get_call_stack (); - - frame.add_method (cs, &octave::call_stack::restore_frame, - cs.current_frame ()); - - if (context == "caller") - cs.goto_caller_frame (); - else if (context == "base") - cs.goto_base_frame (); - else - error ("assignin: CONTEXT must be \"caller\" or \"base\""); - - std::string nm = args(1).xstring_value ("assignin: VARNAME must be a string"); - - if (octave::valid_identifier (nm)) - { - // Put the check here so that we don't slow down assignments - // generally. Any that go through Octave's parser should have - // already been checked. - - if (octave::iskeyword (nm)) - error ("assignin: invalid assignment to keyword '%s'", nm.c_str ()); - - interp.assign (nm, args(2)); - } - else - error ("assignin: invalid variable name in argument VARNAME"); - - return retval; + std::string context + = args(0).xstring_value ("assignin: CONTEXT must be a string"); + + std::string varname + = args(1).xstring_value ("assignin: VARNAME must be a string"); + + interp.assignin (context, varname, args(2)); + + return octave_value_list (); } /* @@ -5622,6 +5596,7 @@ @seealso{eval, assignin} @end deftypefn */) { + octave_value_list retval; int nargin = args.length (); diff -r b37c1656aa42 -r daab1b311a98 libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Tue Apr 02 14:49:58 2019 -0700 +++ b/libinterp/parse-tree/pt-eval.cc Sun Mar 31 19:35:39 2019 +0000 @@ -900,6 +900,42 @@ } void + tree_evaluator::assignin (const std::string& context, + const std::string& name, const octave_value& val) + { + // FIXME: Can this be done without an unwind-protect frame, simply + // by geting a reference to the caller or base stack frame and + // calling assign on that? + + octave::unwind_protect frame; + + frame.add_method (m_call_stack, &call_stack::restore_frame, + m_call_stack.current_frame ()); + + if (context == "caller") + m_call_stack.goto_caller_frame (); + else if (context == "base") + m_call_stack.goto_base_frame (); + else + error ("assignin: CONTEXT must be \"caller\" or \"base\""); + + if (valid_identifier (name)) + { + // Put the check here so that we don't slow down assignments + // generally. Any that go through Octave's parser should have + // already been checked. + + if (iskeyword (name)) + error ("assignin: invalid assignment to keyword '%s'", + name.c_str ()); + + assign (name, val); + } + else + error ("assignin: invalid variable name '%s'", name.c_str ()); + } + + void tree_evaluator::set_auto_fcn_var (stack_frame::auto_var_type avt, const octave_value& val) { diff -r b37c1656aa42 -r daab1b311a98 libinterp/parse-tree/pt-eval.h --- a/libinterp/parse-tree/pt-eval.h Tue Apr 02 14:49:58 2019 -0700 +++ b/libinterp/parse-tree/pt-eval.h Sun Mar 31 19:35:39 2019 +0000 @@ -405,6 +405,9 @@ void assign (const std::string& name, const octave_value& val = octave_value ()); + void assignin (const std::string& context, const std::string& name, + const octave_value& val = octave_value ()); + void set_auto_fcn_var (stack_frame::auto_var_type avt, const octave_value& val = octave_value ());