# HG changeset patch # User jwe # Date 793906737 0 # Node ID c210c5a25a4839fc4e88599e290741a5e6a17a2d # Parent 0326a802cd5cef7936278bc5ddcba4f19a860dff [project @ 1995-02-27 17:36:16 by jwe] diff -r 0326a802cd5c -r c210c5a25a48 src/parse.y --- a/src/parse.y Mon Feb 27 16:15:02 1995 +0000 +++ b/src/parse.y Mon Feb 27 17:38:57 1995 +0000 @@ -1339,13 +1339,10 @@ } else { - symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); + static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); + static tree_identifier ans_id (sr); - assert (sr); - - tree_identifier *ans = new tree_identifier (sr); - - return new tree_simple_assignment_expression (ans, expr, 0, 1); + return new tree_simple_assignment_expression (&ans_id, expr, 1, 1); } } diff -r 0326a802cd5c -r c210c5a25a48 src/pt-exp-base.cc --- a/src/pt-exp-base.cc Mon Feb 27 16:15:02 1995 +0000 +++ b/src/pt-exp-base.cc Mon Feb 27 17:38:57 1995 +0000 @@ -963,29 +963,11 @@ if (! error_state && retval.is_defined ()) { if (maybe_do_ans_assign && ! object_to_eval->is_constant ()) - { - -// XXX FIXME XXX -- need a procedure to do this, probably in -// variables.cc, to isolate the code that does lookups... - - symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); - - assert (sr); - - tree_identifier *ans_id = new tree_identifier (sr); - - tree_constant *tmp = new tree_constant (retval); - - tree_simple_assignment_expression tmp_ass (ans_id, tmp, 0, 1); - - tmp_ass.eval (print); - } - else - { - if (print) - print_constant (retval, name ()); - } + bind_ans (retval, print); + else if (print) + print_constant (retval, name ()); } + return retval; } @@ -1015,24 +997,7 @@ retval = object_to_eval->eval (0, nargout, args); if (retval.length () > 0 && retval(0).is_defined ()) - { - -// XXX FIXME XXX -- need a procedure to do this, probably in -// variables.cc, to isolate the code that does lookups... - - symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); - - assert (sr); - - tree_identifier *ans_id = new tree_identifier (sr); - - tree_constant *tmp = new tree_constant (retval(0)); - - tree_simple_assignment_expression tmp_ass (ans_id, - tmp, 0, 1); - - tmp_ass.eval (print); - } + bind_ans (retval(0), print); } else retval = object_to_eval->eval (print, nargout, args); diff -r 0326a802cd5c -r c210c5a25a48 src/variables.cc --- a/src/variables.cc Mon Feb 27 16:15:02 1995 +0000 +++ b/src/variables.cc Mon Feb 27 17:38:57 1995 +0000 @@ -1405,6 +1405,19 @@ } #endif +void +bind_ans (const tree_constant& val, int print) +{ + static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); + static tree_identifier ans_id (sr); + + tree_constant *tmp = new tree_constant (val); + + tree_simple_assignment_expression tmp_ass (&ans_id, tmp, 1, 1); + + tmp_ass.eval (print); +} + // Give a global variable a definition. This will insert the symbol // in the global table if necessary. diff -r 0326a802cd5c -r c210c5a25a48 src/variables.h --- a/src/variables.h Mon Feb 27 16:15:02 1995 +0000 +++ b/src/variables.h Mon Feb 27 17:38:57 1995 +0000 @@ -109,6 +109,8 @@ int nargin, int nargout); #endif +extern void bind_ans (const tree_constant& val, int print); + extern void bind_builtin_variable (const char *, tree_constant *, int protect = 0, int eternal = 0, sv_Function f = (sv_Function) 0,