diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 15:13:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-19 15:13:14 +0100 |
commit | 65e1046abf28a3b73e56e6b17ae936e7b2f314c3 (patch) | |
tree | 0a4a2e89b4d12830cfaf0bf7de89cd139d9b60d7 | |
parent | 684d441f5c8c4eac5962ad0e0b59e8999284fe6a (diff) | |
download | busybox-w32-65e1046abf28a3b73e56e6b17ae936e7b2f314c3.tar.gz busybox-w32-65e1046abf28a3b73e56e6b17ae936e7b2f314c3.tar.bz2 busybox-w32-65e1046abf28a3b73e56e6b17ae936e7b2f314c3.zip |
bc: open-code bc_parse_updateFunc() macro
This clearly shows one place which would need changing
for nested funcdefs to work.
function old new delta
bc_parse_reset 106 110 +4
zbc_vm_process 586 585 -1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-1) Total: 3 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index d03d38aa9..8d2c2705b 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1171,6 +1171,8 @@ static BcFunc* bc_program_func(size_t idx) | |||
1171 | { | 1171 | { |
1172 | return bc_vec_item(&G.prog.fns, idx); | 1172 | return bc_vec_item(&G.prog.fns, idx); |
1173 | } | 1173 | } |
1174 | // BC_PROG_MAIN is zeroth element, so: | ||
1175 | #define bc_program_func_BC_PROG_MAIN() ((BcFunc*)(G.prog.fns.v)) | ||
1174 | 1176 | ||
1175 | static void *bc_vec_item_rev(const BcVec *v, size_t idx) | 1177 | static void *bc_vec_item_rev(const BcVec *v, size_t idx) |
1176 | { | 1178 | { |
@@ -3538,9 +3540,6 @@ static void bc_program_reset(void) | |||
3538 | ip->idx = f->code.len; | 3540 | ip->idx = f->code.len; |
3539 | } | 3541 | } |
3540 | 3542 | ||
3541 | #define bc_parse_updateFunc(p, f) \ | ||
3542 | ((p)->func = bc_program_func((p)->fidx = (f))) | ||
3543 | |||
3544 | // Called when zbc/zdc_parse_parse() detects a failure, | 3543 | // Called when zbc/zdc_parse_parse() detects a failure, |
3545 | // resets parsing structures. | 3544 | // resets parsing structures. |
3546 | static void bc_parse_reset(BcParse *p) | 3545 | static void bc_parse_reset(BcParse *p) |
@@ -3551,7 +3550,8 @@ static void bc_parse_reset(BcParse *p) | |||
3551 | bc_vec_pop_all(&p->func->autos); | 3550 | bc_vec_pop_all(&p->func->autos); |
3552 | bc_vec_pop_all(&p->func->labels); | 3551 | bc_vec_pop_all(&p->func->labels); |
3553 | 3552 | ||
3554 | bc_parse_updateFunc(p, BC_PROG_MAIN); | 3553 | p->fidx = BC_PROG_MAIN; |
3554 | p->func = bc_program_func_BC_PROG_MAIN(); | ||
3555 | } | 3555 | } |
3556 | 3556 | ||
3557 | p->l.i = p->l.len; | 3557 | p->l.i = p->l.len; |
@@ -3581,7 +3581,8 @@ static void bc_parse_create(BcParse *p, size_t func) | |||
3581 | bc_vec_init(&p->conds, sizeof(size_t), NULL); | 3581 | bc_vec_init(&p->conds, sizeof(size_t), NULL); |
3582 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); | 3582 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); |
3583 | 3583 | ||
3584 | bc_parse_updateFunc(p, func); | 3584 | p->fidx = func; |
3585 | p->func = bc_program_func(func); | ||
3585 | } | 3586 | } |
3586 | 3587 | ||
3587 | #if ENABLE_BC | 3588 | #if ENABLE_BC |
@@ -4339,7 +4340,10 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p) | |||
4339 | if (s) RETURN_STATUS(s); | 4340 | if (s) RETURN_STATUS(s); |
4340 | 4341 | ||
4341 | bc_parse_push(p, BC_INST_RET0); | 4342 | bc_parse_push(p, BC_INST_RET0); |
4342 | bc_parse_updateFunc(p, BC_PROG_MAIN); | 4343 | |
4344 | // Subsequent code generation is into main program | ||
4345 | p->fidx = BC_PROG_MAIN; | ||
4346 | p->func = bc_program_func_BC_PROG_MAIN(); | ||
4343 | 4347 | ||
4344 | dbg_lex_done("%s:%d done", __func__, __LINE__); | 4348 | dbg_lex_done("%s:%d done", __func__, __LINE__); |
4345 | RETURN_STATUS(s); | 4349 | RETURN_STATUS(s); |