aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-24 17:06:37 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-24 17:07:20 +0100
commita5bf53e4bb7a45236c44e5f564cb044fbf654ea5 (patch)
treef8d62c137decb4b12000248f8452a8d3cc308447 /miscutils
parent4accb6bba8ac89a35f20147196441c1f829be360 (diff)
downloadbusybox-w32-a5bf53e4bb7a45236c44e5f564cb044fbf654ea5.tar.gz
busybox-w32-a5bf53e4bb7a45236c44e5f564cb044fbf654ea5.tar.bz2
busybox-w32-a5bf53e4bb7a45236c44e5f564cb044fbf654ea5.zip
bc: move relational LEXs before math LEXs - shorten dc_LEX_to_INST[]
function old new delta dc_LEX_to_INST 48 42 -6 zdc_parse_expr 523 514 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15) Total: -15 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c81
1 files changed, 39 insertions, 42 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 8556a0e73..68e3668c4 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -253,19 +253,19 @@ typedef enum BcInst {
253#endif 253#endif
254 XC_INST_NEG, // order 254 XC_INST_NEG, // order
255 255
256 XC_INST_POWER, // should 256 XC_INST_REL_EQ, // should
257 XC_INST_MULTIPLY, // match 257 XC_INST_REL_LE, // match
258 XC_INST_DIVIDE, // LEX 258 XC_INST_REL_GE, // LEX
259 XC_INST_MODULUS, // constants 259 XC_INST_REL_NE, // constants
260 XC_INST_PLUS, // for 260 XC_INST_REL_LT, // for
261 XC_INST_MINUS, // these 261 XC_INST_REL_GT, // these
262 262
263 XC_INST_REL_EQ, // operations 263 XC_INST_POWER, // operations
264 XC_INST_REL_LE, // | 264 XC_INST_MULTIPLY, // |
265 XC_INST_REL_GE, // | 265 XC_INST_DIVIDE, // |
266 XC_INST_REL_NE, // | 266 XC_INST_MODULUS, // |
267 XC_INST_REL_LT, // | 267 XC_INST_PLUS, // |
268 XC_INST_REL_GT, // | 268 XC_INST_MINUS, // |
269 269
270 XC_INST_BOOL_NOT, // | 270 XC_INST_BOOL_NOT, // |
271 XC_INST_BOOL_OR, // | 271 XC_INST_BOOL_OR, // |
@@ -401,20 +401,20 @@ typedef enum BcLexType {
401 XC_LEX_1st_op, 401 XC_LEX_1st_op,
402 XC_LEX_NEG = XC_LEX_1st_op, // order 402 XC_LEX_NEG = XC_LEX_1st_op, // order
403 403
404 XC_LEX_OP_POWER, // should 404 XC_LEX_OP_REL_EQ, // should
405 XC_LEX_OP_MULTIPLY, // match 405 XC_LEX_OP_REL_LE, // match
406 XC_LEX_OP_DIVIDE, // INST 406 XC_LEX_OP_REL_GE, // INST
407 XC_LEX_OP_MODULUS, // constants 407 XC_LEX_OP_REL_NE, // constants
408 XC_LEX_OP_PLUS, // for 408 XC_LEX_OP_REL_LT, // for
409 XC_LEX_OP_MINUS, // these 409 XC_LEX_OP_REL_GT, // these
410 410
411 XC_LEX_OP_REL_EQ, // operations 411 XC_LEX_OP_POWER, // operations
412 XC_LEX_OP_REL_LE, // | 412 XC_LEX_OP_MULTIPLY, // |
413 XC_LEX_OP_REL_GE, // | 413 XC_LEX_OP_DIVIDE, // |
414 XC_LEX_OP_REL_NE, // | 414 XC_LEX_OP_MODULUS, // |
415 XC_LEX_OP_REL_LT, // | 415 XC_LEX_OP_PLUS, // |
416 XC_LEX_OP_REL_GT, // | 416 XC_LEX_OP_MINUS, // |
417 XC_LEX_OP_last = XC_LEX_OP_REL_GT, 417 XC_LEX_OP_last = XC_LEX_OP_MINUS,
418#if ENABLE_BC 418#if ENABLE_BC
419 BC_LEX_OP_BOOL_NOT, // | 419 BC_LEX_OP_BOOL_NOT, // |
420 BC_LEX_OP_BOOL_OR, // | 420 BC_LEX_OP_BOOL_OR, // |
@@ -432,16 +432,16 @@ typedef enum BcLexType {
432 BC_LEX_OP_INC, 432 BC_LEX_OP_INC,
433 BC_LEX_OP_DEC, 433 BC_LEX_OP_DEC,
434 434
435 BC_LEX_LPAREN, 435 BC_LEX_LPAREN, // () are 0x28 and 0x29
436 BC_LEX_RPAREN, 436 BC_LEX_RPAREN, // must be LPAREN+1: code uses (c - '(' + BC_LEX_LPAREN)
437 437
438 BC_LEX_LBRACKET, 438 BC_LEX_LBRACKET, // [] are 0x5B and 5D
439 BC_LEX_COMMA, 439 BC_LEX_COMMA,
440 BC_LEX_RBRACKET, 440 BC_LEX_RBRACKET, // must be LBRACKET+2: code uses (c - '[' + BC_LEX_LBRACKET)
441 441
442 BC_LEX_LBRACE, // '{' is 0x7B, '}' is 0x7D, 442 BC_LEX_LBRACE, // {} are 0x7B and 0x7D
443 BC_LEX_SCOLON, 443 BC_LEX_SCOLON,
444 BC_LEX_RBRACE, // should be LBRACE+2: code uses (c - '{' + BC_LEX_LBRACE) 444 BC_LEX_RBRACE, // must be LBRACE+2: code uses (c - '{' + BC_LEX_LBRACE)
445 445
446 BC_LEX_KEY_1st_keyword, 446 BC_LEX_KEY_1st_keyword,
447 BC_LEX_KEY_AUTO = BC_LEX_KEY_1st_keyword, 447 BC_LEX_KEY_AUTO = BC_LEX_KEY_1st_keyword,
@@ -582,8 +582,8 @@ enum {
582 ((uint64_t)((a << 0)+(b << 1)+(c << 2)+(d << 3)+(e << 4)+(f << 5)+(g << 6)+(h << 7))) 582 ((uint64_t)((a << 0)+(b << 1)+(c << 2)+(d << 3)+(e << 4)+(f << 5)+(g << 6)+(h << 7)))
583 BC_PARSE_EXPRS_BITS = 0 // corresponding BC_LEX_xyz: 583 BC_PARSE_EXPRS_BITS = 0 // corresponding BC_LEX_xyz:
584 + (EXBITS(0,0,0,0,0,1,1,1) << (0*8)) // 0: EOF INVAL NL WS STR NAME NUM - 584 + (EXBITS(0,0,0,0,0,1,1,1) << (0*8)) // 0: EOF INVAL NL WS STR NAME NUM -
585 + (EXBITS(1,1,1,1,1,1,1,1) << (1*8)) // 8: ^ * / % + - == <= 585 + (EXBITS(1,1,1,1,1,1,1,1) << (1*8)) // 8: == <= >= != < > ^ *
586 + (EXBITS(1,1,1,1,1,1,1,1) << (2*8)) // 16: >= != < > ! || && ^= 586 + (EXBITS(1,1,1,1,1,1,1,1) << (2*8)) // 16: / % + - ! || && ^=
587 + (EXBITS(1,1,1,1,1,1,1,1) << (3*8)) // 24: *= /= %= += -= = ++ -- 587 + (EXBITS(1,1,1,1,1,1,1,1) << (3*8)) // 24: *= /= %= += -= = ++ --
588 + (EXBITS(1,1,0,0,0,0,0,0) << (4*8)) // 32: ( ) [ , ] { ; } 588 + (EXBITS(1,1,0,0,0,0,0,0) << (4*8)) // 32: ( ) [ , ] { ; }
589 + (EXBITS(0,0,0,0,0,0,0,1) << (5*8)) // 40: auto break cont define else for halt ibase 589 + (EXBITS(0,0,0,0,0,0,0,1) << (5*8)) // 40: auto break cont define else for halt ibase
@@ -612,10 +612,10 @@ static ALWAYS_INLINE long bc_parse_exprs(unsigned i)
612static const uint8_t bc_parse_ops[] = { 612static const uint8_t bc_parse_ops[] = {
613#define OP(p,l) ((int)(l) * 0x10 + (p)) 613#define OP(p,l) ((int)(l) * 0x10 + (p))
614 OP(1, false), // neg 614 OP(1, false), // neg
615 OP(6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), // == <= >= != < >
615 OP(2, false), // pow 616 OP(2, false), // pow
616 OP(3, true ), OP( 3, true ), OP( 3, true ), // mul div mod 617 OP(3, true ), OP( 3, true ), OP( 3, true ), // mul div mod
617 OP(4, true ), OP( 4, true ), // + - 618 OP(4, true ), OP( 4, true ), // + -
618 OP(6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), OP( 6, true ), // == <= >= != < >
619 OP(1, false), // not 619 OP(1, false), // not
620 OP(7, true ), OP( 7, true ), // or and 620 OP(7, true ), OP( 7, true ), // or and
621 OP(5, false), OP( 5, false ), OP( 5, false ), OP( 5, false ), OP( 5, false ), // ^= *= /= %= += 621 OP(5, false), OP( 5, false ), OP( 5, false ), OP( 5, false ), OP( 5, false ), // ^= *= /= %= +=
@@ -677,9 +677,6 @@ dc_LEX_to_INST[] = { // starts at XC_LEX_OP_POWER // corresponding XC/DC_L
677 XC_INST_POWER, XC_INST_MULTIPLY, // OP_POWER OP_MULTIPLY 677 XC_INST_POWER, XC_INST_MULTIPLY, // OP_POWER OP_MULTIPLY
678 XC_INST_DIVIDE, XC_INST_MODULUS, // OP_DIVIDE OP_MODULUS 678 XC_INST_DIVIDE, XC_INST_MODULUS, // OP_DIVIDE OP_MODULUS
679 XC_INST_PLUS, XC_INST_MINUS, // OP_PLUS OP_MINUS 679 XC_INST_PLUS, XC_INST_MINUS, // OP_PLUS OP_MINUS
680 DC_INST_INVALID, DC_INST_INVALID, // OP_REL_EQ OP_REL_LE
681 DC_INST_INVALID, DC_INST_INVALID, // OP_REL_GE OP_REL_NE
682 DC_INST_INVALID, DC_INST_INVALID, // OP_REL_LT OP_REL_GT
683 XC_INST_BOOL_NOT, // DC_LEX_OP_BOOL_NOT 680 XC_INST_BOOL_NOT, // DC_LEX_OP_BOOL_NOT
684 DC_INST_INVALID, // DC_LEX_OP_ASSIGN 681 DC_INST_INVALID, // DC_LEX_OP_ASSIGN
685 XC_INST_REL_GT, // DC_LEX_LPAREN 682 XC_INST_REL_GT, // DC_LEX_LPAREN
@@ -4655,7 +4652,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4655 bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last; 4652 bool paren_first, paren_expr, rprn, done, get_token, assign, bin_last;
4656 4653
4657 dbg_lex_enter("%s:%d entered", __func__, __LINE__); 4654 dbg_lex_enter("%s:%d entered", __func__, __LINE__);
4658 paren_first = p->l.t.t == BC_LEX_LPAREN; 4655 paren_first = (p->l.t.t == BC_LEX_LPAREN);
4659 nparens = nrelops = 0; 4656 nparens = nrelops = 0;
4660 paren_expr = rprn = done = get_token = assign = false; 4657 paren_expr = rprn = done = get_token = assign = false;
4661 bin_last = true; 4658 bin_last = true;
@@ -4671,7 +4668,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4671 case XC_LEX_OP_MINUS: 4668 case XC_LEX_OP_MINUS:
4672 s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs); 4669 s = zbc_parse_minus(p, &prev, ops_bgn, rprn, &nexprs);
4673 rprn = get_token = false; 4670 rprn = get_token = false;
4674 bin_last = prev == XC_INST_MINUS; 4671 bin_last = (prev == XC_INST_MINUS);
4675 break; 4672 break;
4676 case BC_LEX_OP_ASSIGN_POWER: 4673 case BC_LEX_OP_ASSIGN_POWER:
4677 case BC_LEX_OP_ASSIGN_MULTIPLY: 4674 case BC_LEX_OP_ASSIGN_MULTIPLY:
@@ -4812,7 +4809,7 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4812 4809
4813 while (p->ops.len > ops_bgn) { 4810 while (p->ops.len > ops_bgn) {
4814 top = BC_PARSE_TOP_OP(p); 4811 top = BC_PARSE_TOP_OP(p);
4815 assign = top >= BC_LEX_OP_ASSIGN_POWER && top <= BC_LEX_OP_ASSIGN; 4812 assign = (top >= BC_LEX_OP_ASSIGN_POWER && top <= BC_LEX_OP_ASSIGN);
4816 4813
4817 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN) 4814 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN)
4818 return bc_error_bad_expression(); 4815 return bc_error_bad_expression();