Commit Graph

43 Commits

Author SHA1 Message Date
Fabian Homborg
14908322a9 Also include fallback.h
GRrrrrr
2020-12-14 23:23:00 +01:00
Fabian Homborg
0f5a226e2f math: Use fish_wcstod instead
1. This should be using our wcstod_l on platforms where we need
it (for some reason it wasn't picking it up on FreeBSD?)

2. This purports to have a "fast path". I like fast paths.
2020-12-14 23:09:01 +01:00
Fabian Homborg
e94f86e6d2 math: Use wcstod_l
Locale-wise, we're only interested in one thing:

"." is the radix character when interpreting numbers

And for that it's enough to just use our c-locale, like elsewhere.

This saves a bunch of switching locale back and forth, and simplifies
the code.
2020-12-14 22:58:47 +01:00
Fabian Homborg
97cd87f3b2 math: Use wchar
This was doing a bunch of work narrowing strings for no reason.
2020-12-14 22:54:53 +01:00
Fabian Homborg
ab5d7f80d0 Restyle codebase
And again clang-format does something I don't like:

-    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0) return found;
+    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0)
+        return found;

I *know* this is a bit of a long line. I would still quite like having
no brace-less multi-line if *ever*. Either put the body on the same
line, or add braces.

Blergh
2020-12-06 15:39:54 +01:00
Fabian Homborg
a14e64ed6c math: Don't override errors with "unexpected token"
As always, we want to give the most specific error we can.

Fixes #7508
2020-11-26 12:41:19 +01:00
Fabian Homborg
903a9fbf0c math: Don't match longer function names
The comparison here is a bit naive, so "n" matches "ncr", so
technically

   math 'n(2, 3)'

is equivalent to

   math 'ncr(2, 3)'

Work towards #7508.
2020-11-26 12:37:09 +01:00
Fabian Homborg
a84d57b02b math: Actually report closing paren error
This was typically overridden by "too many/few arguments", but it's
actually incorrect:

    sin(55

has the correct number of arguments to `sin`, but it's lacking
the closing `)`.
2020-10-26 18:13:43 +01:00
Johannes Altmanninger
fbaa5d193d Declare functions in headers or use internal linkage (static)
Found with gcc's -Wmissing-declarations which gives warnings like

	../src/tinyexpr.cpp:61:5: warning: no previous declaration for ‘int get_arity(int)’ [-Wmissing-declarations]
	   61 | int get_arity(const int type) {

The same warnings show up for builtin functions like builtin_bg because they
currently don't include their own headers. I left that.
Also reformat the touched files.
2020-09-08 22:44:03 +02:00
Fabian Homborg
5eb4de4285 math: Implement tau 2020-08-26 17:48:58 +02:00
Fabian Homborg
5b1c000a2e math: Add bitwise and/or functions
Just as `math "bitand(5,3)"` and `math "bitor(6,2)"`.

These cast to long long before doing their thing,
so they truncate to an integer, producing weird results with floats.

That's to be expected because float representation is *very*
different, and performing bitwise operations on floats feels quite useless.

Fixes #7281.
2020-08-26 17:48:58 +02:00
Rosen Penev
0668513138 Change C casts to C++ ones
Some were kept for compatibility.

Found with -Wold-style-cast

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-05-01 13:30:56 -07:00
Rosen Penev
8d3377e923 [clang-tidy] Use C++ using instead of typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
220f0a132d [clang-tidy] use auto when casting
Found with modernize-use-auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Fabian Homborg
921fce3a51 math: Complain about unknown *function*, not *variable*
We removed variables from tinyexpr, so we shouldn't use that error.
2020-02-07 17:43:22 +01:00
Rosen Penev
6f4a9d527c [clang-tidy] Use C++ using instead of C typedef
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
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