feat: add == and != operators for bool, number, and string types with type-checking

Implement equality and inequality operators across three primitive types in the compiler and runtime. Add `bool_eqeq`/`bool_bangeq`, `num_eqeq`/`num_bangeq`, and `string_eqeq`/`string_bangeq` primitives that return false/true respectively when comparing against incompatible types. Update the parse rule table with `INFIX_OPERATOR` macros for `TOKEN_EQEQ` and `TOKEN_BANGEQ` at `PREC_COMPARISON` precedence. Include test files `bool_equality.wren`, `number_equality.wren`, and `string_equality.wren` covering cross-type comparisons and edge cases.
This commit is contained in:
Bob Nystrom
2013-11-05 17:57:57 +00:00
parent c466c60434
commit 8353c26596
7 changed files with 178 additions and 35 deletions
+19
View File
@@ -0,0 +1,19 @@
io.write(123 == 123) // expect: true
io.write(123 == 124) // expect: false
io.write(-3 == 3) // expect: false
// Not equal to other types.
io.write(123 == "123") // expect: false
io.write(1 == true) // expect: false
io.write(0 == false) // expect: false
io.write(123 != 123) // expect: false
io.write(123 != 124) // expect: true
io.write(-3 != 3) // expect: true
// Not equal to other types.
io.write(123 != "123") // expect: true
io.write(1 != true) // expect: true
io.write(0 != false) // expect: true
// TODO(bob): Should 0 == -0?