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>
diff --git a/miscutils/bc.c b/miscutils/bc.c
index d03d38a..8d2c270 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1171,6 +1171,8 @@
{
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 @@
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 @@
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 @@
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 @@
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);