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.
24 lines
650 B
Plaintext
24 lines
650 B
Plaintext
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
|