Mercurial > hg > octave-nkf
diff src/pt-loop.cc @ 3877:55648fc616c8
[project @ 2002-03-07 23:00:09 by jwe]
author | jwe |
---|---|
date | Thu, 07 Mar 2002 23:00:10 +0000 |
parents | bf6116ca10eb |
children | edd758a7ca8d |
line wrap: on
line diff
--- a/src/pt-loop.cc +++ b/src/pt-loop.cc @@ -41,6 +41,10 @@ #include "pt-loop.h" #include "pt-stmt.h" #include "pt-walk.h" +#include "unwind-prot.h" + +// TRUE means we are evaluating some kind of looping construct. +bool evaluating_looping_command = false; // Decide if it's time to quit a for or while loop. static inline bool @@ -78,6 +82,12 @@ if (error_state) return; + unwind_protect::begin_frame ("while_command::eval"); + + unwind_protect_bool (evaluating_looping_command); + + evaluating_looping_command = true; + if (! expr) panic_impossible (); @@ -92,7 +102,7 @@ if (error_state) { eval_error (); - return; + goto cleanup; } } @@ -102,6 +112,9 @@ else break; } + + cleanup: + unwind_protect::run_frame ("while_command::eval"); } void @@ -126,6 +139,12 @@ if (error_state) return; + unwind_protect::begin_frame ("do_until_command::eval"); + + unwind_protect_bool (evaluating_looping_command); + + evaluating_looping_command = true; + if (! expr) panic_impossible (); @@ -140,13 +159,16 @@ if (error_state) { eval_error (); - return; + goto cleanup; } } if (quit_loop_now () || expr->is_logically_true ("do-until")) break; } + + cleanup: + unwind_protect::run_frame ("do_until_command::eval"); } void @@ -223,144 +245,155 @@ if (error_state) return; + unwind_protect::begin_frame ("simple_for_command::eval"); + + unwind_protect_bool (evaluating_looping_command); + + evaluating_looping_command = true; + octave_value rhs = expr->rvalue (); if (error_state || rhs.is_undefined ()) { eval_error (); - return; - } - - octave_lvalue ult = lhs->lvalue (); - - if (error_state) - { - eval_error (); - return; + goto cleanup; } - if (rhs.is_range ()) - { - Range rng = rhs.range_value (); + { + octave_lvalue ult = lhs->lvalue (); - int steps = rng.nelem (); - double b = rng.base (); - double increment = rng.inc (); + if (error_state) + { + eval_error (); + goto cleanup; + } + + if (rhs.is_range ()) + { + Range rng = rhs.range_value (); - for (int i = 0; i < steps; i++) - { - MAYBE_DO_BREAKPOINT; + int steps = rng.nelem (); + double b = rng.base (); + double increment = rng.inc (); - double tmp_val = b + i * increment; + for (int i = 0; i < steps; i++) + { + MAYBE_DO_BREAKPOINT; - octave_value val (tmp_val); + double tmp_val = b + i * increment; + + octave_value val (tmp_val); - bool quit = false; + bool quit = false; - do_for_loop_once (ult, val, quit); + do_for_loop_once (ult, val, quit); - if (quit) - break; - } - } - else if (rhs.is_scalar_type ()) - { - bool quit = false; - - MAYBE_DO_BREAKPOINT; + if (quit) + break; + } + } + else if (rhs.is_scalar_type ()) + { + bool quit = false; + + MAYBE_DO_BREAKPOINT; - do_for_loop_once (ult, rhs, quit); - } - else if (rhs.is_string ()) - { - charMatrix chm_tmp = rhs.char_matrix_value (); - int nr = chm_tmp.rows (); - int steps = chm_tmp.columns (); + do_for_loop_once (ult, rhs, quit); + } + else if (rhs.is_string ()) + { + charMatrix chm_tmp = rhs.char_matrix_value (); + int nr = chm_tmp.rows (); + int steps = chm_tmp.columns (); - if (error_state) - return; + if (error_state) + goto cleanup; - if (nr == 1) - DO_LOOP (chm_tmp (0, i)); - else - { - for (int i = 0; i < steps; i++) - { - MAYBE_DO_BREAKPOINT; + if (nr == 1) + DO_LOOP (chm_tmp (0, i)); + else + { + for (int i = 0; i < steps; i++) + { + MAYBE_DO_BREAKPOINT; - octave_value val (chm_tmp.extract (0, i, nr-1, i), true); + octave_value val (chm_tmp.extract (0, i, nr-1, i), true); - bool quit = false; + bool quit = false; - do_for_loop_once (ult, val, quit); + do_for_loop_once (ult, val, quit); - if (quit) - break; - } - } - } - else if (rhs.is_matrix_type ()) - { - Matrix m_tmp; - ComplexMatrix cm_tmp; + if (quit) + break; + } + } + } + else if (rhs.is_matrix_type ()) + { + Matrix m_tmp; + ComplexMatrix cm_tmp; - int nr; - int steps; + int nr; + int steps; - if (rhs.is_real_matrix ()) - { - m_tmp = rhs.matrix_value (); - nr = m_tmp.rows (); - steps = m_tmp.columns (); - } - else - { - cm_tmp = rhs.complex_matrix_value (); - nr = cm_tmp.rows (); - steps = cm_tmp.columns (); - } + if (rhs.is_real_matrix ()) + { + m_tmp = rhs.matrix_value (); + nr = m_tmp.rows (); + steps = m_tmp.columns (); + } + else + { + cm_tmp = rhs.complex_matrix_value (); + nr = cm_tmp.rows (); + steps = cm_tmp.columns (); + } - if (error_state) - return; + if (error_state) + goto cleanup; - if (rhs.is_real_matrix ()) - { - if (nr == 1) - DO_LOOP (m_tmp (0, i)); - else - 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 (rhs.is_map ()) - { - Octave_map tmp_val (rhs.map_value ()); + if (rhs.is_real_matrix ()) + { + if (nr == 1) + DO_LOOP (m_tmp (0, i)); + else + 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 (rhs.is_map ()) + { + Octave_map tmp_val (rhs.map_value ()); - for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) - { - MAYBE_DO_BREAKPOINT; + for (Pix p = tmp_val.first (); p != 0; tmp_val.next (p)) + { + MAYBE_DO_BREAKPOINT; - octave_value val = tmp_val.contents (p); + octave_value val = tmp_val.contents (p); - bool quit = false; + bool quit = false; - do_for_loop_once (ult, val, quit); + do_for_loop_once (ult, val, quit); - if (quit) - break; - } - } - else - { - ::error ("invalid type in for loop expression near line %d, column %d", - line (), column ()); - } + if (quit) + break; + } + } + else + { + ::error ("invalid type in for loop expression near line %d, column %d", + line (), column ()); + } + } + + cleanup: + unwind_protect::run_frame ("simple_for_command::eval"); } void @@ -419,12 +452,18 @@ if (error_state) return; + unwind_protect::begin_frame ("complex_for_command::eval"); + + unwind_protect_bool (evaluating_looping_command); + + evaluating_looping_command = true; + octave_value rhs = expr->rvalue (); if (error_state || rhs.is_undefined ()) { eval_error (); - return; + goto cleanup; } if (rhs.is_map ()) @@ -460,6 +499,9 @@ } else error ("in statement `for [X, Y] = VAL', VAL must be a structure"); + + cleanup: + unwind_protect::run_frame ("complex_for_command::eval"); } void