Mercurial > jwe > octave
diff src/pt-cmd.cc @ 1168:e2036dce97ea
[project @ 1995-03-10 18:49:55 by jwe]
author | jwe |
---|---|
date | Fri, 10 Mar 1995 18:50:02 +0000 |
parents | 7f42e76331b0 |
children | b6360f2d4fa6 |
line wrap: on
line diff
--- a/src/pt-cmd.cc Fri Mar 10 16:39:45 1995 +0000 +++ b/src/pt-cmd.cc Fri Mar 10 18:50:02 1995 +0000 @@ -50,7 +50,7 @@ #include "unwind-prot.h" // Decide if it's time to quit a for or while loop. -static int +static inline int quit_loop_now (void) { // Maybe handle `continue N' someday... @@ -240,6 +240,87 @@ delete list; } +inline void +tree_for_command::do_for_loop_once (tree_constant& rhs, int& quit) +{ + quit = 0; + + tree_constant *tmp = new tree_constant (rhs); + tree_simple_assignment_expression tmp_ass (id, tmp, 1); + tmp_ass.eval (0); + + if (error_state) + { + eval_error (); + return; + } + + if (list) + { + list->eval (1); + if (error_state) + { + eval_error (); + quit = 1; + return; + } + } + + quit = quit_loop_now (); +} + +inline void +tree_for_command::do_for_loop_once (tree_identifier *ident, + tree_constant& rhs, int& quit) +{ + quit = 0; + + ident->assign (rhs); + + if (error_state) + { + eval_error (); + return; + } + + if (list) + { + list->eval (1); + if (error_state) + { + eval_error (); + quit = 1; + return; + } + } + + quit = quit_loop_now (); +} + +#define DO_LOOP(val) \ + do \ + { \ + if (ident) \ + for (int i = 0; i < steps; i++) \ + { \ + tree_constant rhs (val); \ + int quit = 0; \ + do_for_loop_once (ident, rhs, quit); \ + if (quit) \ + break; \ + } \ + else \ + for (int i = 0; i < steps; i++) \ + { \ + tree_constant rhs (val); \ + int quit = 0; \ + do_for_loop_once (rhs, quit); \ + if (quit) \ + break; \ + } \ + } \ + while (0) + void tree_for_command::eval (void) { @@ -254,11 +335,21 @@ return; } + tree_identifier *ident = 0; + if (! id->arg_list ()) + { + tree_indirect_ref *idr = id->ident (); + if (idr->is_identifier_only ()) + ident = idr->ident (); + } + if (tmp_expr.is_scalar_type ()) { - tree_constant *rhs = new tree_constant (tmp_expr); int quit = 0; - do_for_loop_once (rhs, quit); + if (ident) + do_for_loop_once (ident, tmp_expr, quit); + else + do_for_loop_once (tmp_expr, quit); } else if (tmp_expr.is_matrix_type ()) { @@ -279,29 +370,19 @@ steps = cm_tmp.columns (); } - for (int i = 0; i < steps; i++) + if (tmp_expr.is_real_matrix ()) { - tree_constant *rhs = 0; - if (nr == 1) - { - if (tmp_expr.is_real_matrix ()) - rhs = new tree_constant (m_tmp (0, i)); - else - rhs = new tree_constant (cm_tmp (0, i)); - } + DO_LOOP(m_tmp (0, i)); else - { - if (tmp_expr.is_real_matrix ()) - rhs = new tree_constant (m_tmp.extract (0, i, nr-1, i)); - else - rhs = new tree_constant (cm_tmp.extract (0, i, nr-1, i)); - } - - int quit = 0; - do_for_loop_once (rhs, quit); - if (quit) - break; + DO_LOOP(m_tmp.extract (0, i, nr-1, i)); + } + else + { + if (nr == 1) + DO_LOOP(cm_tmp (0, i)); + else + DO_LOOP(cm_tmp.extract (0, i, nr-1, i)); } } else if (tmp_expr.is_string ()) @@ -316,16 +397,35 @@ double b = rng.base (); double increment = rng.inc (); - for (int i = 0; i < steps; i++) + if (ident) { - double tmp_val = b + i * increment; + for (int i = 0; i < steps; i++) + { + double tmp_val = b + i * increment; + + tree_constant rhs (tmp_val); + + int quit = 0; + do_for_loop_once (ident, rhs, quit); - tree_constant *rhs = new tree_constant (tmp_val); + if (quit) + break; + } + } + else + { + for (int i = 0; i < steps; i++) + { + double tmp_val = b + i * increment; - int quit = 0; - do_for_loop_once (rhs, quit); - if (quit) - break; + tree_constant rhs (tmp_val); + + int quit = 0; + do_for_loop_once (rhs, quit); + + if (quit) + break; + } } } else @@ -344,35 +444,6 @@ } void -tree_for_command::do_for_loop_once (tree_constant *rhs, int& quit) -{ - quit = 0; - - tree_simple_assignment_expression tmp_ass (id, rhs, 1); - - tmp_ass.eval (0); - - if (error_state) - { - eval_error (); - return; - } - - if (list) - { - list->eval (1); - if (error_state) - { - eval_error (); - quit = 1; - return; - } - } - - quit = quit_loop_now (); -} - -void tree_for_command::print_code (ostream& os) { print_code_indent (os);