diff test/recursion.tst @ 24325:bc65aa8a5ff1

don't store persistent variables separately in scope object * symrec.cc, symrec.h (symbol_record::xpersistent_varref, symbol_record::xpersistent_varval): Delete unused functions. (symbol_record::symbol_record_rep::clear): If persistent, don't call symbol_scope::persistent_assign. Clear value before clearing status as a persistent variable. (symbol_record::symbol_record_rep::init_persistent): Only mark_persistent, don't set value here. (symbol_record::symbol_record_rep::varref): Don't call symbol_scope::persistent_varref. Simply store value in element zero of value stack. (symbol_record::symbol_record_rep::varval): Don't call symbol_scope::persistent_varref. Simply access value from element zero of value stack. * symscope.cc, symscope.h (symbol_scope::refresh): New function. (symbol_scope::m_persistent_symbols): Delete member variable and all uses. (symbol_scope::m_persistent_symbols_const_iterator, symbol_scope::m_persistent_symbols_iterator): Delete typedefs. (symbol_scope::persistent_assign, symbol_scope::persistent_varref, symbol_scope::persistent_varval): Delete unused functions. * ov-usr-fcn.cc (octave_user_function::call): To clear local variables on function return, add symbol_scope::refresh to the unwind_protect frame instead of symbol_scope::clear_variables. * recursion.tst: New tests.
author John W. Eaton <jwe@octave.org>
date Mon, 27 Nov 2017 23:52:54 -0500
parents 092078913d54
children 194eb4bd202b
line wrap: on
line diff
--- a/test/recursion.tst	Mon Nov 27 20:28:13 2017 -0500
+++ b/test/recursion.tst	Mon Nov 27 23:52:54 2017 -0500
@@ -38,4 +38,30 @@
 %!
 %!assert (f (5), 120)
 
+%!function r = f (x)
+%!  persistent p = 1;
+%!  if (x == 1)
+%!    f (x + 1);
+%!    r = p;
+%!  else
+%!    clear p
+%!    p = 13;
+%!  endif
+%!endfunction
+%!
+%!error <'p' undefined> f (1)
+
+%!function r = f (x)
+%!  persistent p = 1;
+%!  if (x == 1)
+%!    f (x + 1);
+%!    r = p;
+%!  else
+%!    p = 13;
+%!  endif
+%!endfunction
+%!
+%!assert (f (1), 13)
+
+
 %%FIXME: Need test for maximum recursion depth