raygard / wak

wak -- an awk implementation for toybox and standalone
BSD Zero Clause License
52 stars 2 forks source link

Add gawk bitwise functions (and, or, xor, lshift, rshift) and test cases #4

Closed oliverkwebb closed 2 months ago

oliverkwebb commented 3 months ago

Adding these functions is pretty straightforward, also added test cases for them and some other builtin functions.

oguz-ismail commented 3 months ago

In order to prevent inconsistent results across platforms these functions don't accept negative arguments in gawk.

$ exe/wak 'BEGIN{print and(-1,1)}'
1
$ gawk 'BEGIN{print and(-1,1)}'
gawk: cmd. line:1: fatal: and: argument 1 negative value -1 is not allowed

There is also this:

$ gawk 'BEGIN{print lshift(9000000000000000000,1)}'
18000000000000000000
$ exe/wak 'BEGIN{print lshift(9000000000000000000,1)}'
-446744073709551616

push_int_val takes an argument of type ptrdiff_t, you call it with an argument of type size_t which may be greater than PTRDIFF_MAX and lead to an implementation-defined result.