bc: simplify use of "ip" in loop parsing functions
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Dec 2018 21:44:51 +0000 (22:44 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 16 Dec 2018 21:44:51 +0000 (22:44 +0100)
function                                             old     new   delta
zbc_parse_stmt_possibly_auto                        2106    2065     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-41)             Total: -41 bytes
   text    data     bss     dec     hex filename
 982076     485    7296  989857   f1aa1 busybox_old
 982035     485    7296  989816   f1a78 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c
testsuite/bc.tests

index f85ab1aeac5850e0de2c782c67c6125e5df3cbe4..925950d78db5e0a668fdbf785c9b2eeb401d6f7a 100644 (file)
@@ -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;
 
index 21b26008f0cddcea269bbdde0146eb560f63688d..987461ebbc84ea6d82ed2b0baca1aa77c0bf2848 100755 (executable)
@@ -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