feat: add bitwise NOT operator (~) with token, parser, and native implementation
Add TOKEN_TILDE token type and lexer support for the '~' character in the compiler. Implement the bitwise NOT operation as a native method on the Num class, operating on 32-bit unsigned integers. Include a new OPERATOR macro for prefix/infix operator grammar rules and add comprehensive test cases covering positive, negative, floating-point, and boundary values.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
var a = "a"
|
||||
var b = "b"
|
||||
var c = "c"
|
||||
|
||||
// Assignment is right-associative.
|
||||
a = b = c
|
||||
io.write(a) // expect: c
|
||||
io.write(b) // expect: c
|
||||
io.write(c) // expect: c
|
||||
@@ -0,0 +1,23 @@
|
||||
io.write(~0) // expect: 4294967295
|
||||
io.write(~1) // expect: 4294967294
|
||||
io.write(~23) // expect: 4294967272
|
||||
|
||||
// Max u32 value.
|
||||
io.write(~4294967295) // expect: 0
|
||||
|
||||
// Past max u32 value.
|
||||
// TODO(bob): Is this right?
|
||||
io.write(~4294967296) // expect: 4294967295
|
||||
|
||||
// Negative numbers.
|
||||
io.write(~-1) // expect: 0
|
||||
io.write(~-123) // expect: 122
|
||||
io.write(~-4294967294) // expect: 4294967293
|
||||
io.write(~-4294967295) // expect: 4294967294
|
||||
io.write(~-4294967296) // expect: 4294967295
|
||||
|
||||
// Floating point values.
|
||||
io.write(~1.23) // expect: 4294967294
|
||||
io.write(~0.00123) // expect: 4294967295
|
||||
io.write(~345.67) // expect: 4294966950
|
||||
io.write(~-12.34) // expect: 11
|
||||
Reference in New Issue
Block a user