aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-28 14:18:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-28 14:18:35 +0200
commit800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d (patch)
treec78ee209986946838faf337bf997c2f6fb7d84f7
parente619a25a551ac6a5f215005166371074a9e2816f (diff)
downloadbusybox-w32-800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d.tar.gz
busybox-w32-800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d.tar.bz2
busybox-w32-800207b90a4f5f78cbe65a0f4b3ecd3b93abbd7d.zip
shell/math: code shrink
function old new delta arith_apply 1015 1023 +8 evaluate_string 1309 1295 -14 .rodata 105344 105321 -23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37) Total: -29 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/math.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/shell/math.c b/shell/math.c
index 9e81d604c..e15b014aa 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -141,6 +141,7 @@ typedef unsigned char operator;
141 * but there are 11 of them, which doesn't fit into 3 bits for unique id. 141 * but there are 11 of them, which doesn't fit into 3 bits for unique id.
142 * Abusing another precedence level: 142 * Abusing another precedence level:
143 */ 143 */
144#define PREC_ASSIGN1 2
144#define TOK_ASSIGN tok_decl(2,0) 145#define TOK_ASSIGN tok_decl(2,0)
145#define TOK_AND_ASSIGN tok_decl(2,1) 146#define TOK_AND_ASSIGN tok_decl(2,1)
146#define TOK_OR_ASSIGN tok_decl(2,2) 147#define TOK_OR_ASSIGN tok_decl(2,2)
@@ -150,11 +151,12 @@ typedef unsigned char operator;
150#define TOK_LSHIFT_ASSIGN tok_decl(2,6) 151#define TOK_LSHIFT_ASSIGN tok_decl(2,6)
151#define TOK_RSHIFT_ASSIGN tok_decl(2,7) 152#define TOK_RSHIFT_ASSIGN tok_decl(2,7)
152 153
154#define PREC_ASSIGN2 3
153#define TOK_MUL_ASSIGN tok_decl(3,0) 155#define TOK_MUL_ASSIGN tok_decl(3,0)
154#define TOK_DIV_ASSIGN tok_decl(3,1) 156#define TOK_DIV_ASSIGN tok_decl(3,1)
155#define TOK_REM_ASSIGN tok_decl(3,2) 157#define TOK_REM_ASSIGN tok_decl(3,2)
156 158
157#define fix_assignment_prec(prec) do { if (prec == 3) prec = 2; } while (0) 159#define fix_assignment_prec(prec) do { prec -= (prec == 3); } while (0)
158 160
159/* Ternary conditional operator is right associative too */ 161/* Ternary conditional operator is right associative too */
160/* 162/*
@@ -211,25 +213,25 @@ typedef unsigned char operator;
211#define TOK_UPLUS tok_decl(UNARYPREC+1,1) 213#define TOK_UPLUS tok_decl(UNARYPREC+1,1)
212 214
213#define PREC_PRE (UNARYPREC+2) 215#define PREC_PRE (UNARYPREC+2)
214#define TOK_PRE_INC tok_decl(PREC_PRE, 0) 216#define TOK_PRE_INC tok_decl(PREC_PRE,0)
215#define TOK_PRE_DEC tok_decl(PREC_PRE, 1) 217#define TOK_PRE_DEC tok_decl(PREC_PRE,1)
216 218
217#define PREC_POST (UNARYPREC+3) 219#define PREC_POST (UNARYPREC+3)
218#define TOK_POST_INC tok_decl(PREC_POST, 0) 220#define TOK_POST_INC tok_decl(PREC_POST,0)
219#define TOK_POST_DEC tok_decl(PREC_POST, 1) 221#define TOK_POST_DEC tok_decl(PREC_POST,1)
220 222
221/* TOK_VALUE marks a number, name, name++/name--, or (EXPR): 223/* TOK_VALUE marks a number, name, name++/name--, or (EXPR):
222 * IOW: something which can be used as the left side of a binary op. 224 * IOW: something which can be used as the left side of a binary op.
223 * Since it's never pushed to opstack, its precedence does not matter. 225 * Since it's never pushed to opstack, its precedence does not matter.
224 */ 226 */
225#define TOK_VALUE tok_decl(PREC_POST, 2) 227#define TOK_VALUE tok_decl(PREC_POST,2)
226 228
227static int 229static int
228is_assign_op(operator op) 230is_assign_op(operator op)
229{ 231{
230 operator prec = PREC(op); 232 operator prec = PREC(op);
231 fix_assignment_prec(prec); 233 return prec == PREC_ASSIGN1
232 return prec == PREC(TOK_ASSIGN) 234 || prec == PREC_ASSIGN2
233 || prec == PREC_PRE 235 || prec == PREC_PRE
234 || prec == PREC_POST; 236 || prec == PREC_POST;
235} 237}