aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 979d5113d..56a2bca71 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4173,9 +4173,9 @@ static BC_STATUS zbc_parse_if(BcParse *p)
4173static BC_STATUS zbc_parse_while(BcParse *p) 4173static BC_STATUS zbc_parse_while(BcParse *p)
4174{ 4174{
4175 BcStatus s; 4175 BcStatus s;
4176 BcInstPtr ip;
4177 size_t *label; 4176 size_t *label;
4178 size_t cond_idx; 4177 size_t cond_idx;
4178 size_t ip_idx;
4179 4179
4180 s = zbc_lex_next(&p->l); 4180 s = zbc_lex_next(&p->l);
4181 if (s) RETURN_STATUS(s); 4181 if (s) RETURN_STATUS(s);
@@ -4184,16 +4184,13 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4184 if (s) RETURN_STATUS(s); 4184 if (s) RETURN_STATUS(s);
4185 4185
4186 cond_idx = p->func->labels.len; 4186 cond_idx = p->func->labels.len;
4187 ip_idx = cond_idx + 1;
4187 4188
4188 bc_vec_push(&p->func->labels, &p->func->code.len); 4189 bc_vec_push(&p->func->labels, &p->func->code.len);
4189 bc_vec_push(&p->conds, &cond_idx); 4190 bc_vec_push(&p->conds, &cond_idx);
4190 4191
4191 ip.idx = p->func->labels.len; 4192 bc_vec_push(&p->exits, &ip_idx);
4192 ip.func = 1; 4193 bc_vec_push(&p->func->labels, &ip_idx);
4193 ip.len = 0;
4194
4195 bc_vec_push(&p->exits, &ip.idx);
4196 bc_vec_push(&p->func->labels, &ip.idx);
4197 4194
4198 s = zbc_parse_expr(p, BC_PARSE_REL, bc_parse_next_rel); 4195 s = zbc_parse_expr(p, BC_PARSE_REL, bc_parse_next_rel);
4199 if (s) RETURN_STATUS(s); 4196 if (s) RETURN_STATUS(s);
@@ -4204,7 +4201,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4204 if (s) RETURN_STATUS(s); 4201 if (s) RETURN_STATUS(s);
4205 4202
4206 bc_parse_push(p, BC_INST_JUMP_ZERO); 4203 bc_parse_push(p, BC_INST_JUMP_ZERO);
4207 bc_parse_pushIndex(p, ip.idx); 4204 bc_parse_pushIndex(p, ip_idx);
4208 4205
4209 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while"); 4206 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while");
4210 if (s) RETURN_STATUS(s); 4207 if (s) RETURN_STATUS(s);
@@ -4213,7 +4210,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4213 bc_parse_push(p, BC_INST_JUMP); 4210 bc_parse_push(p, BC_INST_JUMP);
4214 bc_parse_pushIndex(p, cond_idx); 4211 bc_parse_pushIndex(p, cond_idx);
4215 4212
4216 label = bc_vec_item(&p->func->labels, ip.idx); 4213 label = bc_vec_item(&p->func->labels, ip_idx);
4217 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); 4214 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
4218 *label = p->func->code.len; 4215 *label = p->func->code.len;
4219 4216
@@ -4229,7 +4226,6 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4229static BC_STATUS zbc_parse_for(BcParse *p) 4226static BC_STATUS zbc_parse_for(BcParse *p)
4230{ 4227{
4231 BcStatus s; 4228 BcStatus s;
4232 BcInstPtr ip;
4233 size_t *label; 4229 size_t *label;
4234 size_t cond_idx, exit_idx, body_idx, update_idx; 4230 size_t cond_idx, exit_idx, body_idx, update_idx;
4235 4231
@@ -4273,8 +4269,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4273 bc_parse_push(p, BC_INST_JUMP); 4269 bc_parse_push(p, BC_INST_JUMP);
4274 bc_parse_pushIndex(p, body_idx); 4270 bc_parse_pushIndex(p, body_idx);
4275 4271
4276 ip.idx = p->func->labels.len;
4277
4278 bc_vec_push(&p->conds, &update_idx); 4272 bc_vec_push(&p->conds, &update_idx);
4279 bc_vec_push(&p->func->labels, &p->func->code.len); 4273 bc_vec_push(&p->func->labels, &p->func->code.len);
4280 4274
@@ -4290,12 +4284,8 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4290 bc_parse_pushIndex(p, cond_idx); 4284 bc_parse_pushIndex(p, cond_idx);
4291 bc_vec_push(&p->func->labels, &p->func->code.len); 4285 bc_vec_push(&p->func->labels, &p->func->code.len);
4292 4286
4293 ip.idx = exit_idx; 4287 bc_vec_push(&p->exits, &exit_idx);
4294 ip.func = 1; 4288 bc_vec_push(&p->func->labels, &exit_idx);
4295 ip.len = 0;
4296
4297 bc_vec_push(&p->exits, &ip.idx);
4298 bc_vec_push(&p->func->labels, &ip.idx);
4299 4289
4300 // for(...)<newline>stmt is accepted as well 4290 // for(...)<newline>stmt is accepted as well
4301 s = zbc_lex_next_and_skip_NLINE(&p->l); 4291 s = zbc_lex_next_and_skip_NLINE(&p->l);
@@ -4309,7 +4299,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4309 bc_parse_push(p, BC_INST_JUMP); 4299 bc_parse_push(p, BC_INST_JUMP);
4310 bc_parse_pushIndex(p, update_idx); 4300 bc_parse_pushIndex(p, update_idx);
4311 4301
4312 label = bc_vec_item(&p->func->labels, ip.idx); 4302 label = bc_vec_item(&p->func->labels, exit_idx);
4313 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); 4303 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
4314 *label = p->func->code.len; 4304 *label = p->func->code.len;
4315 4305