GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-eval.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <cctype>
28 
29 #include <iostream>
30 
31 #include <fstream>
32 #include <typeinfo>
33 
34 #include "debug.h"
35 #include "defun.h"
36 #include "error.h"
37 #include "gripes.h"
38 #include "input.h"
39 #include "ov-fcn-handle.h"
40 #include "ov-usr-fcn.h"
41 #include "variables.h"
42 #include "pt-all.h"
43 #include "pt-eval.h"
44 #include "symtab.h"
45 #include "unwind-prot.h"
46 
47 //FIXME: This should be part of tree_evaluator
48 #include "pt-jit.h"
49 
51 
53 
55 
57 
58 bool tree_evaluator::debug_mode = false;
59 
62 
64 
65 // Maximum nesting level for functions, scripts, or sourced files called
66 // recursively.
68 
69 // If TRUE, turn off printing of results in functions (as if a
70 // semicolon has been appended to each statement).
71 static bool Vsilent_functions = false;
72 
73 // Normal evaluator.
74 
75 void
77 {
79 }
80 
81 void
83 {
85 }
86 
87 void
89 {
91 }
92 
93 void
95 {
96  if (! error_state)
97  {
98  if (debug_mode)
100 
101  if (statement_context == function || statement_context == script
102  || in_loop_command)
104  }
105 }
106 
107 void
109 {
110  panic_impossible ();
111 }
112 
113 void
115 {
116  if (! error_state)
117  {
118  if (debug_mode)
119  do_breakpoint (cmd.is_breakpoint ());
120 
121  if (statement_context == function || statement_context == script
122  || in_loop_command)
124  }
125 }
126 
127 void
129 {
131 
132  dbstep_flag = 0;
133 }
134 
135 bool
137 {
138  return ! (Vsilent_functions && (statement_context == function
139  || statement_context == script));
140 }
141 
142 static inline void
144 {
145  tree_identifier *id = elt.ident ();
146 
147  if (id)
148  {
149  id->mark_global ();
150 
151  if (! error_state)
152  {
153  octave_lvalue ult = id->lvalue ();
154 
155  if (ult.is_undefined ())
156  {
157  tree_expression *expr = elt.expression ();
158 
159  octave_value init_val;
160 
161  if (expr)
162  init_val = expr->rvalue1 ();
163  else
164  init_val = Matrix ();
165 
166  ult.assign (octave_value::op_asn_eq, init_val);
167  }
168  }
169  }
170 }
171 
172 static inline void
174 {
175  tree_identifier *id = elt.ident ();
176 
177  if (id)
178  {
179  id->mark_as_static ();
180 
181  octave_lvalue ult = id->lvalue ();
182 
183  if (ult.is_undefined ())
184  {
185  tree_expression *expr = elt.expression ();
186 
187  octave_value init_val;
188 
189  if (expr)
190  init_val = expr->rvalue1 ();
191  else
192  init_val = Matrix ();
193 
194  ult.assign (octave_value::op_asn_eq, init_val);
195  }
196  }
197 }
198 
199 void
200 tree_evaluator::do_decl_init_list (decl_elt_init_fcn fcn,
201  tree_decl_init_list *init_list)
202 {
203  if (init_list)
204  {
205  for (tree_decl_init_list::iterator p = init_list->begin ();
206  p != init_list->end (); p++)
207  {
208  tree_decl_elt *elt = *p;
209 
210  fcn (*elt);
211 
212  if (error_state)
213  break;
214  }
215  }
216 }
217 
218 void
220 {
221  if (debug_mode)
222  do_breakpoint (cmd.is_breakpoint ());
223 
225 }
226 
227 void
229 {
230  if (debug_mode)
231  do_breakpoint (cmd.is_breakpoint ());
232 
234 }
235 
236 void
238 {
239  panic_impossible ();
240 }
241 
242 #if 0
243 bool
244 tree_decl_elt::eval (void)
245 {
246  bool retval = false;
247 
248  if (id && expr)
249  {
250  octave_lvalue ult = id->lvalue ();
251 
252  octave_value init_val = expr->rvalue1 ();
253 
254  if (! error_state)
255  {
256  ult.assign (octave_value::op_asn_eq, init_val);
257 
258  retval = true;
259  }
260  }
261 
262  return retval;
263 }
264 #endif
265 
266 void
268 {
269  panic_impossible ();
270 }
271 
272 // Decide if it's time to quit a for or while loop.
273 static inline bool
275 {
276  octave_quit ();
277 
278  // Maybe handle 'continue N' someday...
279 
282 
283  bool quit = (error_state
287 
290 
291  return quit;
292 }
293 
294 void
296 {
297  if (error_state)
298  return;
299 
300  if (debug_mode)
301  do_breakpoint (cmd.is_breakpoint ());
302 
303  // FIXME: need to handle PARFOR loops here using cmd.in_parallel ()
304  // and cmd.maxproc_expr ();
305 
306  unwind_protect frame;
307 
309 
310  in_loop_command = true;
311 
312  tree_expression *expr = cmd.control_expr ();
313 
314  octave_value rhs = expr->rvalue1 ();
315 
316 #if HAVE_LLVM
317  if (tree_jit::execute (cmd, rhs))
318  return;
319 #endif
320 
321  if (error_state || rhs.is_undefined ())
322  return;
323 
324  {
325  tree_expression *lhs = cmd.left_hand_side ();
326 
327  octave_lvalue ult = lhs->lvalue ();
328 
329  if (error_state)
330  return;
331 
332  tree_statement_list *loop_body = cmd.body ();
333 
334  if (rhs.is_range ())
335  {
336  Range rng = rhs.range_value ();
337 
338  octave_idx_type steps = rng.nelem ();
339  double b = rng.base ();
340  double increment = rng.inc ();
341 
342  for (octave_idx_type i = 0; i < steps; i++)
343  {
344  // Use multiplication here rather than declaring a
345  // temporary variable outside the loop and using
346  //
347  // tmp_val += increment
348  //
349  // to avoid problems with limited precision. Also, this
350  // is consistent with the way Range::matrix_value is
351  // implemented.
352 
353  octave_value val (b + i * increment);
354 
355  ult.assign (octave_value::op_asn_eq, val);
356 
357  if (! error_state && loop_body)
358  loop_body->accept (*this);
359 
360  if (quit_loop_now ())
361  break;
362  }
363  }
364  else if (rhs.is_scalar_type ())
365  {
366  ult.assign (octave_value::op_asn_eq, rhs);
367 
368  if (! error_state && loop_body)
369  loop_body->accept (*this);
370 
371  // Maybe decrement break and continue states.
372  quit_loop_now ();
373  }
374  else if (rhs.is_matrix_type () || rhs.is_cell () || rhs.is_string ()
375  || rhs.is_map ())
376  {
377  // A matrix or cell is reshaped to 2 dimensions and iterated by
378  // columns.
379 
380  dim_vector dv = rhs.dims ().redim (2);
381 
382  octave_idx_type nrows = dv(0), steps = dv(1);
383 
384  if (steps > 0)
385  {
386  octave_value arg = rhs;
387  if (rhs.ndims () > 2)
388  arg = arg.reshape (dv);
389 
390  // for row vectors, use single index to speed things up.
391  octave_value_list idx;
392  octave_idx_type iidx;
393  if (nrows == 1)
394  {
395  idx.resize (1);
396  iidx = 0;
397  }
398  else
399  {
400  idx.resize (2);
402  iidx = 1;
403  }
404 
405  for (octave_idx_type i = 1; i <= steps; i++)
406  {
407  // do_index_op expects one-based indices.
408  idx(iidx) = i;
409  octave_value val = arg.do_index_op (idx);
410 
411  ult.assign (octave_value::op_asn_eq, val);
412 
413  if (! error_state && loop_body)
414  loop_body->accept (*this);
415 
416  if (quit_loop_now ())
417  break;
418  }
419  }
420  }
421  else
422  {
423  ::error ("invalid type in for loop expression near line %d, column %d",
424  cmd.line (), cmd.column ());
425  }
426  }
427 }
428 
429 void
431 {
432  if (error_state)
433  return;
434 
435  if (debug_mode)
436  do_breakpoint (cmd.is_breakpoint ());
437 
438  unwind_protect frame;
439 
441 
442  in_loop_command = true;
443 
444  tree_expression *expr = cmd.control_expr ();
445 
446  octave_value rhs = expr->rvalue1 ();
447 
448  if (error_state || rhs.is_undefined ())
449  return;
450 
451  if (rhs.is_map ())
452  {
453  // Cycle through structure elements. First element of id_list
454  // is set to value and the second is set to the name of the
455  // structure element.
456 
457  tree_argument_list *lhs = cmd.left_hand_side ();
458 
460 
461  tree_expression *elt = *p++;
462 
463  octave_lvalue val_ref = elt->lvalue ();
464 
465  elt = *p;
466 
467  octave_lvalue key_ref = elt->lvalue ();
468 
469  const octave_map tmp_val = rhs.map_value ();
470 
471  tree_statement_list *loop_body = cmd.body ();
472 
473  string_vector keys = tmp_val.keys ();
474 
475  octave_idx_type nel = keys.numel ();
476 
477  for (octave_idx_type i = 0; i < nel; i++)
478  {
479  std::string key = keys[i];
480 
481  const Cell val_lst = tmp_val.contents (key);
482 
483  octave_idx_type n = val_lst.numel ();
484 
485  octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst);
486 
487  val_ref.assign (octave_value::op_asn_eq, val);
488  key_ref.assign (octave_value::op_asn_eq, key);
489 
490  if (! error_state && loop_body)
491  loop_body->accept (*this);
492 
493  if (quit_loop_now ())
494  break;
495  }
496  }
497  else
498  error ("in statement 'for [X, Y] = VAL', VAL must be a structure");
499 }
500 
501 void
503 {
504  panic_impossible ();
505 }
506 
507 void
509 {
510  panic_impossible ();
511 }
512 
513 void
515 {
516  panic_impossible ();
517 }
518 
519 void
521 {
522  panic_impossible ();
523 }
524 
525 void
527 {
528  octave_value fcn = cmd.function ();
529 
530  octave_function *f = fcn.function_value ();
531 
532  if (f)
533  {
534  std::string nm = f->name ();
535 
537 
538  // Make sure that any variable with the same name as the new
539  // function is cleared.
540 
542  }
543 }
544 
545 void
547 {
548  panic_impossible ();
549 }
550 
551 void
553 {
554  panic_impossible ();
555 }
556 
557 void
559 {
560  tree_if_command_list *lst = cmd.cmd_list ();
561 
562  if (lst)
563  lst->accept (*this);
564 }
565 
566 void
568 {
569  for (tree_if_command_list::iterator p = lst.begin (); p != lst.end (); p++)
570  {
571  tree_if_clause *tic = *p;
572 
573  tree_expression *expr = tic->condition ();
574 
575  if (statement_context == function || statement_context == script)
576  octave_call_stack::set_location (tic->line (), tic->column ());
577 
578  if (debug_mode && ! tic->is_else_clause ())
579  do_breakpoint (tic->is_breakpoint ());
580 
581  if (tic->is_else_clause () || expr->is_logically_true ("if"))
582  {
583  if (! error_state)
584  {
585  tree_statement_list *stmt_lst = tic->commands ();
586 
587  if (stmt_lst)
588  stmt_lst->accept (*this);
589  }
590 
591  break;
592  }
593  }
594 }
595 
596 void
598 {
599  panic_impossible ();
600 }
601 
602 void
604 {
605  panic_impossible ();
606 }
607 
608 void
610 {
611  panic_impossible ();
612 }
613 
614 void
616 {
617  panic_impossible ();
618 }
619 
620 void
622 {
623  if (debug_mode && cmd.is_end_of_fcn_or_script ())
624  do_breakpoint (cmd.is_breakpoint (), true);
625 }
626 
627 void
629 {
630  panic_impossible ();
631 }
632 
633 void
635 {
636  panic_impossible ();
637 }
638 
639 void
641 {
642  panic_impossible ();
643 }
644 
645 void
647 {
648  panic_impossible ();
649 }
650 
651 void
653 {
654  panic_impossible ();
655 }
656 
657 void
659 {
660  if (! error_state)
661  {
662  if (debug_mode)
663  do_breakpoint (cmd.is_breakpoint ());
664 
665  // Act like dbcont.
666 
667  if (Vdebugging
669  {
670  Vdebugging = false;
671 
673  }
674  else if (statement_context == function || statement_context == script
675  || in_loop_command)
677  }
678 }
679 
680 void
682 {
683  panic_impossible ();
684 }
685 
686 void
688 {
689  panic_impossible ();
690 }
691 
692 void
694 {
695  tree_command *cmd = stmt.command ();
696  tree_expression *expr = stmt.expression ();
697 
698  if (cmd || expr)
699  {
700  if (statement_context == function || statement_context == script)
701  {
702  // Skip commands issued at a debug> prompt to avoid disturbing
703  // the state of the program we are debugging.
704 
705  if (! Vdebugging)
706  octave_call_stack::set_location (stmt.line (), stmt.column ());
707 
708  // FIXME: we need to distinguish functions from scripts
709  // to get this right.
710  if ((statement_context == script
713  || (statement_context == function
715  stmt.echo_code ();
716  }
717 
718  try
719  {
720  if (cmd)
721  cmd->accept (*this);
722  else
723  {
724  if (debug_mode)
725  do_breakpoint (expr->is_breakpoint ());
726 
727  // FIXME: maybe all of this should be packaged in
728  // one virtual function that returns a flag saying whether
729  // or not the expression will take care of binding ans and
730  // printing the result.
731 
732  // FIXME: it seems that we should just have to
733  // call expr->rvalue1 () and that should take care of
734  // everything, binding ans as necessary?
735 
736  bool do_bind_ans = false;
737 
738  if (expr->is_identifier ())
739  {
740  tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
741 
742  do_bind_ans = (! id->is_variable ());
743  }
744  else
745  do_bind_ans = (! expr->is_assignment_expression ());
746 
747  octave_value tmp_result = expr->rvalue1 (0);
748 
749  if (do_bind_ans && ! (error_state || tmp_result.is_undefined ()))
750  bind_ans (tmp_result, expr->print_result ()
752 
753  // if (tmp_result.is_defined ())
754  // result_values(0) = tmp_result;
755  }
756  }
757  catch (octave_execution_exception)
758  {
760  }
761  catch (std::bad_alloc)
762  {
763  // FIXME: We want to use error_with_id here so that we set
764  // the error state, give users control over this error
765  // message, and so that we set the error_state appropriately
766  // so we'll get stack trace info when appropriate. But
767  // error_with_id will require some memory allocations. Is
768  // there anything we can do to make those more likely to
769  // succeed?
770 
771  error_with_id ("Octave:bad-alloc",
772  "out of memory or dimension too large for Octave's index type");
773  }
774  }
775 }
776 
777 void
779 {
780  static octave_value_list empty_list;
781 
782  if (error_state)
783  return;
784 
786 
787  if (p != lst.end ())
788  {
789  while (true)
790  {
791  tree_statement *elt = *p++;
792 
793  if (elt)
794  {
795  octave_quit ();
796 
797  elt->accept (*this);
798 
799  if (error_state)
800  break;
801 
804  break;
805 
807  break;
808 
809  if (p == lst.end ())
810  break;
811  else
812  {
813  // Clear previous values before next statement is
814  // evaluated so that we aren't holding an extra
815  // reference to a value that may be used next. For
816  // example, in code like this:
817  //
818  // X = rand (N); # refcount for X should be 1
819  // # after this statement
820  //
821  // X(idx) = val; # no extra copy of X should be
822  // # needed, but we will be faked
823  // # out if retval is not cleared
824  // # between statements here
825 
826  // result_values = empty_list;
827  }
828  }
829  else
830  error ("invalid statement found in statement list!");
831  }
832  }
833 }
834 
835 void
837 {
838  panic_impossible ();
839 }
840 
841 void
843 {
844  panic_impossible ();
845 }
846 
847 void
849 {
850  if (debug_mode)
851  do_breakpoint (cmd.is_breakpoint ());
852 
853  tree_expression *expr = cmd.switch_value ();
854 
855  if (expr)
856  {
857  octave_value val = expr->rvalue1 ();
858 
859  tree_switch_case_list *lst = cmd.case_list ();
860 
861  if (! error_state && lst)
862  {
863  for (tree_switch_case_list::iterator p = lst->begin ();
864  p != lst->end (); p++)
865  {
866  tree_switch_case *t = *p;
867 
868  if (t->is_default_case () || t->label_matches (val))
869  {
870  if (error_state)
871  break;
872 
873  tree_statement_list *stmt_lst = t->commands ();
874 
875  if (stmt_lst)
876  stmt_lst->accept (*this);
877 
878  break;
879  }
880  }
881  }
882  }
883  else
884  ::error ("missing value in switch command near line %d, column %d",
885  cmd.line (), cmd.column ());
886 }
887 
888 void
890 {
891  unwind_protect frame;
892 
896 
898  Vdebug_on_error = false;
899  Vdebug_on_warning = false;
900 
901  tree_statement_list *catch_code = cmd.cleanup ();
902 
903  // The catch code is *not* added to unwind_protect stack; it doesn't need
904  // to be run on interrupts.
905 
906  tree_statement_list *try_code = cmd.body ();
907 
908  if (try_code)
909  {
910  try_code->accept (*this);
911  }
912 
913  if (error_state)
914  {
915  error_state = 0;
916 
917  if (catch_code)
918  {
919  // Set up for letting the user print any messages from errors that
920  // occurred in the body of the try_catch statement.
921 
923 
924  tree_identifier *expr_id = cmd.identifier ();
925  octave_lvalue ult;
926 
927  if (expr_id)
928  {
929 
930  octave_scalar_map err;
931 
932  ult = expr_id->lvalue ();
933 
934  if (error_state)
935  return;
936 
937  err.assign ("message", last_error_message ());
938  err.assign ("identifier", last_error_id ());
939 
940  if (! error_state)
941  ult.assign (octave_value::op_asn_eq, err);
942 
943  }
944 
945  if (catch_code)
946  catch_code->accept (*this);
947  }
948  }
949 }
950 
951 void
953 {
954  unwind_protect frame;
955 
958 
959  // We want to run the cleanup code without error_state being set,
960  // but we need to restore its value, so that any errors encountered
961  // in the first part of the unwind_protect are not completely
962  // ignored.
963 
964  frame.protect_var (error_state);
965  error_state = 0;
966 
967  // We want to preserve the last location info for possible
968  // backtracking.
973 
974  // Similarly, if we have seen a return or break statement, allow all
975  // the cleanup code to run before returning or handling the break.
976  // We don't have to worry about continue statements because they can
977  // only occur in loops.
978 
981 
984 
985  if (list)
986  list->accept (*this);
987 
988  // The unwind_protects are popped off the stack in the reverse of
989  // the order they are pushed on.
990 
991  // FIXME: these statements say that if we see a break or
992  // return statement in the cleanup block, that we want to use the
993  // new value of the breaking or returning flag instead of restoring
994  // the previous value. Is that the right thing to do? I think so.
995  // Consider the case of
996  //
997  // function foo ()
998  // unwind_protect
999  // stderr << "1: this should always be executed\n";
1000  // break;
1001  // stderr << "1: this should never be executed\n";
1002  // unwind_protect_cleanup
1003  // stderr << "2: this should always be executed\n";
1004  // return;
1005  // stderr << "2: this should never be executed\n";
1006  // end_unwind_protect
1007  // endfunction
1008  //
1009  // If we reset the value of the breaking flag, both the returning
1010  // flag and the breaking flag will be set, and we shouldn't have
1011  // both. So, use the most recent one. If there is no return or
1012  // break in the cleanup block, the values should be reset to
1013  // whatever they were when the cleanup block was entered.
1014 
1016  {
1017  frame.discard (2);
1018  }
1019  else
1020  {
1021  frame.run (2);
1022  }
1023 
1024  // We don't want to ignore errors that occur in the cleanup code, so
1025  // if an error is encountered there, leave error_state alone.
1026  // Otherwise, set it back to what it was before.
1027 
1028  if (error_state)
1029  frame.discard (2);
1030  else
1031  frame.run (2);
1032 
1033  frame.run ();
1034 }
1035 
1036 void
1038 {
1039  tree_statement_list *cleanup_code = cmd.cleanup ();
1040 
1041  tree_statement_list *unwind_protect_code = cmd.body ();
1042 
1043  if (unwind_protect_code)
1044  {
1045  try
1046  {
1047  unwind_protect_code->accept (*this);
1048  }
1049  catch (...)
1050  {
1051  // Run the cleanup code on exceptions, so that it is run even in case
1052  // of interrupt or out-of-memory.
1053  do_unwind_protect_cleanup_code (cleanup_code);
1054  // FIXME: should error_state be checked here?
1055  // We want to rethrow the exception, even if error_state is set, so
1056  // that interrupts continue.
1057  throw;
1058  }
1059 
1060  do_unwind_protect_cleanup_code (cleanup_code);
1061  }
1062 }
1063 
1064 void
1066 {
1067  if (error_state)
1068  return;
1069 
1070 #if HAVE_LLVM
1071  if (tree_jit::execute (cmd))
1072  return;
1073 #endif
1074 
1075  unwind_protect frame;
1076 
1077  frame.protect_var (in_loop_command);
1078 
1079  in_loop_command = true;
1080 
1081  tree_expression *expr = cmd.condition ();
1082 
1083  if (! expr)
1084  panic_impossible ();
1085 
1086  for (;;)
1087  {
1088  if (debug_mode)
1089  do_breakpoint (cmd.is_breakpoint ());
1090 
1091  if (expr->is_logically_true ("while"))
1092  {
1093  tree_statement_list *loop_body = cmd.body ();
1094 
1095  if (loop_body)
1096  {
1097  loop_body->accept (*this);
1098 
1099  if (error_state)
1100  return;
1101  }
1102 
1103  if (quit_loop_now ())
1104  break;
1105  }
1106  else
1107  break;
1108  }
1109 }
1110 
1111 void
1113 {
1114  if (error_state)
1115  return;
1116 
1117  unwind_protect frame;
1118 
1119  frame.protect_var (in_loop_command);
1120 
1121  in_loop_command = true;
1122 
1123  tree_expression *expr = cmd.condition ();
1124 
1125  if (! expr)
1126  panic_impossible ();
1127 
1128  for (;;)
1129  {
1130  tree_statement_list *loop_body = cmd.body ();
1131 
1132  if (loop_body)
1133  {
1134  loop_body->accept (*this);
1135 
1136  if (error_state)
1137  return;
1138  }
1139 
1140  if (quit_loop_now ())
1141  break;
1142 
1143  if (debug_mode)
1144  do_breakpoint (cmd.is_breakpoint ());
1145 
1146  if (expr->is_logically_true ("do-until"))
1147  break;
1148  }
1149 }
1150 
1151 void
1153 {
1155 }
1156 
1157 void
1158 tree_evaluator::do_breakpoint (bool is_breakpoint,
1159  bool is_end_of_fcn_or_script) const
1160 {
1161  bool break_on_this_statement = false;
1162 
1164  {
1165  break_on_this_statement = true;
1166 
1168 
1170  }
1171  else if (is_breakpoint)
1172  {
1173  break_on_this_statement = true;
1174 
1175  dbstep_flag = 0;
1176 
1178  }
1179  else if (dbstep_flag > 0)
1180  {
1182  {
1183  if (dbstep_flag == 1 || is_end_of_fcn_or_script)
1184  {
1185  // We get here if we are doing a "dbstep" or a "dbstep N" and the
1186  // count has reached 1 so that we must stop and return to debug
1187  // prompt. Alternatively, "dbstep N" has been used but the end
1188  // of the frame has been reached so we stop at the last line and
1189  // return to prompt.
1190 
1191  break_on_this_statement = true;
1192 
1193  dbstep_flag = 0;
1194  }
1195  else
1196  {
1197  // Executing "dbstep N". Decrease N by one and continue.
1198 
1199  dbstep_flag--;
1200  }
1201 
1202  }
1203  else if (dbstep_flag == 1
1205  {
1206  // We stepped out from the end of a function.
1207 
1209 
1210  break_on_this_statement = true;
1211 
1212  dbstep_flag = 0;
1213  }
1214  }
1215  else if (dbstep_flag == -1)
1216  {
1217  // We get here if we are doing a "dbstep in".
1218 
1219  break_on_this_statement = true;
1220 
1221  dbstep_flag = 0;
1222 
1224  }
1225  else if (dbstep_flag == -2)
1226  {
1227  // We get here if we are doing a "dbstep out". Check for end of
1228  // function and whether the current frame is the same as the
1229  // cached value because we want to step out from the frame where
1230  // "dbstep out" was evaluated, not from any functions called from
1231  // that frame.
1232 
1233  if (is_end_of_fcn_or_script
1235  dbstep_flag = -1;
1236  }
1237 
1238  if (break_on_this_statement)
1239  do_keyboard ();
1240 
1241 }
1242 
1243 // ARGS is currently unused, but since the do_keyboard function in
1244 // input.cc accepts an argument list, we preserve it here so that the
1245 // interface won't have to change if we decide to use it in the future.
1246 
1249 {
1250  return ::do_keyboard (args);
1251 }
1252 
1253 DEFUN (max_recursion_depth, args, nargout,
1254  "-*- texinfo -*-\n\
1255 @deftypefn {Built-in Function} {@var{val} =} max_recursion_depth ()\n\
1256 @deftypefnx {Built-in Function} {@var{old_val} =} max_recursion_depth (@var{new_val})\n\
1257 @deftypefnx {Built-in Function} {} max_recursion_depth (@var{new_val}, \"local\")\n\
1258 Query or set the internal limit on the number of times a function may\n\
1259 be called recursively. If the limit is exceeded, an error message is\n\
1260 printed and control returns to the top level.\n\
1261 \n\
1262 When called from inside a function with the @qcode{\"local\"} option, the\n\
1263 variable is changed locally for the function and any subroutines it calls.\n\
1264 The original variable value is restored when exiting the function.\n\
1265 @end deftypefn")
1266 {
1267  return SET_INTERNAL_VARIABLE (max_recursion_depth);
1268 }
1269 
1270 /*
1271 %!test
1272 %! orig_val = max_recursion_depth ();
1273 %! old_val = max_recursion_depth (2*orig_val);
1274 %! assert (orig_val, old_val);
1275 %! assert (max_recursion_depth (), 2*orig_val);
1276 %! max_recursion_depth (orig_val);
1277 %! assert (max_recursion_depth (), orig_val);
1278 
1279 %!error (max_recursion_depth (1, 2))
1280 */
1281 
1282 DEFUN (silent_functions, args, nargout,
1283  "-*- texinfo -*-\n\
1284 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\
1285 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\
1286 @deftypefnx {Built-in Function} {} silent_functions (@var{new_val}, \"local\")\n\
1287 Query or set the internal variable that controls whether internal\n\
1288 output from a function is suppressed. If this option is disabled,\n\
1289 Octave will display the results produced by evaluating expressions\n\
1290 within a function body that are not terminated with a semicolon.\n\
1291 \n\
1292 When called from inside a function with the @qcode{\"local\"} option, the\n\
1293 variable is changed locally for the function and any subroutines it calls.\n\
1294 The original variable value is restored when exiting the function.\n\
1295 @end deftypefn")
1296 {
1297  return SET_INTERNAL_VARIABLE (silent_functions);
1298 }
1299 
1300 /*
1301 %!test
1302 %! orig_val = silent_functions ();
1303 %! old_val = silent_functions (! orig_val);
1304 %! assert (orig_val, old_val);
1305 %! assert (silent_functions (), ! orig_val);
1306 %! silent_functions (orig_val);
1307 %! assert (silent_functions (), orig_val);
1308 
1309 %!error (silent_functions (1, 2))
1310 */