[git commit] bc: open-code bc_parse_updateFunc() macro

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 19 14:13:14 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=65e1046abf28a3b73e56e6b17ae936e7b2f314c3
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

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 at googlemail.com>
---
 miscutils/bc.c | 16 ++++++++++------
 1 file 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)
 {
 	return bc_vec_item(&G.prog.fns, idx);
 }
+// BC_PROG_MAIN is zeroth element, so:
+#define bc_program_func_BC_PROG_MAIN() ((BcFunc*)(G.prog.fns.v))
 
 static void *bc_vec_item_rev(const BcVec *v, size_t idx)
 {
@@ -3538,9 +3540,6 @@ static void bc_program_reset(void)
 	ip->idx = f->code.len;
 }
 
-#define bc_parse_updateFunc(p, f) \
-	((p)->func = bc_program_func((p)->fidx = (f)))
-
 // Called when zbc/zdc_parse_parse() detects a failure,
 // resets parsing structures.
 static void bc_parse_reset(BcParse *p)
@@ -3551,7 +3550,8 @@ static void bc_parse_reset(BcParse *p)
 		bc_vec_pop_all(&p->func->autos);
 		bc_vec_pop_all(&p->func->labels);
 
-		bc_parse_updateFunc(p, BC_PROG_MAIN);
+		p->fidx = BC_PROG_MAIN;
+		p->func = bc_program_func_BC_PROG_MAIN();
 	}
 
 	p->l.i = p->l.len;
@@ -3581,7 +3581,8 @@ static void bc_parse_create(BcParse *p, size_t func)
 	bc_vec_init(&p->conds, sizeof(size_t), NULL);
 	bc_vec_init(&p->ops, sizeof(BcLexType), NULL);
 
-	bc_parse_updateFunc(p, func);
+	p->fidx = func;
+	p->func = bc_program_func(func);
 }
 
 #if ENABLE_BC
@@ -4339,7 +4340,10 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
 	if (s) RETURN_STATUS(s);
 
 	bc_parse_push(p, BC_INST_RET0);
-	bc_parse_updateFunc(p, BC_PROG_MAIN);
+
+	// Subsequent code generation is into main program
+	p->fidx = BC_PROG_MAIN;
+	p->func = bc_program_func_BC_PROG_MAIN();
 
 	dbg_lex_done("%s:%d done", __func__, __LINE__);
 	RETURN_STATUS(s);


More information about the busybox-cvs mailing list