feat: add boolean literals and number comparison operators to compiler and VM
Add TOKEN_TRUE/TOKEN_FALSE parsing with boolean() prefix rule emitting CODE_TRUE/CODE_FALSE bytecodes. Wire comparison operators <, >, <=, >= as infix rules with PREC_COMPARISON precedence. Implement num_lt, num_gt, num_lte, num_gte primitives returning bool values. Register boolClass with toString primitive and move class initialization into registerPrimitives(). Add OBJ_TRUE/OBJ_FALSE object types with makeBool() helper and AS_BOOL macro. Include test files for bool_toString and number_comparison.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
io.write(true.toString) // expect: true
|
||||
io.write(false.toString) // expect: false
|
||||
@@ -0,0 +1,17 @@
|
||||
io.write(1 < 2) // expect: true
|
||||
io.write(2 < 2) // expect: false
|
||||
io.write(2 < 1) // expect: false
|
||||
|
||||
io.write(1 <= 2) // expect: true
|
||||
io.write(2 <= 2) // expect: true
|
||||
io.write(2 <= 1) // expect: false
|
||||
|
||||
io.write(1 > 2) // expect: false
|
||||
io.write(2 > 2) // expect: false
|
||||
io.write(2 > 1) // expect: true
|
||||
|
||||
io.write(1 >= 2) // expect: false
|
||||
io.write(2 >= 2) // expect: true
|
||||
io.write(2 >= 1) // expect: true
|
||||
|
||||
// TODO(bob): Wrong type for RHS.
|
||||
Reference in New Issue
Block a user