aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 22:44:51 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 22:44:51 +0100
commit06ade77002eaa28bb3f19480f68ad270b22bd48e (patch)
tree257712440df650debf886de5b614c81b6e3af08b
parent146a79d19c19465aa5a29c271341158b46cc5ade (diff)
downloadbusybox-w32-06ade77002eaa28bb3f19480f68ad270b22bd48e.tar.gz
busybox-w32-06ade77002eaa28bb3f19480f68ad270b22bd48e.tar.bz2
busybox-w32-06ade77002eaa28bb3f19480f68ad270b22bd48e.zip
bc: simplify use of "ip" in loop parsing functions
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>
-rw-r--r--miscutils/bc.c8
-rwxr-xr-xtestsuite/bc.tests31
2 files changed, 33 insertions, 6 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index f85ab1aea..925950d78 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4174,7 +4174,6 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4174{ 4174{
4175 BcStatus s; 4175 BcStatus s;
4176 BcInstPtr ip; 4176 BcInstPtr ip;
4177 BcInstPtr *ipp;
4178 size_t *label; 4177 size_t *label;
4179 size_t n; 4178 size_t n;
4180 4179
@@ -4214,14 +4213,13 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4214 bc_parse_push(p, BC_INST_JUMP); 4213 bc_parse_push(p, BC_INST_JUMP);
4215 bc_parse_pushIndex(p, n); 4214 bc_parse_pushIndex(p, n);
4216 4215
4217 ipp = bc_vec_top(&p->exits);
4218 label = bc_vec_top(&p->conds); 4216 label = bc_vec_top(&p->conds);
4219 4217
4220 dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label); 4218 dbg_lex("%s:%d BC_INST_JUMP to %d", __func__, __LINE__, *label);
4221 bc_parse_push(p, BC_INST_JUMP); 4219 bc_parse_push(p, BC_INST_JUMP);
4222 bc_parse_pushIndex(p, *label); 4220 bc_parse_pushIndex(p, *label);
4223 4221
4224 label = bc_vec_item(&p->func->labels, ipp->idx); 4222 label = bc_vec_item(&p->func->labels, ip.idx);
4225 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); 4223 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
4226 *label = p->func->code.len; 4224 *label = p->func->code.len;
4227 4225
@@ -4238,7 +4236,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4238{ 4236{
4239 BcStatus s; 4237 BcStatus s;
4240 BcInstPtr ip; 4238 BcInstPtr ip;
4241 BcInstPtr *ipp;
4242 size_t *label; 4239 size_t *label;
4243 size_t cond_idx, exit_idx, body_idx, update_idx; 4240 size_t cond_idx, exit_idx, body_idx, update_idx;
4244 size_t n; 4241 size_t n;
@@ -4318,7 +4315,6 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4318 bc_parse_push(p, BC_INST_JUMP); 4315 bc_parse_push(p, BC_INST_JUMP);
4319 bc_parse_pushIndex(p, n); 4316 bc_parse_pushIndex(p, n);
4320 4317
4321 ipp = bc_vec_top(&p->exits);
4322 label = bc_vec_top(&p->conds); 4318 label = bc_vec_top(&p->conds);
4323 4319
4324//TODO: commonalize? 4320//TODO: commonalize?
@@ -4326,7 +4322,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4326 bc_parse_push(p, BC_INST_JUMP); 4322 bc_parse_push(p, BC_INST_JUMP);
4327 bc_parse_pushIndex(p, *label); 4323 bc_parse_pushIndex(p, *label);
4328 4324
4329 label = bc_vec_item(&p->func->labels, ipp->idx); 4325 label = bc_vec_item(&p->func->labels, ip.idx);
4330 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); 4326 dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len);
4331 *label = p->func->code.len; 4327 *label = p->func->code.len;
4332 4328
diff --git a/testsuite/bc.tests b/testsuite/bc.tests
index 21b26008f..987461ebb 100755
--- a/testsuite/bc.tests
+++ b/testsuite/bc.tests
@@ -76,6 +76,37 @@ testing "bc print 1,2,3" \
76 "123" \ 76 "123" \
77 "" "print 1,2,3" 77 "" "print 1,2,3"
78 78
79testing "bc nested loops and breaks" \
80 "bc" \
81 "\
8211
8321
8431
8522
8612
8799
88" \
89 "" "\
90if(1) {
91 11
92 while(1) {
93 21
94 while(1) {
95 31
96 break
97 32
98 }
99 22
100 break
101 23
102 }
103 12
104} else {
105 88
106}
10799
108"
109
79tar xJf bc_large.tar.xz 110tar xJf bc_large.tar.xz
80 111
81for f in bc*.bc; do 112for f in bc*.bc; do