diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 21:39:10 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 21:39:10 +0100 |
commit | d6ad3666dc51f475a6e76b07f2c59d039f69f2d4 (patch) | |
tree | acfa48d7a51552414342c7c4ab36742bed59939c | |
parent | c2da68e896d4253466bed202e71bae7b9b2aeec9 (diff) | |
download | busybox-w32-d6ad3666dc51f475a6e76b07f2c59d039f69f2d4.tar.gz busybox-w32-d6ad3666dc51f475a6e76b07f2c59d039f69f2d4.tar.bz2 busybox-w32-d6ad3666dc51f475a6e76b07f2c59d039f69f2d4.zip |
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>
-rw-r--r-- | miscutils/bc.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index dc8e5c761..3d26c39a7 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -6549,7 +6549,7 @@ static BC_STATUS zbc_program_nquit(void) | |||
6549 | # define zbc_program_nquit(...) (zbc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS) | 6549 | # define zbc_program_nquit(...) (zbc_program_nquit(__VA_ARGS__), BC_STATUS_SUCCESS) |
6550 | #endif | 6550 | #endif |
6551 | 6551 | ||
6552 | static BcStatus bc_program_execStr(char *code, size_t *bgn, | 6552 | static BC_STATUS zbc_program_execStr(char *code, size_t *bgn, |
6553 | bool cond) | 6553 | bool cond) |
6554 | { | 6554 | { |
6555 | BcStatus s = BC_STATUS_SUCCESS; | 6555 | BcStatus s = BC_STATUS_SUCCESS; |
@@ -6561,7 +6561,7 @@ static BcStatus bc_program_execStr(char *code, size_t *bgn, | |||
6561 | size_t fidx, sidx; | 6561 | size_t fidx, sidx; |
6562 | 6562 | ||
6563 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6563 | if (!BC_PROG_STACK(&G.prog.results, 1)) |
6564 | return bc_error_stack_has_too_few_elements(); | 6564 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6565 | 6565 | ||
6566 | r = bc_vec_top(&G.prog.results); | 6566 | r = bc_vec_top(&G.prog.results); |
6567 | 6567 | ||
@@ -6639,7 +6639,7 @@ static BcStatus bc_program_execStr(char *code, size_t *bgn, | |||
6639 | bc_vec_pop(&G.prog.results); | 6639 | bc_vec_pop(&G.prog.results); |
6640 | bc_vec_push(&G.prog.stack, &ip); | 6640 | bc_vec_push(&G.prog.stack, &ip); |
6641 | 6641 | ||
6642 | return BC_STATUS_SUCCESS; | 6642 | RETURN_STATUS(BC_STATUS_SUCCESS); |
6643 | 6643 | ||
6644 | err: | 6644 | err: |
6645 | bc_parse_free(&prs); | 6645 | bc_parse_free(&prs); |
@@ -6647,8 +6647,11 @@ err: | |||
6647 | bc_vec_pop_all(&f->code); | 6647 | bc_vec_pop_all(&f->code); |
6648 | exit: | 6648 | exit: |
6649 | bc_vec_pop(&G.prog.results); | 6649 | bc_vec_pop(&G.prog.results); |
6650 | return s; | 6650 | RETURN_STATUS(s); |
6651 | } | 6651 | } |
6652 | #if ERRORS_ARE_FATAL | ||
6653 | # define zbc_program_execStr(...) (zbc_program_execStr(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
6654 | #endif | ||
6652 | #endif // ENABLE_DC | 6655 | #endif // ENABLE_DC |
6653 | 6656 | ||
6654 | static void bc_program_pushGlobal(char inst) | 6657 | static void bc_program_pushGlobal(char inst) |
@@ -6700,7 +6703,7 @@ static void bc_program_addFunc(char *name, size_t *idx) | |||
6700 | } | 6703 | } |
6701 | } | 6704 | } |
6702 | 6705 | ||
6703 | static BcStatus bc_program_exec(void) | 6706 | static BC_STATUS zbc_program_exec(void) |
6704 | { | 6707 | { |
6705 | BcResult r, *ptr; | 6708 | BcResult r, *ptr; |
6706 | BcNum *num; | 6709 | BcNum *num; |
@@ -6717,7 +6720,7 @@ static BcStatus bc_program_exec(void) | |||
6717 | #if ENABLE_BC | 6720 | #if ENABLE_BC |
6718 | case BC_INST_JUMP_ZERO: | 6721 | case BC_INST_JUMP_ZERO: |
6719 | s = zbc_program_prep(&ptr, &num); | 6722 | s = zbc_program_prep(&ptr, &num); |
6720 | if (s) return s; | 6723 | if (s) RETURN_STATUS(s); |
6721 | cond = !bc_num_cmp(num, &G.prog.zero); | 6724 | cond = !bc_num_cmp(num, &G.prog.zero); |
6722 | bc_vec_pop(&G.prog.results); | 6725 | bc_vec_pop(&G.prog.results); |
6723 | // Fallthrough. | 6726 | // Fallthrough. |
@@ -6813,7 +6816,7 @@ static BcStatus bc_program_exec(void) | |||
6813 | break; | 6816 | break; |
6814 | case BC_INST_BOOL_NOT: | 6817 | case BC_INST_BOOL_NOT: |
6815 | s = zbc_program_prep(&ptr, &num); | 6818 | s = zbc_program_prep(&ptr, &num); |
6816 | if (s) return s; | 6819 | if (s) RETURN_STATUS(s); |
6817 | bc_num_init_DEF_SIZE(&r.d.n); | 6820 | bc_num_init_DEF_SIZE(&r.d.n); |
6818 | if (!bc_num_cmp(num, &G.prog.zero)) | 6821 | if (!bc_num_cmp(num, &G.prog.zero)) |
6819 | bc_num_one(&r.d.n); | 6822 | bc_num_one(&r.d.n); |
@@ -6844,7 +6847,7 @@ static BcStatus bc_program_exec(void) | |||
6844 | case BC_INST_EXECUTE: | 6847 | case BC_INST_EXECUTE: |
6845 | case BC_INST_EXEC_COND: | 6848 | case BC_INST_EXEC_COND: |
6846 | cond = inst == BC_INST_EXEC_COND; | 6849 | cond = inst == BC_INST_EXEC_COND; |
6847 | s = bc_program_execStr(code, &ip->idx, cond); | 6850 | s = zbc_program_execStr(code, &ip->idx, cond); |
6848 | break; | 6851 | break; |
6849 | case BC_INST_PRINT_STACK: { | 6852 | case BC_INST_PRINT_STACK: { |
6850 | size_t idx; | 6853 | size_t idx; |
@@ -6862,7 +6865,7 @@ static BcStatus bc_program_exec(void) | |||
6862 | break; | 6865 | break; |
6863 | case BC_INST_DUPLICATE: | 6866 | case BC_INST_DUPLICATE: |
6864 | if (!BC_PROG_STACK(&G.prog.results, 1)) | 6867 | if (!BC_PROG_STACK(&G.prog.results, 1)) |
6865 | return bc_error_stack_has_too_few_elements(); | 6868 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6866 | ptr = bc_vec_top(&G.prog.results); | 6869 | ptr = bc_vec_top(&G.prog.results); |
6867 | bc_result_copy(&r, ptr); | 6870 | bc_result_copy(&r, ptr); |
6868 | bc_vec_push(&G.prog.results, &r); | 6871 | bc_vec_push(&G.prog.results, &r); |
@@ -6870,7 +6873,7 @@ static BcStatus bc_program_exec(void) | |||
6870 | case BC_INST_SWAP: { | 6873 | case BC_INST_SWAP: { |
6871 | BcResult *ptr2; | 6874 | BcResult *ptr2; |
6872 | if (!BC_PROG_STACK(&G.prog.results, 2)) | 6875 | if (!BC_PROG_STACK(&G.prog.results, 2)) |
6873 | return bc_error_stack_has_too_few_elements(); | 6876 | RETURN_STATUS(bc_error_stack_has_too_few_elements()); |
6874 | ptr = bc_vec_item_rev(&G.prog.results, 0); | 6877 | ptr = bc_vec_item_rev(&G.prog.results, 0); |
6875 | ptr2 = bc_vec_item_rev(&G.prog.results, 1); | 6878 | ptr2 = bc_vec_item_rev(&G.prog.results, 1); |
6876 | memcpy(&r, ptr, sizeof(BcResult)); | 6879 | memcpy(&r, ptr, sizeof(BcResult)); |
@@ -6909,7 +6912,7 @@ static BcStatus bc_program_exec(void) | |||
6909 | 6912 | ||
6910 | if (s || G_interrupt) { | 6913 | if (s || G_interrupt) { |
6911 | bc_program_reset(); | 6914 | bc_program_reset(); |
6912 | return s; | 6915 | RETURN_STATUS(s); |
6913 | } | 6916 | } |
6914 | 6917 | ||
6915 | // If the stack has changed, pointers may be invalid. | 6918 | // If the stack has changed, pointers may be invalid. |
@@ -6918,8 +6921,11 @@ static BcStatus bc_program_exec(void) | |||
6918 | code = func->code.v; | 6921 | code = func->code.v; |
6919 | } | 6922 | } |
6920 | 6923 | ||
6921 | return BC_STATUS_SUCCESS; | 6924 | RETURN_STATUS(BC_STATUS_SUCCESS); |
6922 | } | 6925 | } |
6926 | #if ERRORS_ARE_FATAL | ||
6927 | # define zbc_program_exec(...) (zbc_program_exec(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
6928 | #endif | ||
6923 | 6929 | ||
6924 | #if ENABLE_BC | 6930 | #if ENABLE_BC |
6925 | static void bc_vm_info(void) | 6931 | static void bc_vm_info(void) |
@@ -7009,28 +7015,31 @@ static unsigned bc_vm_envLen(const char *var) | |||
7009 | return len; | 7015 | return len; |
7010 | } | 7016 | } |
7011 | 7017 | ||
7012 | static BcStatus bc_vm_process(const char *text) | 7018 | static BC_STATUS zbc_vm_process(const char *text) |
7013 | { | 7019 | { |
7014 | BcStatus s = zbc_parse_text(&G.prs, text); | 7020 | BcStatus s = zbc_parse_text(&G.prs, text); |
7015 | 7021 | ||
7016 | if (s) return s; | 7022 | if (s) RETURN_STATUS(s); |
7017 | 7023 | ||
7018 | while (G.prs.l.t.t != BC_LEX_EOF) { | 7024 | while (G.prs.l.t.t != BC_LEX_EOF) { |
7019 | ERROR_RETURN(s =) G.prs.parse(&G.prs); | 7025 | ERROR_RETURN(s =) G.prs.parse(&G.prs); |
7020 | if (s) return s; | 7026 | if (s) RETURN_STATUS(s); |
7021 | } | 7027 | } |
7022 | 7028 | ||
7023 | if (BC_PARSE_CAN_EXEC(&G.prs)) { | 7029 | if (BC_PARSE_CAN_EXEC(&G.prs)) { |
7024 | s = bc_program_exec(); | 7030 | s = zbc_program_exec(); |
7025 | fflush_and_check(); | 7031 | fflush_and_check(); |
7026 | if (s) | 7032 | if (s) |
7027 | bc_program_reset(); | 7033 | bc_program_reset(); |
7028 | } | 7034 | } |
7029 | 7035 | ||
7030 | return s; | 7036 | RETURN_STATUS(s); |
7031 | } | 7037 | } |
7038 | #if ERRORS_ARE_FATAL | ||
7039 | # define zbc_vm_process(...) (zbc_vm_process(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
7040 | #endif | ||
7032 | 7041 | ||
7033 | static BcStatus bc_vm_file(const char *file) | 7042 | static BC_STATUS zbc_vm_file(const char *file) |
7034 | { | 7043 | { |
7035 | const char *sv_file; | 7044 | const char *sv_file; |
7036 | char *data; | 7045 | char *data; |
@@ -7039,12 +7048,12 @@ static BcStatus bc_vm_file(const char *file) | |||
7039 | BcInstPtr *ip; | 7048 | BcInstPtr *ip; |
7040 | 7049 | ||
7041 | data = bc_read_file(file); | 7050 | data = bc_read_file(file); |
7042 | if (!data) return bc_error_fmt("file '%s' is not text", file); | 7051 | if (!data) RETURN_STATUS(bc_error_fmt("file '%s' is not text", file)); |
7043 | 7052 | ||
7044 | sv_file = G.prog.file; | 7053 | sv_file = G.prog.file; |
7045 | G.prog.file = file; | 7054 | G.prog.file = file; |
7046 | bc_lex_file(&G.prs.l); | 7055 | bc_lex_file(&G.prs.l); |
7047 | s = bc_vm_process(data); | 7056 | s = zbc_vm_process(data); |
7048 | if (s) goto err; | 7057 | if (s) goto err; |
7049 | 7058 | ||
7050 | main_func = bc_program_func(BC_PROG_MAIN); | 7059 | main_func = bc_program_func(BC_PROG_MAIN); |
@@ -7056,8 +7065,11 @@ static BcStatus bc_vm_file(const char *file) | |||
7056 | err: | 7065 | err: |
7057 | G.prog.file = sv_file; | 7066 | G.prog.file = sv_file; |
7058 | free(data); | 7067 | free(data); |
7059 | return s; | 7068 | RETURN_STATUS(s); |
7060 | } | 7069 | } |
7070 | #if ERRORS_ARE_FATAL | ||
7071 | # define zbc_vm_file(...) (zbc_vm_file(__VA_ARGS__), BC_STATUS_SUCCESS) | ||
7072 | #endif | ||
7061 | 7073 | ||
7062 | static BcStatus bc_vm_stdin(void) | 7074 | static BcStatus bc_vm_stdin(void) |
7063 | { | 7075 | { |
@@ -7120,7 +7132,7 @@ static BcStatus bc_vm_stdin(void) | |||
7120 | } | 7132 | } |
7121 | 7133 | ||
7122 | bc_vec_concat(&buffer, buf.v); | 7134 | bc_vec_concat(&buffer, buf.v); |
7123 | s = bc_vm_process(buffer.v); | 7135 | s = zbc_vm_process(buffer.v); |
7124 | if (s) { | 7136 | if (s) { |
7125 | if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) { | 7137 | if (ENABLE_FEATURE_CLEAN_UP && !G_ttyin) { |
7126 | // Debug config, non-interactive mode: | 7138 | // Debug config, non-interactive mode: |
@@ -7343,14 +7355,14 @@ static BcStatus bc_vm_exec(void) | |||
7343 | ERROR_RETURN(s =) G.prs.parse(&G.prs); | 7355 | ERROR_RETURN(s =) G.prs.parse(&G.prs); |
7344 | if (DEBUG_LIB && s) return s; | 7356 | if (DEBUG_LIB && s) return s; |
7345 | } | 7357 | } |
7346 | s = bc_program_exec(); | 7358 | s = zbc_program_exec(); |
7347 | if (DEBUG_LIB && s) return s; | 7359 | if (DEBUG_LIB && s) return s; |
7348 | } | 7360 | } |
7349 | #endif | 7361 | #endif |
7350 | 7362 | ||
7351 | s = BC_STATUS_SUCCESS; | 7363 | s = BC_STATUS_SUCCESS; |
7352 | for (i = 0; !s && i < G.files.len; ++i) | 7364 | for (i = 0; !s && i < G.files.len; ++i) |
7353 | s = bc_vm_file(*((char **) bc_vec_item(&G.files, i))); | 7365 | s = zbc_vm_file(*((char **) bc_vec_item(&G.files, i))); |
7354 | if (ENABLE_FEATURE_CLEAN_UP && s && !G_ttyin) { | 7366 | if (ENABLE_FEATURE_CLEAN_UP && s && !G_ttyin) { |
7355 | // Debug config, non-interactive mode: | 7367 | // Debug config, non-interactive mode: |
7356 | // return all the way back to main. | 7368 | // return all the way back to main. |
@@ -7362,7 +7374,7 @@ static BcStatus bc_vm_exec(void) | |||
7362 | s = bc_vm_stdin(); | 7374 | s = bc_vm_stdin(); |
7363 | 7375 | ||
7364 | if (!s && !BC_PARSE_CAN_EXEC(&G.prs)) | 7376 | if (!s && !BC_PARSE_CAN_EXEC(&G.prs)) |
7365 | s = bc_vm_process(""); | 7377 | s = zbc_vm_process(""); |
7366 | 7378 | ||
7367 | return s; | 7379 | return s; |
7368 | } | 7380 | } |
@@ -7560,12 +7572,13 @@ int dc_main(int argc UNUSED_PARAM, char **argv) | |||
7560 | switch (n) { | 7572 | switch (n) { |
7561 | case 'e': | 7573 | case 'e': |
7562 | noscript = 0; | 7574 | noscript = 0; |
7563 | n = bc_vm_process(optarg); | 7575 | n = zbc_vm_process(optarg); |
7564 | if (n) return n; | 7576 | if (n) return n; |
7565 | break; | 7577 | break; |
7566 | case 'f': | 7578 | case 'f': |
7567 | noscript = 0; | 7579 | noscript = 0; |
7568 | bc_vm_file(optarg); | 7580 | n = zbc_vm_file(optarg); |
7581 | if (n) return n; | ||
7569 | break; | 7582 | break; |
7570 | case 'x': | 7583 | case 'x': |
7571 | option_mask32 |= DC_FLAG_X; | 7584 | option_mask32 |= DC_FLAG_X; |