GNU Octave  4.2.1
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-2017 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 #if defined (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 "call-stack.h"
35 #include "debug.h"
36 #include "defun.h"
37 #include "error.h"
38 #include "errwarn.h"
39 #include "input.h"
40 #include "interpreter.h"
41 #include "ov-fcn-handle.h"
42 #include "ov-usr-fcn.h"
43 #include "variables.h"
44 #include "pt-all.h"
45 #include "pt-eval.h"
46 #include "symtab.h"
47 #include "unwind-prot.h"
48 
49 //FIXME: This should be part of tree_evaluator
50 #include "pt-jit.h"
51 
52 // Maximum nesting level for functions, scripts, or sourced files called
53 // recursively.
55 
56 // If TRUE, turn off printing of results in functions (as if a
57 // semicolon has been appended to each statement).
58 static bool Vsilent_functions = false;
59 
60 namespace octave
61 {
63 
65 
66  bool tree_evaluator::debug_mode = false;
67 
69 
72 
74 
75  // Normal evaluator.
76 
77  void
79  {
81  }
82 
83  void
85  {
87  }
88 
89  void
91  {
93  }
94 
95  void
97  {
98  if (debug_mode)
99  do_breakpoint (cmd.is_breakpoint (true));
100 
101  if (statement_context == function || statement_context == script
102  || in_loop_command)
104  }
105 
106  void
108  {
109  panic_impossible ();
110  }
111 
112  void
114  {
115  if (debug_mode)
116  do_breakpoint (cmd.is_breakpoint (true));
117 
118  if (in_loop_command)
120  }
121 
122  void
124  {
126 
127  dbstep_flag = 0;
128  }
129 
130  bool
132  {
133  return ! (Vsilent_functions && (statement_context == function
134  || statement_context == script));
135  }
136 }
137 
138 static inline void
140 {
141  tree_identifier *id = elt.ident ();
142 
143  if (id)
144  {
145  id->mark_global ();
146 
147  octave_lvalue ult = id->lvalue ();
148 
149  if (ult.is_undefined ())
150  {
151  tree_expression *expr = elt.expression ();
152 
153  octave_value init_val;
154 
155  if (expr)
156  init_val = expr->rvalue1 ();
157  else
158  init_val = Matrix ();
159 
160  ult.assign (octave_value::op_asn_eq, init_val);
161  }
162  }
163 }
164 
165 static inline void
167 {
168  tree_identifier *id = elt.ident ();
169 
170  if (id)
171  {
172  id->mark_as_static ();
173 
174  octave_lvalue ult = id->lvalue ();
175 
176  if (ult.is_undefined ())
177  {
178  tree_expression *expr = elt.expression ();
179 
180  octave_value init_val;
181 
182  if (expr)
183  init_val = expr->rvalue1 ();
184  else
185  init_val = Matrix ();
186 
187  ult.assign (octave_value::op_asn_eq, init_val);
188  }
189  }
190 }
191 
192 namespace octave
193 {
194  void
196  tree_decl_init_list *init_list)
197  {
198  if (init_list)
199  {
200  for (tree_decl_init_list::iterator p = init_list->begin ();
201  p != init_list->end (); p++)
202  {
203  tree_decl_elt *elt = *p;
204 
205  fcn (*elt);
206  }
207  }
208  }
209 
210  void
212  {
213  if (debug_mode)
214  do_breakpoint (cmd.is_breakpoint (true));
215 
217  }
218 
219  void
221  {
222  if (debug_mode)
223  do_breakpoint (cmd.is_breakpoint (true));
224 
226  }
227 
228  void
230  {
231  panic_impossible ();
232  }
233 
234  void
236  {
237  panic_impossible ();
238  }
239 }
240 
241 // Decide if it's time to quit a for or while loop.
242 static inline bool
244 {
245  octave_quit ();
246 
247  // Maybe handle 'continue N' someday...
248 
251 
252  bool quit = (tree_return_command::returning
255 
258 
259  return quit;
260 }
261 
262 namespace octave
263 {
264  void
266  {
267  if (debug_mode)
268  do_breakpoint (cmd.is_breakpoint (true));
269 
270  // FIXME: need to handle PARFOR loops here using cmd.in_parallel ()
271  // and cmd.maxproc_expr ();
272 
274 
276 
277  in_loop_command = true;
278 
279  tree_expression *expr = cmd.control_expr ();
280 
281  octave_value rhs = expr->rvalue1 ();
282 
283 #if defined (HAVE_LLVM)
284  if (tree_jit::execute (cmd, rhs))
285  return;
286 #endif
287 
288  if (rhs.is_undefined ())
289  return;
290 
291  tree_expression *lhs = cmd.left_hand_side ();
292 
293  octave_lvalue ult = lhs->lvalue ();
294 
295  tree_statement_list *loop_body = cmd.body ();
296 
297  if (rhs.is_range ())
298  {
299  Range rng = rhs.range_value ();
300 
301  octave_idx_type steps = rng.numel ();
302 
303  for (octave_idx_type i = 0; i < steps; i++)
304  {
305  octave_value val (rng.elem (i));
306 
308 
309  if (loop_body)
310  loop_body->accept (*this);
311 
312  if (quit_loop_now ())
313  break;
314  }
315  }
316  else if (rhs.is_scalar_type ())
317  {
318  ult.assign (octave_value::op_asn_eq, rhs);
319 
320  if (loop_body)
321  loop_body->accept (*this);
322 
323  // Maybe decrement break and continue states.
324  quit_loop_now ();
325  }
326  else if (rhs.is_matrix_type () || rhs.is_cell () || rhs.is_string ()
327  || rhs.is_map ())
328  {
329  // A matrix or cell is reshaped to 2 dimensions and iterated by
330  // columns.
331 
332  dim_vector dv = rhs.dims ().redim (2);
333 
334  octave_idx_type nrows = dv(0);
335  octave_idx_type steps = dv(1);
336 
337  if (steps > 0)
338  {
339  octave_value arg = rhs;
340  if (rhs.ndims () > 2)
341  arg = arg.reshape (dv);
342 
343  // for row vectors, use single index to speed things up.
344  octave_value_list idx;
345  octave_idx_type iidx;
346  if (nrows == 1)
347  {
348  idx.resize (1);
349  iidx = 0;
350  }
351  else
352  {
353  idx.resize (2);
355  iidx = 1;
356  }
357 
358  for (octave_idx_type i = 1; i <= steps; i++)
359  {
360  // do_index_op expects one-based indices.
361  idx(iidx) = i;
362  octave_value val = arg.do_index_op (idx);
363 
364  ult.assign (octave_value::op_asn_eq, val);
365 
366  if (loop_body)
367  loop_body->accept (*this);
368 
369  if (quit_loop_now ())
370  break;
371  }
372  }
373  }
374  else
375  error ("invalid type in for loop expression near line %d, column %d",
376  cmd.line (), cmd.column ());
377  }
378 
379  void
381  {
382  if (debug_mode)
383  do_breakpoint (cmd.is_breakpoint (true));
384 
386 
388 
389  in_loop_command = true;
390 
391  tree_expression *expr = cmd.control_expr ();
392 
393  octave_value rhs = expr->rvalue1 ();
394 
395  if (rhs.is_undefined ())
396  return;
397 
398  if (! rhs.is_map ())
399  error ("in statement 'for [X, Y] = VAL', VAL must be a structure");
400 
401  // Cycle through structure elements. First element of id_list
402  // is set to value and the second is set to the name of the
403  // structure element.
404 
405  tree_argument_list *lhs = cmd.left_hand_side ();
406 
408 
409  tree_expression *elt = *p++;
410 
411  octave_lvalue val_ref = elt->lvalue ();
412 
413  elt = *p;
414 
415  octave_lvalue key_ref = elt->lvalue ();
416 
417  const octave_map tmp_val = rhs.map_value ();
418 
419  tree_statement_list *loop_body = cmd.body ();
420 
421  string_vector keys = tmp_val.keys ();
422 
423  octave_idx_type nel = keys.numel ();
424 
425  for (octave_idx_type i = 0; i < nel; i++)
426  {
427  std::string key = keys[i];
428 
429  const Cell val_lst = tmp_val.contents (key);
430 
431  octave_idx_type n = val_lst.numel ();
432 
433  octave_value val = (n == 1) ? val_lst(0) : octave_value (val_lst);
434 
435  val_ref.assign (octave_value::op_asn_eq, val);
436  key_ref.assign (octave_value::op_asn_eq, key);
437 
438  if (loop_body)
439  loop_body->accept (*this);
440 
441  if (quit_loop_now ())
442  break;
443  }
444  }
445 
446  void
448  {
449  panic_impossible ();
450  }
451 
452  void
454  {
455  panic_impossible ();
456  }
457 
458  void
460  {
461  panic_impossible ();
462  }
463 
464  void
466  {
467  panic_impossible ();
468  }
469 
470  void
472  {
473  octave_value fcn = cmd.function ();
474 
475  octave_function *f = fcn.function_value ();
476 
477  if (f)
478  {
479  std::string nm = f->name ();
480 
482 
483  // Make sure that any variable with the same name as the new
484  // function is cleared.
485 
487  }
488  }
489 
490  void
492  {
493  panic_impossible ();
494  }
495 
496  void
498  {
499  panic_impossible ();
500  }
501 
502  void
504  {
505  tree_if_command_list *lst = cmd.cmd_list ();
506 
507  if (lst)
508  lst->accept (*this);
509  }
510 
511  void
513  {
514  for (tree_if_command_list::iterator p = lst.begin (); p != lst.end (); p++)
515  {
516  tree_if_clause *tic = *p;
517 
518  tree_expression *expr = tic->condition ();
519 
520  if (statement_context == function || statement_context == script)
521  octave_call_stack::set_location (tic->line (), tic->column ());
522 
523  if (debug_mode && ! tic->is_else_clause ())
524  do_breakpoint (tic->is_breakpoint (true));
525 
526  if (tic->is_else_clause () || expr->is_logically_true ("if"))
527  {
528  tree_statement_list *stmt_lst = tic->commands ();
529 
530  if (stmt_lst)
531  stmt_lst->accept (*this);
532 
533  break;
534  }
535  }
536  }
537 
538  void
540  {
541  panic_impossible ();
542  }
543 
544  void
546  {
547  panic_impossible ();
548  }
549 
550  void
552  {
553  panic_impossible ();
554  }
555 
556  void
558  {
559  panic_impossible ();
560  }
561 
562  void
564  {
565  if (debug_mode && cmd.is_end_of_fcn_or_script ())
566  do_breakpoint (cmd.is_breakpoint (true), true);
567  }
568 
569  void
571  {
572  panic_impossible ();
573  }
574 
575  void
577  {
578  panic_impossible ();
579  }
580 
581  void
583  {
584  panic_impossible ();
585  }
586 
587  void
589  {
590  panic_impossible ();
591  }
592 
593  void
595  {
596  panic_impossible ();
597  }
598 
599  void
601  {
602  panic_impossible ();
603  }
604 
605  void
607  {
608  if (debug_mode)
609  do_breakpoint (cmd.is_breakpoint (true));
610 
611  // Act like dbcont.
612 
613  if (Vdebugging
615  {
616  Vdebugging = false;
617 
619  }
620  else if (statement_context == function || statement_context == script
621  || in_loop_command)
623  }
624 
625  void
627  {
628  panic_impossible ();
629  }
630 
631  void
633  {
634  panic_impossible ();
635  }
636 
637  void
639  {
640  tree_command *cmd = stmt.command ();
641  tree_expression *expr = stmt.expression ();
642 
643  if (cmd || expr)
644  {
645  if (statement_context == function || statement_context == script)
646  {
647  // Skip commands issued at a debug> prompt to avoid disturbing
648  // the state of the program we are debugging.
649 
650  if (Vtrack_line_num)
651  octave_call_stack::set_location (stmt.line (), stmt.column ());
652 
653  if ((statement_context == script
657  || (statement_context == function
659  stmt.echo_code ();
660  }
661 
662  try
663  {
664  if (cmd)
665  cmd->accept (*this);
666  else
667  {
668  if (debug_mode)
669  do_breakpoint (expr->is_breakpoint (true));
670 
671  // FIXME: maybe all of this should be packaged in
672  // one virtual function that returns a flag saying whether
673  // or not the expression will take care of binding ans and
674  // printing the result.
675 
676  // FIXME: it seems that we should just have to
677  // call expr->rvalue1 () and that should take care of
678  // everything, binding ans as necessary?
679 
680  bool do_bind_ans = false;
681 
682  if (expr->is_identifier ())
683  {
684  tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
685 
686  do_bind_ans = (! id->is_variable ());
687  }
688  else
689  do_bind_ans = (! expr->is_assignment_expression ());
690 
691  octave_value tmp_result = expr->rvalue1 (0);
692 
693  if (do_bind_ans && tmp_result.is_defined ())
694  bind_ans (tmp_result, expr->print_result ()
696 
697  // if (tmp_result.is_defined ())
698  // result_values(0) = tmp_result;
699  }
700  }
701  catch (const std::bad_alloc&)
702  {
703  // FIXME: We want to use error_with_id here so that give users
704  // control over this error message but error_with_id will
705  // require some memory allocations. Is there anything we can
706  // do to make those more likely to succeed?
707 
708  error_with_id ("Octave:bad-alloc",
709  "out of memory or dimension too large for Octave's index type");
710  }
711  }
712  }
713 
714  void
716  {
717  // FIXME: commented out along with else clause below.
718  // static octave_value_list empty_list;
719 
721 
722  if (p != lst.end ())
723  {
724  while (true)
725  {
726  tree_statement *elt = *p++;
727 
728  if (! elt)
729  error ("invalid statement found in statement list!");
730 
731  octave_quit ();
732 
733  elt->accept (*this);
734 
737  break;
738 
740  break;
741 
742  if (p == lst.end ())
743  break;
744  else
745  {
746  // Clear previous values before next statement is
747  // evaluated so that we aren't holding an extra
748  // reference to a value that may be used next. For
749  // example, in code like this:
750  //
751  // X = rand (N); # refcount for X should be 1
752  // # after this statement
753  //
754  // X(idx) = val; # no extra copy of X should be
755  // # needed, but we will be faked
756  // # out if retval is not cleared
757  // # between statements here
758 
759  // result_values = empty_list;
760  }
761  }
762  }
763  }
764 
765  void
767  {
768  panic_impossible ();
769  }
770 
771  void
773  {
774  panic_impossible ();
775  }
776 
777  void
779  {
780  if (debug_mode)
781  do_breakpoint (cmd.is_breakpoint (true));
782 
783  tree_expression *expr = cmd.switch_value ();
784 
785  if (! expr)
786  error ("missing value in switch command near line %d, column %d",
787  cmd.line (), cmd.column ());
788 
789  octave_value val = expr->rvalue1 ();
790 
791  tree_switch_case_list *lst = cmd.case_list ();
792 
793  if (lst)
794  {
795  for (tree_switch_case_list::iterator p = lst->begin ();
796  p != lst->end (); p++)
797  {
798  tree_switch_case *t = *p;
799 
800  if (t->is_default_case () || t->label_matches (val))
801  {
802  tree_statement_list *stmt_lst = t->commands ();
803 
804  if (stmt_lst)
805  stmt_lst->accept (*this);
806 
807  break;
808  }
809  }
810  }
811  }
812 
813  void
815  {
816  bool execution_error = false;
817 
818  {
819  // unwind frame before catch block
821 
825 
827  Vdebug_on_error = false;
828  Vdebug_on_warning = false;
829 
830  // The catch code is *not* added to unwind_protect stack;
831  // it doesn't need to be run on interrupts.
832 
833  tree_statement_list *try_code = cmd.body ();
834 
835  if (try_code)
836  {
837  try
838  {
839  in_try_catch++;
840  try_code->accept (*this);
841  in_try_catch--;
842  }
843  catch (const octave::execution_exception&)
844  {
846 
847  in_try_catch--; // must be restored before "catch" block
848  execution_error = true;
849  }
850  }
851  // Unwind to let the user print any messages from
852  // errors that occurred in the body of the try_catch statement,
853  // or throw further errors.
854  }
855 
856  if (execution_error)
857  {
858  tree_statement_list *catch_code = cmd.cleanup ();
859  if (catch_code)
860  {
861  tree_identifier *expr_id = cmd.identifier ();
862  octave_lvalue ult;
863 
864  if (expr_id)
865  {
866  ult = expr_id->lvalue ();
867 
869 
870  err.assign ("message", last_error_message ());
871  err.assign ("identifier", last_error_id ());
872  err.assign ("stack", last_error_stack ());
873 
874  ult.assign (octave_value::op_asn_eq, err);
875  }
876 
877  // perform actual "catch" block
878  if (catch_code)
879  catch_code->accept (*this);
880  }
881  }
882  }
883 
884  void
886  {
888 
891 
892  // We want to preserve the last location info for possible
893  // backtracking.
898 
899  // Similarly, if we have seen a return or break statement, allow all
900  // the cleanup code to run before returning or handling the break.
901  // We don't have to worry about continue statements because they can
902  // only occur in loops.
903 
906 
909 
910  try
911  {
912  if (list)
913  list->accept (*this);
914  }
915  catch (const octave::execution_exception&)
916  {
918 
920  frame.discard (2);
921  else
922  frame.run (2);
923 
924  frame.discard (2);
925 
926  throw;
927  }
928 
929  // The unwind_protects are popped off the stack in the reverse of
930  // the order they are pushed on.
931 
932  // FIXME: these statements say that if we see a break or
933  // return statement in the cleanup block, that we want to use the
934  // new value of the breaking or returning flag instead of restoring
935  // the previous value. Is that the right thing to do? I think so.
936  // Consider the case of
937  //
938  // function foo ()
939  // unwind_protect
940  // fprintf (stderr, "1: this should always be executed\n");
941  // break;
942  // fprintf (stderr, "1: this should never be executed\n");
943  // unwind_protect_cleanup
944  // fprintf (stderr, "2: this should always be executed\n");
945  // return;
946  // fprintf (stderr, "2: this should never be executed\n");
947  // end_unwind_protect
948  // endfunction
949  //
950  // If we reset the value of the breaking flag, both the returning
951  // flag and the breaking flag will be set, and we shouldn't have
952  // both. So, use the most recent one. If there is no return or
953  // break in the cleanup block, the values should be reset to
954  // whatever they were when the cleanup block was entered.
955 
957  frame.discard (2);
958  else
959  frame.run (2);
960  }
961 
962  void
964  {
965  tree_statement_list *cleanup_code = cmd.cleanup ();
966 
967  tree_statement_list *unwind_protect_code = cmd.body ();
968 
969  if (unwind_protect_code)
970  {
971  try
972  {
973  unwind_protect_code->accept (*this);
974  }
975  catch (const octave::execution_exception&)
976  {
977  // FIXME: Maybe we should be able to temporarily set the
978  // interpreter's exception handling state to something "safe"
979  // while the cleanup block runs instead of just resetting it
980  // here?
982 
983  // Run the cleanup code on exceptions, so that it is run even
984  // in case of interrupt or out-of-memory.
985  do_unwind_protect_cleanup_code (cleanup_code);
986 
987  // If an error occurs inside the cleanup code, a new
988  // exception will be thrown instead of the original.
989  throw;
990  }
991 
992  // Also execute the unwind_protect_cleanump code if the
993  // unwind_protect block runs without error.
994  do_unwind_protect_cleanup_code (cleanup_code);
995  }
996  }
997 
998  void
1000  {
1001 #if defined (HAVE_LLVM)
1002  if (tree_jit::execute (cmd))
1003  return;
1004 #endif
1005 
1007 
1008  frame.protect_var (in_loop_command);
1009 
1010  in_loop_command = true;
1011 
1012  tree_expression *expr = cmd.condition ();
1013 
1014  if (! expr)
1015  panic_impossible ();
1016 
1017  for (;;)
1018  {
1019  if (debug_mode)
1020  do_breakpoint (cmd.is_breakpoint (true));
1021 
1022  if (expr->is_logically_true ("while"))
1023  {
1024  tree_statement_list *loop_body = cmd.body ();
1025 
1026  if (loop_body)
1027  loop_body->accept (*this);
1028 
1029  if (quit_loop_now ())
1030  break;
1031  }
1032  else
1033  break;
1034  }
1035  }
1036 
1037  void
1039  {
1040 #if defined (HAVE_LLVM)
1041  if (tree_jit::execute (cmd))
1042  return;
1043 #endif
1044 
1046 
1047  frame.protect_var (in_loop_command);
1048 
1049  in_loop_command = true;
1050 
1051  tree_expression *expr = cmd.condition ();
1052  int until_line = cmd.line ();
1053  int until_column = cmd.column ();
1054 
1055  if (! expr)
1056  panic_impossible ();
1057 
1058  for (;;)
1059  {
1060  tree_statement_list *loop_body = cmd.body ();
1061 
1062  if (loop_body)
1063  loop_body->accept (*this);
1064 
1065  if (quit_loop_now ())
1066  break;
1067 
1068  if (debug_mode)
1069  do_breakpoint (cmd.is_breakpoint (true));
1070 
1071  octave_call_stack::set_location (until_line, until_column);
1072 
1073  if (expr->is_logically_true ("do-until"))
1074  break;
1075  }
1076  }
1077 
1078  void
1080  {
1081  do_breakpoint (stmt.is_breakpoint (true), stmt.is_end_of_fcn_or_script ());
1082  }
1083 
1084  void
1085  tree_evaluator::do_breakpoint (bool is_breakpoint,
1086  bool is_end_of_fcn_or_script) const
1087  {
1088  bool break_on_this_statement = false;
1089 
1091  {
1092  break_on_this_statement = true;
1093 
1095 
1097  }
1098  else if (is_breakpoint)
1099  {
1100  break_on_this_statement = true;
1101 
1102  dbstep_flag = 0;
1103 
1105  }
1106  else if (dbstep_flag > 0)
1107  {
1109  {
1110  if (dbstep_flag == 1 || is_end_of_fcn_or_script)
1111  {
1112  // We get here if we are doing a "dbstep" or a "dbstep N" and the
1113  // count has reached 1 so that we must stop and return to debug
1114  // prompt. Alternatively, "dbstep N" has been used but the end
1115  // of the frame has been reached so we stop at the last line and
1116  // return to prompt.
1117 
1118  break_on_this_statement = true;
1119 
1120  dbstep_flag = 0;
1121  }
1122  else
1123  {
1124  // Executing "dbstep N". Decrease N by one and continue.
1125 
1126  dbstep_flag--;
1127  }
1128 
1129  }
1130  else if (dbstep_flag == 1
1132  {
1133  // We stepped out from the end of a function.
1134 
1136 
1137  break_on_this_statement = true;
1138 
1139  dbstep_flag = 0;
1140  }
1141  }
1142  else if (dbstep_flag == -1)
1143  {
1144  // We get here if we are doing a "dbstep in".
1145 
1146  break_on_this_statement = true;
1147 
1148  dbstep_flag = 0;
1149 
1151  }
1152  else if (dbstep_flag == -2)
1153  {
1154  // We get here if we are doing a "dbstep out". Check for end of
1155  // function and whether the current frame is the same as the
1156  // cached value because we want to step out from the frame where
1157  // "dbstep out" was evaluated, not from any functions called from
1158  // that frame.
1159 
1160  if (is_end_of_fcn_or_script
1162  dbstep_flag = -1;
1163  }
1164 
1165  if (break_on_this_statement)
1166  do_keyboard ();
1167 
1168  }
1169 
1170  // ARGS is currently unused, but since the do_keyboard function in
1171  // input.cc accepts an argument list, we preserve it here so that the
1172  // interface won't have to change if we decide to use it in the future.
1173 
1174  octave_value
1176  {
1177  return ::do_keyboard (args);
1178  }
1179 }
1180 
1181 DEFUN (max_recursion_depth, args, nargout,
1182  doc: /* -*- texinfo -*-
1183 @deftypefn {} {@var{val} =} max_recursion_depth ()
1184 @deftypefnx {} {@var{old_val} =} max_recursion_depth (@var{new_val})
1185 @deftypefnx {} {} max_recursion_depth (@var{new_val}, "local")
1186 Query or set the internal limit on the number of times a function may
1187 be called recursively.
1188 
1189 If the limit is exceeded, an error message is printed and control returns to
1190 the top level.
1191 
1192 When called from inside a function with the @qcode{"local"} option, the
1193 variable is changed locally for the function and any subroutines it calls.
1194 The original variable value is restored when exiting the function.
1195 @end deftypefn */)
1196 {
1197  return SET_INTERNAL_VARIABLE (max_recursion_depth);
1198 }
1199 
1200 /*
1201 %!test
1202 %! orig_val = max_recursion_depth ();
1203 %! old_val = max_recursion_depth (2*orig_val);
1204 %! assert (orig_val, old_val);
1205 %! assert (max_recursion_depth (), 2*orig_val);
1206 %! max_recursion_depth (orig_val);
1207 %! assert (max_recursion_depth (), orig_val);
1208 
1209 %!error (max_recursion_depth (1, 2))
1210 */
1211 
1212 DEFUN (silent_functions, args, nargout,
1213  doc: /* -*- texinfo -*-
1214 @deftypefn {} {@var{val} =} silent_functions ()
1215 @deftypefnx {} {@var{old_val} =} silent_functions (@var{new_val})
1216 @deftypefnx {} {} silent_functions (@var{new_val}, "local")
1217 Query or set the internal variable that controls whether internal
1218 output from a function is suppressed.
1219 
1220 If this option is disabled, Octave will display the results produced by
1221 evaluating expressions within a function body that are not terminated with
1222 a semicolon.
1223 
1224 When called from inside a function with the @qcode{"local"} option, the
1225 variable is changed locally for the function and any subroutines it calls.
1226 The original variable value is restored when exiting the function.
1227 @end deftypefn */)
1228 {
1229  return SET_INTERNAL_VARIABLE (silent_functions);
1230 }
1231 
1232 /*
1233 %!test
1234 %! orig_val = silent_functions ();
1235 %! old_val = silent_functions (! orig_val);
1236 %! assert (orig_val, old_val);
1237 %! assert (silent_functions (), ! orig_val);
1238 %! silent_functions (orig_val);
1239 %! assert (silent_functions (), orig_val);
1240 
1241 %!error (silent_functions (1, 2))
1242 */
octave_lvalue lvalue(void)
Definition: pt-id.cc:125
bool Vdebug_on_error
Definition: error.cc:61
string_vector keys(void) const
Definition: oct-map.h:338
tree_identifier * identifier(void)
Definition: pt-except.h:59
const Cell & contents(const_iterator p) const
Definition: oct-map.h:313
void visit_funcall(tree_funcall &)
Definition: pt-eval.cc:582
bool is_range(void) const
Definition: ov.h:587
void discard(size_t num)
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
Definition: Cell.h:37
void mark_global(void)
Definition: pt-id.h:96
void visit_argument_list(tree_argument_list &)
Definition: pt-eval.cc:84
void visit_global_command(tree_global_command &)
Definition: pt-eval.cc:211
bool Vdebug_on_warning
Definition: error.cc:69
tree_statement_list * cleanup(void)
Definition: pt-except.h:127
int ndims(void) const
Definition: ov.h:495
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:515
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:728
bool label_matches(const octave_value &val)
Definition: pt-select.cc:121
void visit_parameter_list(tree_parameter_list &)
Definition: pt-eval.cc:588
tree_expression * switch_value(void)
Definition: pt-select.h:270
void visit_octave_user_script(octave_user_script &)
Definition: pt-eval.cc:447
static int dbstep_flag
Definition: pt-eval.h:155
void visit_octave_user_function_header(octave_user_function &)
Definition: pt-eval.cc:459
tree_expression * control_expr(void)
Definition: pt-loop.h:293
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
void visit_if_command_list(tree_if_command_list &)
Definition: pt-eval.cc:512
static bool all_scripts(void)
Definition: call-stack.h:208
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
static bool in_loop_command
Definition: pt-eval.h:176
static int continuing
Definition: pt-jump.h:78
void accept(tree_walker &tw)
Definition: pt-stmt.cc:324
static bool have_breakpoints(void)
Definition: debug.h:119
octave_map map_value(void) const
Definition: ov.cc:1693
bool is_scalar_type(void) const
Definition: ov.h:673
bool is_defined(void) const
Definition: ov.h:536
bool is_default_case(void)
Definition: pt-select.h:187
static bool execute(tree_simple_for_command &cmd, const octave_value &bounds)
Definition: pt-jit.cc:2026
tree_command * command(void)
Definition: pt-stmt.h:84
void run(size_t num)
Definition: Range.h:33
void do_decl_init_list(decl_elt_init_fcn fcn, tree_decl_init_list *init_list)
Definition: pt-eval.cc:195
void protect_var(T &var)
bool is_end_of_fcn_or_script(void) const
Definition: pt-cmd.h:79
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void echo_code(void)
Definition: pt-stmt.cc:128
void error(const char *fmt,...)
Definition: error.cc:570
static void reset_debug_state(void)
Definition: pt-eval.cc:123
void visit_try_catch_command(tree_try_catch_command &)
Definition: pt-eval.cc:814
std::string name(void) const
Definition: ov-fcn.h:163
#define SET_INTERNAL_VARIABLE(NM)
Definition: variables.h:126
tree_switch_case_list * case_list(void)
Definition: pt-select.h:272
void visit_persistent_command(tree_persistent_command &)
Definition: pt-eval.cc:220
void visit_constant(tree_constant &)
Definition: pt-eval.cc:570
void visit_simple_assignment(tree_simple_assignment &)
Definition: pt-eval.cc:632
std::list< tree_decl_elt * >::iterator iterator
Definition: base-list.h:40
bool is_cell(void) const
Definition: ov.h:545
tree_statement_list * commands(void)
Definition: pt-select.h:63
void visit_prefix_expression(tree_prefix_expression &)
Definition: pt-eval.cc:600
virtual octave_value do_keyboard(const octave_value_list &args=octave_value_list()) const
Definition: pt-eval.cc:1175
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
static bool statement_printing_enabled(void)
Definition: pt-eval.cc:131
static void set_location(int l, int c)
Definition: call-stack.h:230
void visit_statement(tree_statement &)
Definition: pt-eval.cc:638
tree_argument_list * left_hand_side(void)
Definition: pt-loop.h:291
static bool quiet_breakpoint_flag
Definition: pt-eval.h:162
octave_value arg
Definition: pr-output.cc:3440
octave_function * fcn
Definition: ov-class.cc:1743
tree_identifier * ident(void)
Definition: pt-decl.h:87
tree_decl_init_list * initializer_list(void)
Definition: pt-decl.h:162
void visit_return_command(tree_return_command &)
Definition: pt-eval.cc:606
tree_statement_list * body(void)
Definition: pt-loop.h:295
tree_if_command_list * cmd_list(void)
Definition: pt-select.h:137
tree_statement_list * body(void)
Definition: pt-loop.h:214
JNIEnv void * args
Definition: ov-java.cc:67
bool is_breakpoint(bool check_valid=false) const
Definition: pt-stmt.cc:94
static int breaking
Definition: pt-jump.h:50
static int current_line(void)
Definition: call-stack.h:114
void visit_switch_command(tree_switch_command &)
Definition: pt-eval.cc:778
int buffer_error_messages
Definition: error.cc:111
void mark_as_static(void)
Definition: pt-id.h:98
bool print_result(void) const
Definition: pt-exp.h:99
void visit_postfix_expression(tree_postfix_expression &)
Definition: pt-eval.cc:594
static void do_global_init(tree_decl_elt &elt)
Definition: pt-eval.cc:139
iterator end(void)
Definition: base-list.h:86
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
void do_breakpoint(tree_statement &stmt) const
Definition: pt-eval.cc:1079
tree_expression * condition(void)
Definition: pt-select.h:61
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
void add_fcn(void(*fcn)(void))
static size_t current_frame(void)
Definition: call-stack.h:131
void visit_cell(tree_cell &)
Definition: pt-eval.cc:551
tree_expression * control_expr(void)
Definition: pt-loop.h:210
void visit_identifier(tree_identifier &)
Definition: pt-eval.cc:491
bool Vtrack_line_num
Definition: input.cc:114
void visit_if_command(tree_if_command &)
Definition: pt-eval.cc:503
void visit_fcn_handle(tree_fcn_handle &)
Definition: pt-eval.cc:576
void error_with_id(const char *id, const char *fmt,...)
Definition: error.cc:615
void accept(tree_walker &tw)
Definition: pt-stmt.cc:185
static size_t current_frame
Definition: pt-eval.h:158
Range range_value(void) const
Definition: ov.h:923
bool is_matrix_type(void) const
Definition: ov.h:676
void visit_if_clause(tree_if_clause &)
Definition: pt-eval.cc:497
bool is_string(void) const
Definition: ov.h:578
octave_idx_type numel(void) const
Definition: Range.h:85
int in_try_catch
Definition: error.cc:115
OCTINTERP_API std::string last_error_id(void)
octave_value function(void)
Definition: pt-cmd.h:118
double elem(octave_idx_type i) const
Definition: Range.cc:88
tree_statement_list * body(void)
Definition: pt-except.h:125
static void install_cmdline_function(const std::string &name, const octave_value &fcn)
Definition: symtab.h:1566
#define panic_impossible()
Definition: error.h:40
void visit_binary_expression(tree_binary_expression &)
Definition: pt-eval.cc:90
void do_unwind_protect_cleanup_code(tree_statement_list *list)
Definition: pt-eval.cc:885
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
Definition: pt-eval.cc:78
tree_expression * left_hand_side(void)
Definition: pt-loop.h:208
void visit_octave_user_function_trailer(octave_user_function &)
Definition: pt-eval.cc:465
sig_atomic_t octave_interrupt_state
Definition: cquit.c:58
void visit_break_command(tree_break_command &)
Definition: pt-eval.cc:96
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
Definition: symtab.h:1330
dim_vector redim(int n) const
Definition: dim-vector.cc:275
tree_statement_list * body(void)
Definition: pt-except.h:61
static bool quit_loop_now(void)
Definition: pt-eval.cc:243
OCTINTERP_API void bind_ans(const octave_value &val, bool print)
Definition: dMatrix.h:37
tree_statement_list * commands(void)
Definition: pt-select.h:193
static void set_column(int c)
Definition: call-stack.h:242
tree_statement_list * cleanup(void)
Definition: pt-except.h:63
static bool debug_mode
Definition: pt-eval.h:160
dim_vector dims(void) const
Definition: ov.h:486
virtual int line(void) const
Definition: pt.h:49
void visit_switch_case_list(tree_switch_case_list &)
Definition: pt-eval.cc:772
void visit_while_command(tree_while_command &)
Definition: pt-eval.cc:999
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1705
int line(void) const
Definition: pt-stmt.cc:107
bool is_map(void) const
Definition: ov.h:590
void visit_decl_elt(tree_decl_elt &)
Definition: pt-eval.cc:229
octave::unwind_protect frame
Definition: graphics.cc:11584
void recover_from_exception(void)
Definition: interpreter.cc:200
OCTINTERP_API std::string last_error_message(void)
void visit_complex_for_command(tree_complex_for_command &)
Definition: pt-eval.cc:380
bool is_end_of_fcn_or_script(void) const
Definition: pt-stmt.cc:136
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
int Vecho_executing_commands
Definition: input.cc:93
OCTINTERP_API octave_map last_error_stack(void)
void visit_simple_for_command(tree_simple_for_command &)
Definition: pt-eval.cc:265
void visit_statement_list(tree_statement_list &)
Definition: pt-eval.cc:715
static int returning
Definition: pt-jump.h:106
void assign(octave_value::assign_op, const octave_value &)
Definition: oct-lvalue.cc:33
octave_value do_keyboard(const octave_value_list &args=octave_value_list())
bool is_else_clause(void)
Definition: pt-select.h:59
static bool Vsilent_functions
Definition: pt-eval.cc:58
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
static void do_static_init(tree_decl_elt &elt)
Definition: pt-eval.cc:166
int Vmax_recursion_depth
Definition: pt-eval.cc:54
p
Definition: lu.cc:138
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:223
tree_expression * expression(void)
Definition: pt-stmt.h:86
static int current_column(void)
Definition: call-stack.h:120
void visit_function_def(tree_function_def &)
Definition: pt-eval.cc:471
void visit_do_until_command(tree_do_until_command &)
Definition: pt-eval.cc:1038
tree_expression * expression(void)
Definition: pt-decl.h:91
bool is_breakpoint(bool check_active=false) const
Definition: pt.h:75
virtual octave_lvalue lvalue(void)
Definition: pt-exp.cc:72
void accept(tree_walker &tw)
Definition: pt-select.cc:81
void visit_decl_init_list(tree_decl_init_list &)
Definition: pt-eval.cc:235
bool octave_debug_on_interrupt_state
Definition: pt-bp.cc:33
bool is_undefined(void) const
Definition: ov.h:539
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
virtual bool is_assignment_expression(void) const
Definition: pt-exp.h:65
void visit_continue_command(tree_continue_command &)
Definition: pt-eval.cc:113
static void set_line(int l)
Definition: call-stack.h:236
int column(void) const
Definition: pt-stmt.cc:113
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
Definition: error.cc:1036
bool is_undefined(void) const
Definition: oct-lvalue.h:73
static stmt_list_type statement_context
Definition: pt-eval.h:173
tree_statement_list * body(void)
Definition: pt-loop.h:84
virtual bool is_logically_true(const char *)
Definition: pt-exp.cc:39
void visit_switch_case(tree_switch_case &)
Definition: pt-eval.cc:766
void visit_no_op_command(tree_no_op_command &)
Definition: pt-eval.cc:563
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool Vdebugging
Definition: input.cc:109
void visit_return_list(tree_return_list &)
Definition: pt-eval.cc:626
void visit_octave_user_function(octave_user_function &)
Definition: pt-eval.cc:453
virtual int column(void) const
Definition: pt.h:51
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
virtual void accept(tree_walker &tw)=0
void visit_unwind_protect_command(tree_unwind_protect_command &)
Definition: pt-eval.cc:963
void visit_colon_expression(tree_colon_expression &)
Definition: pt-eval.cc:107
dim_vector dv
Definition: sub2ind.cc:263
void visit_index_expression(tree_index_expression &)
Definition: pt-eval.cc:539
void visit_multi_assignment(tree_multi_assignment &)
Definition: pt-eval.cc:557
virtual bool is_identifier(void) const
Definition: pt-exp.h:61
iterator begin(void)
Definition: base-list.h:83
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
void visit_matrix(tree_matrix &)
Definition: pt-eval.cc:545
tree_expression * condition(void)
Definition: pt-loop.h:82
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
Definition: ov.h:454