aboutsummaryrefslogtreecommitdiff
path: root/shell/math.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* shell/math: avoid $((3**999999999999999999)) to take yearsDenys Vlasenko2023-07-021-3/+14
| | | | | | | function old new delta arith_apply 991 1030 +39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: do not accept $((36#@))Denys Vlasenko2023-07-021-16/+22
| | | | | | | | | | function old new delta parse_with_base 170 174 +4 arith_apply 996 991 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-301-4/+7
| | | | | | | | | | function old new delta arith_apply 999 996 -3 evaluate_string 1295 1291 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7) Total: -7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-291-11/+13
| | | | | | | function old new delta arith_apply 1023 996 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-281-8/+10
| | | | | | | | | | | 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>
* shell/math: improve commentsDenys Vlasenko2023-06-261-2/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: rename TOK_NUM to TOK_VALUE, improve commentsDenys Vlasenko2023-06-261-24/+25
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: bash-compatible handling of too large numbersDenys Vlasenko2023-06-251-36/+48
| | | | | | | | | | function old new delta parse_with_base - 170 +170 evaluate_string 1477 1309 -168 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: disable debug againDenys Vlasenko2023-06-191-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: $((1?)) has one-too-small opstack, fix thisDenys Vlasenko2023-06-191-1/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix comments about jammed-together num+num corner casesDenys Vlasenko2023-06-191-8/+16
| | | | | | | function old new delta evaluate_string 1478 1470 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: add note on ERANGEDenys Vlasenko2023-06-181-4/+11
| | | | | | | function old new delta evaluate_string 1488 1478 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: explain why we use separate &endDenys Vlasenko2023-06-181-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-181-2/+5
| | | | | | | function old new delta evaluate_string 1498 1491 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: eliminate redundant endofname()Denys Vlasenko2023-06-181-8/+8
| | | | | | | function old new delta evaluate_string 1486 1498 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-181-11/+12
| | | | | | | function old new delta evaluate_string 1489 1486 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: decrease stack usage by not allocating copies of variable namesDenys Vlasenko2023-06-181-32/+51
| | | | | | | | | | | | We risk exhaust stack with alloca() with old code. function old new delta arith_apply 990 1023 +33 evaluate_string 1467 1494 +27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: decrease stack usageDenys Vlasenko2023-06-181-35/+27
| | | | | | | function old new delta evaluate_string 1412 1467 +55 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: eliminate some redundant stores on return code pathDenys Vlasenko2023-06-171-20/+23
| | | | | | | function old new delta evaluate_string 1432 1412 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: change ?: nesting code to not have 63 level nesting limitationDenys Vlasenko2023-06-171-13/+20
| | | | | | | | | | | function old new delta evaluate_string 1406 1432 +26 arith 36 29 -7 arith_apply 998 990 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-15) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math.h: update comments, rearrange struct members for smaller codeDenys Vlasenko2023-06-171-1/+1
| | | | | | | | | | function old new delta arith_apply 1000 998 -2 evaluate_string 1414 1406 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: code shrinkDenys Vlasenko2023-06-171-3/+3
| | | | | | | function old new delta evaluate_string 1432 1414 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: tweka commentsDenys Vlasenko2023-06-161-16/+8
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix ?: to not evaluate not-taken branchesDenys Vlasenko2023-06-161-22/+63
| | | | | | | | | | | | | This fixes ash-arith-arith-ternary1/2.tests function old new delta evaluate_string 1271 1432 +161 arith_apply 968 1000 +32 arith 22 36 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0) Total: 207 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: simplify handling of unary plusDenys Vlasenko2023-06-151-3/+5
| | | | | | | | | | function old new delta evaluate_string 1257 1271 +14 arith_apply 977 968 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9) Total: 5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: explain the logic, small tweak to make code smallerDenys Vlasenko2023-06-151-10/+25
| | | | | | | function old new delta evaluate_string 1258 1257 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix order of expansion of variables to numbersDenys Vlasenko2023-06-151-34/+15
| | | | | | | | | | | | | This fixes arith-assign-in-varexp1.tests function old new delta evaluate_string 1132 1258 +126 arith_lookup_val 143 - -143 arith_apply 1132 977 -155 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298) Total: -172 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: remove special code to handle a?b?c:d:e, it works without it nowDenys Vlasenko2023-06-151-9/+3
| | | | | | | | | | | The "hack" to virtually parenthesize ? EXPR : made this unnecessary. The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated before continuing with the second : function old new delta evaluate_string 1148 1132 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix parsing of ?: and explain why it's parsed that wayDenys Vlasenko2023-06-151-14/+34
| | | | | | | | | | | | | | | | | This fixes arith-precedence1.tests. This breaks arith-ternary2.tests again (we now evaluate variables on not-taken branches). We need a better logic here anyway: not only bare variables should not evaluate when not-taken: 1 ? eval_me : do_not_eval but any (arbitrarily complex) expressions shouldn't evaluate as well! 1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4)) function old new delta evaluate_string 1097 1148 +51 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: simpler insertion of "fake" last RPARENDenys Vlasenko2023-06-151-7/+6
| | | | | | | | | Skip one pass through token table, since we know the result. function old new delta evaluate_string 1095 1097 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: trivial code shrinkDenys Vlasenko2023-06-141-4/+3
| | | | | | | function old new delta arith_apply 1143 1132 -11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix the order of variable resolution in binopsDenys Vlasenko2023-06-141-12/+15
| | | | | | | function old new delta arith_apply 1134 1143 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: remove now-unused second_valDenys Vlasenko2023-06-141-20/+3
| | | | | | | | | | | function old new delta arith_apply 1137 1134 -3 evaluate_string 1101 1095 -6 arith_lookup_val 150 143 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16) Total: -16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix nested ?: and do not parse variables in not-taken branchDenys Vlasenko2023-06-141-31/+49
| | | | | | | | | | | | Fixes arith-ternary1.tests and arith-ternary_nested.tests function old new delta evaluate_string 1043 1101 +58 arith_apply 1087 1137 +50 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 108/0) Total: 108 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: remove a redundant checkDenys Vlasenko2023-06-141-6/+6
| | | | | | | function old new delta arith_apply 1134 1087 -47 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: document ternary ?: op's weirdness, add code commentsDenys Vlasenko2023-06-141-28/+49
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: fix one name check, other minor cleanupsDenys Vlasenko2023-06-131-8/+12
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell/math: reduce stack usageDenys Vlasenko2023-06-131-30/+36
| | | | | | | | | | | function old new delta arith_apply 1123 1134 +11 arith_lookup_val 140 145 +5 evaluate_string 1053 1047 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 16/-6) Total: 10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: avoid segfault on ${0::0/0~09J}. Closes 15216Denys Vlasenko2023-06-121-4/+35
| | | | | | | function old new delta evaluate_string 1011 1053 +42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: fix parsing of $(( (v)++ + NUM ))Denys Vlasenko2021-09-261-22/+30
| | | | | | | function old new delta evaluate_string 988 1011 +23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: fix arithmentic evaluation of "++7" and such (it is + + 7, i.e. 7)Denys Vlasenko2021-09-251-8/+15
| | | | | | | function old new delta evaluate_string 945 988 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: remove FAST_FUNC from a static functionDenys Vlasenko2020-10-011-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: better comments in BASE#nn codeDenys Vlasenko2019-10-221-10/+14
| | | | | | | function old new delta evaluate_string 932 930 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix BASE###nn bashism for bases 36..64Denys Vlasenko2019-09-221-3/+21
| | | | | | | function old new delta evaluate_string 876 932 +56 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: fix BASE###nn bashism to accept letter 'digits' for bases > 9Denys Vlasenko2019-09-221-2/+9
| | | | | | | function old new delta evaluate_string 873 876 +3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: move all definitions of strto_arith_t() togetherDenys Vlasenko2019-05-261-3/+7
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: implement optional "BASE#nnnn" numeric literalsDenys Vlasenko2019-05-191-0/+36
| | | | | | | function old new delta evaluate_string 729 851 +122 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: handle $((NUM++...) like bash does. Closes 10706Denys Vlasenko2018-01-281-2/+17
| | | | | | | function old new delta evaluate_string 680 729 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* do not use `a' quoting style in commentsDenys Vlasenko2017-08-021-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* typo fix in commentDenys Vlasenko2014-11-201-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>