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:
Bob Nystrom
2013-11-04 05:38:58 +00:00
parent 0fc8432442
commit 074deebdfd
6 changed files with 146 additions and 14 deletions
+2
View File
@@ -0,0 +1,2 @@
io.write(true.toString) // expect: true
io.write(false.toString) // expect: false
+17
View File
@@ -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.