aboutsummaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-25 22:20:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-25 22:20:14 +0100
commit6e6182342ef59c47972a49543cd8b15dc4f28f6d (patch)
tree81f7b11d93a08568e3f9925772c35000a5e4d69e /miscutils/bc.c
parent0b0e8d0509bdd45aa600d3ea2bf9043630809cd2 (diff)
downloadbusybox-w32-6e6182342ef59c47972a49543cd8b15dc4f28f6d.tar.gz
busybox-w32-6e6182342ef59c47972a49543cd8b15dc4f28f6d.tar.bz2
busybox-w32-6e6182342ef59c47972a49543cd8b15dc4f28f6d.zip
bc: move BcLex::lex member to be the first in struct globals
function old new delta zbc_program_exec 3967 4003 +36 zdc_program_execStr 501 520 +19 zbc_posix_error_fmt 58 62 +4 bc_vm_init 675 679 +4 bc_read_line 407 411 +4 bc_error_fmt 36 40 +4 zdc_parse_register 45 44 -1 zdc_parse_exprs_until_eof 28 27 -1 zbc_parse_text_init 56 55 -1 zbc_parse_stmt_allow_NLINE_before 55 54 -1 zbc_lex_skip_if_at_NLINE 19 18 -1 zbc_lex_number 178 177 -1 bc_parse_create 97 96 -1 bc_lex_whitespace 43 42 -1 bc_lex_name 71 70 -1 bc_lex_lineComment 38 37 -1 bc_lex_assign 35 34 -1 zdc_parse_expr 476 473 -3 bc_verror_msg 93 90 -3 bc_lex_file 27 24 -3 zbc_parse_name 453 448 -5 bc_parse_expr_empty_ok 1776 1764 -12 zbc_vm_process 878 865 -13 zbc_parse_stmt_possibly_auto 1451 1425 -26 zbc_lex_next 2075 2039 -36 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/19 up/down: 71/-112) Total: -41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c130
1 files changed, 65 insertions, 65 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 7a6278cfc..44d4976cc 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -711,40 +711,29 @@ dc_LEX_to_INST[] = { // starts at XC_LEX_OP_POWER // corresponding XC/DC_L
711#endif // ENABLE_DC 711#endif // ENABLE_DC
712 712
713typedef struct BcLex { 713typedef struct BcLex {
714 const char *lex_inbuf; 714 smallint lex; // was BcLexType // first member is most used
715 const char *lex_next_at; // last lex_next() was called at this string 715 smallint lex_last; // was BcLexType
716 bool lex_newline;
716 size_t lex_i; 717 size_t lex_i;
717 size_t lex_line; 718 size_t lex_line;
718 size_t lex_len; 719 size_t lex_len;
719 bool lex_newline; 720 const char *lex_inbuf;
720 smallint lex; // was BcLexType 721 const char *lex_next_at; // last lex_next() was called at this string
721 smallint lex_last; // was BcLexType
722 BcVec lex_strnumbuf; 722 BcVec lex_strnumbuf;
723} BcLex; 723} BcLex;
724 724
725#define BC_PARSE_STREND (0xff)
726
727#if ENABLE_BC
728# define BC_PARSE_REL (1 << 0)
729# define BC_PARSE_PRINT (1 << 1)
730# define BC_PARSE_ARRAY (1 << 2)
731# define BC_PARSE_NOCALL (1 << 3)
732#endif
733
734typedef struct BcParse { 725typedef struct BcParse {
735 BcLex l; 726 BcLex l; // first member is most used
736
737 IF_BC(BcVec exits;)
738 IF_BC(BcVec conds;)
739 IF_BC(BcVec ops;)
740 727
741 const char *filename; 728 const char *filename;
742 FILE *input_fp; 729 FILE *input_fp;
743 730
744 BcFunc *func; 731 BcFunc *func;
745 size_t fidx; 732 size_t fidx;
746
747 IF_BC(size_t in_funcdef;) 733 IF_BC(size_t in_funcdef;)
734 IF_BC(BcVec exits;)
735 IF_BC(BcVec conds;)
736 IF_BC(BcVec ops;)
748} BcParse; 737} BcParse;
749 738
750typedef struct BcProgram { 739typedef struct BcProgram {
@@ -775,6 +764,62 @@ typedef struct BcProgram {
775 IF_BC(BcNum last;) 764 IF_BC(BcNum last;)
776} BcProgram; 765} BcProgram;
777 766
767struct globals {
768 BcParse prs; // first member is most used
769
770 // For error messages. Can be set to current parsed line,
771 // or [TODO] to current executing line (can be before last parsed one)
772 unsigned err_line;
773
774 BcVec input_buffer;
775
776 IF_FEATURE_BC_SIGNALS(smallint ttyin;)
777 IF_FEATURE_CLEAN_UP(smallint exiting;)
778
779 BcProgram prog;
780
781 BcVec files;
782
783 char *env_args;
784
785#if ENABLE_FEATURE_EDITING
786 line_input_t *line_input_state;
787#endif
788} FIX_ALIASING;
789#define G (*ptr_to_globals)
790#define INIT_G() do { \
791 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
792} while (0)
793#define FREE_G() do { \
794 FREE_PTR_TO_GLOBALS(); \
795} while (0)
796#define G_posix (ENABLE_BC && (option_mask32 & BC_FLAG_S))
797#define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W))
798#define G_exreg (ENABLE_DC && (option_mask32 & DC_FLAG_X))
799#if ENABLE_FEATURE_BC_SIGNALS
800# define G_interrupt bb_got_signal
801# define G_ttyin G.ttyin
802#else
803# define G_interrupt 0
804# define G_ttyin 0
805#endif
806#if ENABLE_FEATURE_CLEAN_UP
807# define G_exiting G.exiting
808#else
809# define G_exiting 0
810#endif
811#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b'))
812#define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b'))
813
814#define BC_PARSE_STREND (0xff)
815
816#if ENABLE_BC
817# define BC_PARSE_REL (1 << 0)
818# define BC_PARSE_PRINT (1 << 1)
819# define BC_PARSE_ARRAY (1 << 2)
820# define BC_PARSE_NOCALL (1 << 3)
821#endif
822
778#define BC_PROG_MAIN (0) 823#define BC_PROG_MAIN (0)
779#define BC_PROG_READ (1) 824#define BC_PROG_READ (1)
780#if ENABLE_DC 825#if ENABLE_DC
@@ -830,51 +875,6 @@ typedef struct BcProgram {
830#endif 875#endif
831#define BC_MAX_NUM_STR BC_MAX_STRING_STR 876#define BC_MAX_NUM_STR BC_MAX_STRING_STR
832 877
833struct globals {
834 IF_FEATURE_BC_SIGNALS(smallint ttyin;)
835 IF_FEATURE_CLEAN_UP(smallint exiting;)
836
837 BcParse prs;
838 BcProgram prog;
839
840 // For error messages. Can be set to current parsed line,
841 // or [TODO] to current executing line (can be before last parsed one)
842 unsigned err_line;
843
844 BcVec files;
845 BcVec input_buffer;
846
847 char *env_args;
848
849#if ENABLE_FEATURE_EDITING
850 line_input_t *line_input_state;
851#endif
852} FIX_ALIASING;
853#define G (*ptr_to_globals)
854#define INIT_G() do { \
855 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
856} while (0)
857#define FREE_G() do { \
858 FREE_PTR_TO_GLOBALS(); \
859} while (0)
860#define G_posix (ENABLE_BC && (option_mask32 & BC_FLAG_S))
861#define G_warn (ENABLE_BC && (option_mask32 & BC_FLAG_W))
862#define G_exreg (ENABLE_DC && (option_mask32 & DC_FLAG_X))
863#if ENABLE_FEATURE_BC_SIGNALS
864# define G_interrupt bb_got_signal
865# define G_ttyin G.ttyin
866#else
867# define G_interrupt 0
868# define G_ttyin 0
869#endif
870#if ENABLE_FEATURE_CLEAN_UP
871# define G_exiting G.exiting
872#else
873# define G_exiting 0
874#endif
875#define IS_BC (ENABLE_BC && (!ENABLE_DC || applet_name[0] == 'b'))
876#define IS_DC (ENABLE_DC && (!ENABLE_BC || applet_name[0] != 'b'))
877
878// In configurations where errors abort instead of propagating error 878// In configurations where errors abort instead of propagating error
879// return code up the call chain, functions returning BC_STATUS 879// return code up the call chain, functions returning BC_STATUS
880// actually don't return anything, they always succeed and return "void". 880// actually don't return anything, they always succeed and return "void".