bit and, or, not, xor, shifts, wraps. Also checked and wrapping variants; those can just be builtin functions for now, or possibly a module?
Basic bitops implemented based on luajit's, http://bitop.luajit.org/ . For i32 only right now, but I guess. Doesn't have rotates or other stuff yet, and it's just compiler builtins, but I guess it's a start.
These are now implemented better, and are a great argument for having sigils for most of these operations rather than functions.
__i64_to_i32(__rshift_i64(__bxor_i64(__rshift_i64(oldstate, 18), oldstate), 27))
is pretty... vivid.
WARNING, WARNING, two potentially derailing tangents approaching!
- If garnet aims to have (and already has?) UFCS and generics, doesn't that already become somewhat more manageable even in function form? e.g.:
oldstate :__rshift(18) :__bxor(oldstate) :__rshift(27) :__to_i32()
? Isn't this one of the big appeals/selling-points of UFCS?- I've seen people start to complain that there are many more "mathy planes" where expressions also become "vivid", e.g. matrix arithmetics - thus arguing for operator overloading. (Interestingly to me, I feel that both Nim and OCaml seem to have somehow allowed operator overloading yet still managed to keep it in sane area, maybe through culture - as opposed IMO to Haskell in one troublesome corner, and C++ in another troublesome corner.)
- Garnet had UFCS but that kinda got left behind when modules got implemented, so it's currently either absent or probably-broken; I forget which. It's probably worth giving it some love again. Apparently I made it work again in The Great Significant-Newline-Ification? See
tests/programs/ufcs.gt
, but there may be things about it still broken that I've forgotten.- Operator overloading is its own pile of problems, my vague plan is to make it Rust-like... present but minimal and a bit limited. I think culture is a big part of that; C++ and Haskell both give newbies some very bad examples of what "normal" should look like. Kinda surprised I don't have a design issue on operator overloading somewhere; it's just something I always new but never wrote down, I guess? Feel free to make one if you wanna discuss more.
Syntax bikeshed here: https://todo.sr.ht/~icefox/garnet/67. Right now I've just chosen the stupidest possible names,
bitadn
andbitor
and such. The frontend is implemented, but it doesn't lower to HIR yet and the typechecker doesn't know what to do with em.