← Commit list

06ade7700

Denys Vlasenko
Denys Vlasenko
2018-12-16
SUCCESS Duration: 155s

Subject

bc: simplify use of "ip" in loop parsing functions

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

miscutils/bc.c+2 -6
@@ -4174,7 +4174,6 @@ static BC_STATUS zbc_parse_while(BcParse *p)
{
BcStatus s;
BcInstPtr ip;
- BcInstPtr *ipp;
size_t *label;
size_t n;
@@ -4214,14 +4213,13 @@ static BC_STATUS zbc_parse_while(BcParse *p)
bc_parse_push(p, BC_INST_JUMP);
bc_parse_pushIndex(p, n);
- ipp = bc_vec_top(&p->exits);
label = bc_vec_top(&p->conds);
dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label);
bc_parse_push(p, BC_INST_JUMP);
bc_parse_pushIndex(p, *label);
- label = bc_vec_item(&p->func->labels, ipp->idx);
+ label = bc_vec_item(&p->func->labels, ip.idx);
dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
*label = p->func->code.len;
@@ -4238,7 +4236,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
{
BcStatus s;
BcInstPtr ip;
- BcInstPtr *ipp;
size_t *label;
size_t cond_idx, exit_idx, body_idx, update_idx;
size_t n;
@@ -4318,7 +4315,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
bc_parse_push(p, BC_INST_JUMP);
bc_parse_pushIndex(p, n);
- ipp = bc_vec_top(&p->exits);
label = bc_vec_top(&p->conds);
//TODO: commonalize?
@@ -4326,7 +4322,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
bc_parse_push(p, BC_INST_JUMP);
bc_parse_pushIndex(p, *label);
- label = bc_vec_item(&p->func->labels, ipp->idx);
+ label = bc_vec_item(&p->func->labels, ip.idx);
dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
*label = p->func->code.len;
testsuite/bc.tests+31 -0
@@ -76,6 +76,37 @@ testing "bc print 1,2,3" \
"123" \
"" "print 1,2,3"
+testing "bc nested loops and breaks" \
+ "bc" \
+ "\
+11
+21
+31
+22
+12
+99
+" \
+ "" "\
+if(1) {
+ 11
+ while(1) {
+ 21
+ while(1) {
+ 31
+ break
+ 32
+ }
+ 22
+ break
+ 23
+ }
+ 12
+} else {
+ 88
+}
+99
+"
+
tar xJf bc_large.tar.xz
for f in bc*.bc; do