Commit Graph

26 Commits

Author SHA1 Message Date
Rosen Penev
0dfa7421f3 [clang-tidy] Convert C casts to C++ ones
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Ankush Patil
ee982c4f6c Fixes #6280 : Added right associativity to 'pow' function 2019-11-13 13:51:01 -08:00
Fabian Homborg
c0d8439f3a math: Print special error for logical operators
Until now, something like

`math '7 = 2'`

would complain about a "missing" operator.

Now we print an error about logical operators not being supported and
point the user towards `test`.

Fixes #6096
2019-11-01 08:43:13 +01:00
0x005c
067b30208d Fix math incorrect parenthesis error on missing term 2019-10-31 22:10:54 +01:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
Mahmoud Al-Qudsi
cfe1f1db9e Fix build on FreeBSD 12.0 with stock Clang
`isspace()` is in `ctype.h`.
2019-06-10 16:51:42 -05:00
Fabian Homborg
d1ca392393 math: Allow "x" for multiplication
It's always a bit annoying that `*` requires quoting.

So we allow "x" as an alternative, only it needs to be followed by
whitespace to distinguish it from "0x" hexadecimal notation.
2019-06-10 18:45:10 +02:00
Fabian Homborg
e895cef245 tinyexpr: Correct pi type 2019-05-29 20:50:35 +02:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
Aaron Gyes
09e8f0fd7c rearrange structure fields
Putting larger members before smaller ones will reduce structure
sizes. bools are 1 byte. on 64bit systems I think they reduced:

wgetopt.h:46: 64 to 56 bytes
builtin_history.cpp:30: 48 to 32 bytes
builtin_status.cpp:91: 32 to 24 bytes
tinyexpr.cpp:69: 40 to 32 bytes
2019-04-04 13:47:10 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
ridiculousfish
26ada583a0 Fix te_expr's flexible array member
te_expr has a flexible array member, but it's declared as size 1.
Stop declaring its size so UBSan stops complaining.

Noted in #2852
2019-02-05 23:03:59 -08:00
Fabian Homborg
9f469e576b tinyexpr: Prevent possible division by zero
This is possibly not actually undefined behavior because IEEE754
defines _more_ of division-by-zero, but let's be careful.

Fixes #2852.
2019-02-04 16:32:53 +01:00
Aaron Gyes
6ef617f8e7 tinyexpr: use math.h constants, constexpr 2019-01-25 17:08:15 -08:00
Fabian Homborg
a615151d91 Revert "tinyexpr: Make te_expr a class"
Turns out this crashes on musl when doing te_expr::parameter.push_back(). For some reason.

This reverts commit 2e11e6c692.
2018-12-31 10:37:13 +01:00
Fabian Homborg
e33d29a5d8 tinyexpr: Reserve arity parameters
This somehow fixes heap-buffer-overflow? I thought this was supposed
to be safe.
2018-12-30 20:34:13 +01:00
Fabian Homborg
2e11e6c692 tinyexpr: Make te_expr a class
Removes some #define weirdness.
2018-12-30 19:34:46 +01:00
Fabian Homborg
b8697e7795 tinyexpr: Rename te_variable to te_builtin
Variables aren't a thing here anymore.
2018-12-30 19:34:46 +01:00
Fabian Homborg
a433868363 tinyexpr: Make parameters te_expr* instead of void* 2018-12-30 19:34:46 +01:00
Fabian Homborg
e504faeb38 tinyexpr: Add Comments 2018-12-30 19:34:46 +01:00
Fabian Homborg
c3c1ae18c6 tinyexpr: C++ify find_builtin 2018-12-30 19:34:45 +01:00
Fabian Homborg
b193df8b42 tinyexpr: Move enums together and stop explicit numbering
We should _not_ be doing bit-fiddling with these, so there's no reason
to care about the number.

This also removes the unused "TE_VARIABLE" symbol.
2018-12-30 19:34:45 +01:00
Fabian Homborg
3bbec871e4 tinyexpr: Free all parameters again
This used implicit fallthrough to free all.

We still iterate back-to-front (i--) because maybe that's important?
2018-12-30 19:34:45 +01:00
Fabian Homborg
84ca265b48 tinyexpr: Unfiddle the bits
Mainly this removes the "TYPE_MASK" macro that just masks off the
higher bits, which I don't think were ever actually used.

Much of this seems like anticipation of future direction, but we're
going somewhere else.
2018-12-30 19:34:44 +01:00
Fabian Homborg
61e7f84e29 tinyexpr: Remove PURE flag
This was unused because all functions were marked as pure. We don't
have any plans to add any that aren't, and if we did we'd still have
this in git.
2018-12-30 19:34:41 +01:00
Fabian Homborg
cbc25d7829 [tinyexpr] Port to C++
This removes the need to run c-compilation on one file, and allows us
to in future c++-ify this a bit.

There's a lot of bit-fiddling here that is quite unnecessary, better
error-handling would be nice...

So far this removes a few more unused things (because I would have had
to port them), including:

- Functions with ARITY > 3 (even 3 isn't used, but just so we don't
get complacent)

- Variables

- Most functions moved out of the header, because only te_interp is used.

- The te_print function
2018-12-30 19:34:06 +01:00