bc: further conversions to "z" logic
function old new delta bc_program_exec 3876 - -3876 zbc_program_exec - 3963 +3963 bc_program_execStr 429 - -429 zbc_program_execStr - 427 +427 bc_vm_file 197 - -197 zbc_vm_file - 187 +187 bc_vm_process 74 - -74 zbc_vm_process - 61 +61 bc_parse_pushIndex 66 68 +2 bc_vm_run 624 618 -6 dc_main 187 176 -11 bc_program_reset 64 - -64 zbc_program_pushArray 111 - -111 ------------------------------------------------------------------------------ (add/remove: 4/6 grow/shrink: 1/2 up/down: 4640/-4768) Total: -128 bytes text data bss dec hex filename 980922 485 7296 988703 f161f busybox_old 980794 485 7296 988575 f159f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
c2da68e896
commit
d6ad3666dc
@ -6549,7 +6549,7 @@ static BC_STATUS zbc_program_nquit(void)
|
|||||||
# define zbc_program_nquit(...) (zbc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS)
|
# define zbc_program_nquit(...) (zbc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BcStatus bc_program_execStr(char *code, size_t *bgn,
|
static BC_STATUS zbc_program_execStr(char *code, size_t *bgn,
|
||||||
bool cond)
|
bool cond)
|
||||||
{
|
{
|
||||||
BcStatus s = BC_STATUS_SUCCESS;
|
BcStatus s = BC_STATUS_SUCCESS;
|
||||||
@ -6561,7 +6561,7 @@ static BcStatus bc_program_execStr(char *code, size_t *bgn,
|
|||||||
size_t fidx, sidx;
|
size_t fidx, sidx;
|
||||||
|
|
||||||
if (!BC_PROG_STACK(&G.prog.results, 1))
|
if (!BC_PROG_STACK(&G.prog.results, 1))
|
||||||
return bc_error_stack_has_too_few_elements();
|
RETURN_STATUS(bc_error_stack_has_too_few_elements());
|
||||||
|
|
||||||
r = bc_vec_top(&G.prog.results);
|
r = bc_vec_top(&G.prog.results);
|
||||||
|
|
||||||
@ -6639,7 +6639,7 @@ static BcStatus bc_program_execStr(char *code, size_t *bgn,
|
|||||||
bc_vec_pop(&G.prog.results);
|
bc_vec_pop(&G.prog.results);
|
||||||
bc_vec_push(&G.prog.stack, &ip);
|
bc_vec_push(&G.prog.stack, &ip);
|
||||||
|
|
||||||
return BC_STATUS_SUCCESS;
|
RETURN_STATUS(BC_STATUS_SUCCESS);
|
||||||
|
|
||||||
err:
|
err:
|
||||||
bc_parse_free(&prs);
|
bc_parse_free(&prs);
|
||||||
@ -6647,8 +6647,11 @@ err:
|
|||||||
bc_vec_pop_all(&f->code);
|
bc_vec_pop_all(&f->code);
|
||||||
exit:
|
exit:
|
||||||
bc_vec_pop(&G.prog.results);
|
bc_vec_pop(&G.prog.results);
|
||||||
return s;
|
RETURN_STATUS(s);
|
||||||
}
|
}
|
||||||
|
#if ERRORS_ARE_FATAL
|
||||||
|
# define zbc_program_execStr(...) (zbc_program_execStr(__VA_ARGS__), BC_STATUS_SUCCESS)
|
||||||
|
#endif
|
||||||
#endif // ENABLE_DC
|
#endif // ENABLE_DC
|
||||||
|
|
||||||
static void bc_program_pushGlobal(char inst)
|
static void bc_program_pushGlobal(char inst)
|
||||||
@ -6700,7 +6703,7 @@ static void bc_program_addFunc(char *name, size_t *idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static BcStatus bc_program_exec(void)
|
static BC_STATUS zbc_program_exec(void)
|
||||||
{
|
{
|
||||||
BcResult r, *ptr;
|
BcResult r, *ptr;
|
||||||
BcNum *num;
|
BcNum *num;
|
||||||
@ -6717,7 +6720,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
#if ENABLE_BC
|
#if ENABLE_BC
|
||||||
case BC_INST_JUMP_ZERO:
|
case BC_INST_JUMP_ZERO:
|
||||||
s = zbc_program_prep(&ptr, &num);
|
s = zbc_program_prep(&ptr, &num);
|
||||||
if (s) return s;
|
if (s) RETURN_STATUS(s);
|
||||||
cond = !bc_num_cmp(num, &G.prog.zero);
|
cond = !bc_num_cmp(num, &G.prog.zero);
|
||||||
bc_vec_pop(&G.prog.results);
|
bc_vec_pop(&G.prog.results);
|
||||||
// Fallthrough.
|
// Fallthrough.
|
||||||
@ -6813,7 +6816,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
break;
|
break;
|
||||||
case BC_INST_BOOL_NOT:
|
case BC_INST_BOOL_NOT:
|
||||||
s = zbc_program_prep(&ptr, &num);
|
s = zbc_program_prep(&ptr, &num);
|
||||||
if (s) return s;
|
if (s) RETURN_STATUS(s);
|
||||||
bc_num_init_DEF_SIZE(&r.d.n);
|
bc_num_init_DEF_SIZE(&r.d.n);
|
||||||
if (!bc_num_cmp(num, &G.prog.zero))
|
if (!bc_num_cmp(num, &G.prog.zero))
|
||||||
bc_num_one(&r.d.n);
|
bc_num_one(&r.d.n);
|
||||||
@ -6844,7 +6847,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
case BC_INST_EXECUTE:
|
case BC_INST_EXECUTE:
|
||||||
case BC_INST_EXEC_COND:
|
case BC_INST_EXEC_COND:
|
||||||
cond = inst == BC_INST_EXEC_COND;
|
cond = inst == BC_INST_EXEC_COND;
|
||||||
s = bc_program_execStr(code, &ip->idx, cond);
|
s = zbc_program_execStr(code, &ip->idx, cond);
|
||||||
break;
|
break;
|
||||||
case BC_INST_PRINT_STACK: {
|
case BC_INST_PRINT_STACK: {
|
||||||
size_t idx;
|
size_t idx;
|
||||||
@ -6862,7 +6865,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
break;
|
break;
|
||||||
case BC_INST_DUPLICATE:
|
case BC_INST_DUPLICATE:
|
||||||
if (!BC_PROG_STACK(&G.prog.results, 1))
|
if (!BC_PROG_STACK(&G.prog.results, 1))
|
||||||
return bc_error_stack_has_too_few_elements();
|
RETURN_STATUS(bc_error_stack_has_too_few_elements());
|
||||||
ptr = bc_vec_top(&G.prog.results);
|
ptr = bc_vec_top(&G.prog.results);
|
||||||
bc_result_copy(&r, ptr);
|
bc_result_copy(&r, ptr);
|
||||||
bc_vec_push(&G.prog.results, &r);
|
bc_vec_push(&G.prog.results, &r);
|
||||||
@ -6870,7 +6873,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
case BC_INST_SWAP: {
|
case BC_INST_SWAP: {
|
||||||
BcResult *ptr2;
|
BcResult *ptr2;
|
||||||
if (!BC_PROG_STACK(&G.prog.results, 2))
|
if (!BC_PROG_STACK(&G.prog.results, 2))
|
||||||
return bc_error_stack_has_too_few_elements();
|
RETURN_STATUS(bc_error_stack_has_too_few_elements());
|
||||||
ptr = bc_vec_item_rev(&G.prog.results, 0);
|
ptr = bc_vec_item_rev(&G.prog.results, 0);
|
||||||
ptr2 = bc_vec_item_rev(&G.prog.results, 1);
|
ptr2 = bc_vec_item_rev(&G.prog.results, 1);
|
||||||
memcpy(&r, ptr, sizeof(BcResult));
|
memcpy(&r, ptr, sizeof(BcResult));
|
||||||
@ -6909,7 +6912,7 @@ static BcStatus bc_program_exec(void)
|
|||||||
|
|
||||||
if (s || G_interrupt) {
|
if (s || G_interrupt) {
|
||||||
bc_program_reset();
|
bc_program_reset();
|
||||||
return s;
|
RETURN_STATUS(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the stack has changed, pointers may be invalid.
|
// If the stack has changed, pointers may be invalid.
|
||||||
@ -6918,8 +6921,11 @@ static BcStatus bc_program_exec(void)
|
|||||||
code = func->code.v;
|
code = func->code.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BC_STATUS_SUCCESS;
|
RETURN_STATUS(BC_STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
#if ERRORS_ARE_FATAL
|
||||||
|
# define zbc_program_exec(...) (zbc_program_exec(__VA_ARGS__), BC_STATUS_SUCCESS)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_BC
|
#if ENABLE_BC
|
||||||
static void bc_vm_info(void)
|
static void bc_vm_info(void)
|
||||||
@ -7009,28 +7015,31 @@ static unsigned bc_vm_envLen(const char *var)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BcStatus bc_vm_process(const char *text)
|
static BC_STATUS zbc_vm_process(const char *text)
|
||||||
{
|
{
|
||||||
BcStatus s = zbc_parse_text(&G.prs, text);
|
BcStatus s = zbc_parse_text(&G.prs, text);
|
||||||
|
|
||||||
if (s) return s;
|
if (s) RETURN_STATUS(s);
|
||||||
|
|
||||||
while (G.prs.l.t.t != BC_LEX_EOF) {
|
while (G.prs.l.t.t != BC_LEX_EOF) {
|
||||||
ERROR_RETURN(s =) G.prs.parse(&G.prs);
|
ERROR_RETURN(s =) G.prs.parse(&G.prs);
|
||||||
if (s) return s;
|
if (s) RETURN_STATUS(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BC_PARSE_CAN_EXEC(&G.prs)) {
|
if (BC_PARSE_CAN_EXEC(&G.prs)) {
|
||||||
s = bc_program_exec();
|
s = zbc_program_exec();
|
||||||
fflush_and_check();
|
fflush_and_check();
|
||||||
if (s)
|
if (s)
|
||||||
bc_program_reset();
|
bc_program_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
RETURN_STATUS(s);
|
||||||
}
|
}
|
||||||
|
#if ERRORS_ARE_FATAL
|
||||||
|
# define zbc_vm_process(...) (zbc_vm_process(__VA_ARGS__), BC_STATUS_SUCCESS)
|
||||||
|
#endif
|
||||||
|
|
||||||
static BcStatus bc_vm_file(const char *file)
|
static BC_STATUS zbc_vm_file(const char *file)
|
||||||
{
|
{
|
||||||
const char *sv_file;
|
const char *sv_file;
|
||||||
char *data;
|
char *data;
|
||||||
@ -7039,12 +7048,12 @@ static BcStatus bc_vm_file(const char *file)
|
|||||||
BcInstPtr *ip;
|
BcInstPtr *ip;
|
||||||
|
|
||||||
data = bc_read_file(file);
|
data = bc_read_file(file);
|
||||||
if (!data) return bc_error_fmt("file '%s' is not text", file);
|
if (!data) RETURN_STATUS(bc_error_fmt("file '%s' is not text", file));
|
||||||
|
|
||||||
sv_file = G.prog.file;
|
sv_file = G.prog.file;
|
||||||
G.prog.file = file;
|
G.prog.file = file;
|
||||||
bc_lex_file(&G.prs.l);
|
bc_lex_file(&G.prs.l);
|
||||||
s = bc_vm_process(data);
|
s = zbc_vm_process(data);
|
||||||
if (s) goto err;
|
if (s) goto err;
|
||||||
|
|
||||||
main_func = bc_program_func(BC_PROG_MAIN);
|
main_func = bc_program_func(BC_PROG_MAIN);
|
||||||
@ -7056,8 +7065,11 @@ static BcStatus bc_vm_file(const char *file)
|
|||||||
err:
|
err:
|
||||||
G.prog.file = sv_file;
|
G.prog.file = sv_file;
|
||||||
free(data);
|
free(data);
|
||||||
return s;
|
RETURN_STATUS(s);
|
||||||
}
|
}
|
||||||
|
#if ERRORS_ARE_FATAL
|
||||||
|
# define zbc_vm_file(...) (zbc_vm_file(__VA_ARGS__), BC_STATUS_SUCCESS)
|
||||||
|
#endif
|
||||||
|
|
||||||
static BcStatus bc_vm_stdin(void)
|
static BcStatus bc_vm_stdin(void)
|
||||||
{
|
{
|
||||||
@ -7120,7 +7132,7 @@ static BcStatus bc_vm_stdin(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bc_vec_concat(&buffer, buf.v);
|
bc_vec_concat(&buffer, buf.v);
|
||||||
s = bc_vm_process(buffer.v);
|
s = zbc_vm_process(buffer.v);
|
||||||
if (s) {
|
if (s) {
|
||||||
if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) {
|
if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) {
|
||||||
// Debug config, non-interactive mode:
|
// Debug config, non-interactive mode:
|
||||||
@ -7343,14 +7355,14 @@ static BcStatus bc_vm_exec(void)
|
|||||||
ERROR_RETURN(s =) G.prs.parse(&G.prs);
|
ERROR_RETURN(s =) G.prs.parse(&G.prs);
|
||||||
if (DEBUG_LIB && s) return s;
|
if (DEBUG_LIB && s) return s;
|
||||||
}
|
}
|
||||||
s = bc_program_exec();
|
s = zbc_program_exec();
|
||||||
if (DEBUG_LIB && s) return s;
|
if (DEBUG_LIB && s) return s;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s = BC_STATUS_SUCCESS;
|
s = BC_STATUS_SUCCESS;
|
||||||
for (i = 0; !s && i < G.files.len; ++i)
|
for (i = 0; !s && i < G.files.len; ++i)
|
||||||
s = bc_vm_file(*((char **) bc_vec_item(&G.files, i)));
|
s = zbc_vm_file(*((char **) bc_vec_item(&G.files, i)));
|
||||||
if (ENABLE_FEATURE_CLEAN_UP && s && !G_ttyin) {
|
if (ENABLE_FEATURE_CLEAN_UP && s && !G_ttyin) {
|
||||||
// Debug config, non-interactive mode:
|
// Debug config, non-interactive mode:
|
||||||
// return all the way back to main.
|
// return all the way back to main.
|
||||||
@ -7362,7 +7374,7 @@ static BcStatus bc_vm_exec(void)
|
|||||||
s = bc_vm_stdin();
|
s = bc_vm_stdin();
|
||||||
|
|
||||||
if (!s && !BC_PARSE_CAN_EXEC(&G.prs))
|
if (!s && !BC_PARSE_CAN_EXEC(&G.prs))
|
||||||
s = bc_vm_process("");
|
s = zbc_vm_process("");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -7560,12 +7572,13 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
switch (n) {
|
switch (n) {
|
||||||
case 'e':
|
case 'e':
|
||||||
noscript = 0;
|
noscript = 0;
|
||||||
n = bc_vm_process(optarg);
|
n = zbc_vm_process(optarg);
|
||||||
if (n) return n;
|
if (n) return n;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
noscript = 0;
|
noscript = 0;
|
||||||
bc_vm_file(optarg);
|
n = zbc_vm_file(optarg);
|
||||||
|
if (n) return n;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
option_mask32 |= DC_FLAG_X;
|
option_mask32 |= DC_FLAG_X;
|
||||||
|
Loading…
Reference in New Issue
Block a user