aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index af57b3d6c..ca14c1ba7 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4232,7 +4232,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4232 BcInstPtr ip; 4232 BcInstPtr ip;
4233 size_t *label; 4233 size_t *label;
4234 size_t cond_idx, exit_idx, body_idx, update_idx; 4234 size_t cond_idx, exit_idx, body_idx, update_idx;
4235 size_t n;
4236 4235
4237 dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t); 4236 dbg_lex("%s:%d p->l.t.t:%d", __func__, __LINE__, p->l.t.t);
4238 s = zbc_lex_next(&p->l); 4237 s = zbc_lex_next(&p->l);
@@ -4305,16 +4304,10 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4305 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "for"); 4304 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "for");
4306 if (s) RETURN_STATUS(s); 4305 if (s) RETURN_STATUS(s);
4307 4306
4308 n = *((size_t *) bc_vec_top(&p->conds));
4309 bc_parse_push(p, BC_INST_JUMP);
4310 bc_parse_pushIndex(p, n);
4311
4312 label = bc_vec_top(&p->conds);
4313
4314//TODO: commonalize? 4307//TODO: commonalize?
4315 dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label); 4308 dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, update_idx);
4316 bc_parse_push(p, BC_INST_JUMP); 4309 bc_parse_push(p, BC_INST_JUMP);
4317 bc_parse_pushIndex(p, *label); 4310 bc_parse_pushIndex(p, update_idx);
4318 4311
4319 label = bc_vec_item(&p->func->labels, ip.idx); 4312 label = bc_vec_item(&p->func->labels, ip.idx);
4320 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); 4313 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
@@ -4337,18 +4330,13 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type)
4337 if (type == BC_LEX_KEY_BREAK) { 4330 if (type == BC_LEX_KEY_BREAK) {
4338 BcInstPtr *ipp; 4331 BcInstPtr *ipp;
4339 4332
4340 i = p->exits.len; 4333 if (p->exits.len == 0) // none of the enclosing blocks is a loop
4341 for (;;) { 4334 RETURN_STATUS(bc_error_bad_token());
4342 if (i == 0) // none of the enclosing blocks is a loop 4335 ipp = bc_vec_top(&p->exits);
4343 RETURN_STATUS(bc_error_bad_token());
4344 ipp = bc_vec_item(&p->exits, --i);
4345 if (ipp->func != 0)
4346 break;
4347 }
4348 i = ipp->idx; 4336 i = ipp->idx;
4349 } 4337 } else {
4350 else
4351 i = *((size_t *) bc_vec_top(&p->conds)); 4338 i = *((size_t *) bc_vec_top(&p->conds));
4339 }
4352 4340
4353 bc_parse_push(p, BC_INST_JUMP); 4341 bc_parse_push(p, BC_INST_JUMP);
4354 bc_parse_pushIndex(p, i); 4342 bc_parse_pushIndex(p, i);