feat: rename IO.write to IO.print and add Unicode escape support in strings
Rename the IO.write method to IO.print, which now prints without a trailing newline, and add a new IO.print method that appends a newline after output. Update all benchmark, example, and test files to use IO.print instead of IO.write. Additionally, implement Unicode escape sequence parsing in the compiler's string tokenizer, supporting \uXXXX and \u{...} syntax with proper UTF-8 encoding for code points up to U+10FFFF.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
IO.write(123.abs) // expect: 123
|
||||
IO.write(-123.abs) // expect: 123
|
||||
IO.write(0.abs) // expect: 0
|
||||
IO.write(-0.abs) // expect: 0
|
||||
IO.write(-0.12.abs) // expect: 0.12
|
||||
IO.write(12.34.abs) // expect: 12.34
|
||||
IO.print(123.abs) // expect: 123
|
||||
IO.print(-123.abs) // expect: 123
|
||||
IO.print(0.abs) // expect: 0
|
||||
IO.print(-0.abs) // expect: 0
|
||||
IO.print(-0.12.abs) // expect: 0.12
|
||||
IO.print(12.34.abs) // expect: 12.34
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
IO.write(~0) // expect: 4294967295
|
||||
IO.write(~1) // expect: 4294967294
|
||||
IO.write(~23) // expect: 4294967272
|
||||
IO.print(~0) // expect: 4294967295
|
||||
IO.print(~1) // expect: 4294967294
|
||||
IO.print(~23) // expect: 4294967272
|
||||
|
||||
// Max u32 value.
|
||||
IO.write(~4294967295) // expect: 0
|
||||
IO.print(~4294967295) // expect: 0
|
||||
|
||||
// Past max u32 value.
|
||||
IO.write(~4294967296) // expect: 4294967295
|
||||
IO.print(~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
|
||||
IO.print(~-1) // expect: 0
|
||||
IO.print(~-123) // expect: 122
|
||||
IO.print(~-4294967294) // expect: 4294967293
|
||||
IO.print(~-4294967295) // expect: 4294967294
|
||||
IO.print(~-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
|
||||
IO.print(~1.23) // expect: 4294967294
|
||||
IO.print(~0.00123) // expect: 4294967295
|
||||
IO.print(~345.67) // expect: 4294966950
|
||||
IO.print(~-12.34) // expect: 11
|
||||
|
||||
+20
-20
@@ -1,27 +1,27 @@
|
||||
IO.write(1 < 2) // expect: true
|
||||
IO.write(2 < 2) // expect: false
|
||||
IO.write(2 < 1) // expect: false
|
||||
IO.print(1 < 2) // expect: true
|
||||
IO.print(2 < 2) // expect: false
|
||||
IO.print(2 < 1) // expect: false
|
||||
|
||||
IO.write(1 <= 2) // expect: true
|
||||
IO.write(2 <= 2) // expect: true
|
||||
IO.write(2 <= 1) // expect: false
|
||||
IO.print(1 <= 2) // expect: true
|
||||
IO.print(2 <= 2) // expect: true
|
||||
IO.print(2 <= 1) // expect: false
|
||||
|
||||
IO.write(1 > 2) // expect: false
|
||||
IO.write(2 > 2) // expect: false
|
||||
IO.write(2 > 1) // expect: true
|
||||
IO.print(1 > 2) // expect: false
|
||||
IO.print(2 > 2) // expect: false
|
||||
IO.print(2 > 1) // expect: true
|
||||
|
||||
IO.write(1 >= 2) // expect: false
|
||||
IO.write(2 >= 2) // expect: true
|
||||
IO.write(2 >= 1) // expect: true
|
||||
IO.print(1 >= 2) // expect: false
|
||||
IO.print(2 >= 2) // expect: true
|
||||
IO.print(2 >= 1) // expect: true
|
||||
|
||||
// Zero and negative zero compare the same.
|
||||
IO.write(0 < -0) // expect: false
|
||||
IO.write(-0 < 0) // expect: false
|
||||
IO.write(0 > -0) // expect: false
|
||||
IO.write(-0 > 0) // expect: false
|
||||
IO.write(0 <= -0) // expect: true
|
||||
IO.write(-0 <= 0) // expect: true
|
||||
IO.write(0 >= -0) // expect: true
|
||||
IO.write(-0 >= 0) // expect: true
|
||||
IO.print(0 < -0) // expect: false
|
||||
IO.print(-0 < 0) // expect: false
|
||||
IO.print(0 > -0) // expect: false
|
||||
IO.print(-0 > 0) // expect: false
|
||||
IO.print(0 <= -0) // expect: true
|
||||
IO.print(-0 <= 0) // expect: true
|
||||
IO.print(0 >= -0) // expect: true
|
||||
IO.print(-0 >= 0) // expect: true
|
||||
|
||||
// TODO: Wrong type for RHS.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.write(8 / 2) // expect: 4
|
||||
IO.write(12.34 / -0.4) // expect: -30.85
|
||||
IO.print(8 / 2) // expect: 4
|
||||
IO.print(12.34 / -0.4) // expect: -30.85
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
// TODO: Divide by zero.
|
||||
|
||||
+14
-14
@@ -1,19 +1,19 @@
|
||||
IO.write(123 == 123) // expect: true
|
||||
IO.write(123 == 124) // expect: false
|
||||
IO.write(-3 == 3) // expect: false
|
||||
IO.write(0 == -0) // expect: true
|
||||
IO.print(123 == 123) // expect: true
|
||||
IO.print(123 == 124) // expect: false
|
||||
IO.print(-3 == 3) // expect: false
|
||||
IO.print(0 == -0) // expect: true
|
||||
|
||||
// Not equal to other types.
|
||||
IO.write(123 == "123") // expect: false
|
||||
IO.write(1 == true) // expect: false
|
||||
IO.write(0 == false) // expect: false
|
||||
IO.print(123 == "123") // expect: false
|
||||
IO.print(1 == true) // expect: false
|
||||
IO.print(0 == false) // expect: false
|
||||
|
||||
IO.write(123 != 123) // expect: false
|
||||
IO.write(123 != 124) // expect: true
|
||||
IO.write(-3 != 3) // expect: true
|
||||
IO.write(0 != -0) // expect: false
|
||||
IO.print(123 != 123) // expect: false
|
||||
IO.print(123 != 124) // expect: true
|
||||
IO.print(-3 != 3) // expect: true
|
||||
IO.print(0 != -0) // expect: false
|
||||
|
||||
// Not equal to other types.
|
||||
IO.write(123 != "123") // expect: true
|
||||
IO.write(1 != true) // expect: true
|
||||
IO.write(0 != false) // expect: true
|
||||
IO.print(123 != "123") // expect: true
|
||||
IO.print(1 != true) // expect: true
|
||||
IO.print(0 != false) // expect: true
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
IO.write(123) // expect: 123
|
||||
IO.write(987654) // expect: 987654
|
||||
IO.write(0) // expect: 0
|
||||
IO.write(-0) // expect: -0
|
||||
IO.print(123) // expect: 123
|
||||
IO.print(987654) // expect: 987654
|
||||
IO.print(0) // expect: 0
|
||||
IO.print(-0) // expect: -0
|
||||
|
||||
IO.write(123.456) // expect: 123.456
|
||||
IO.write(-0.001) // expect: -0.001
|
||||
IO.print(123.456) // expect: 123.456
|
||||
IO.print(-0.001) // expect: -0.001
|
||||
|
||||
// TODO: Hex? Scientific notation?
|
||||
// TODO: Literals at and beyond numeric limits.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Infix.
|
||||
IO.write(5 - 3) // expect: 2
|
||||
IO.write(3.1 - 0.24) // expect: 2.86
|
||||
IO.write(3 - 2 - 1) // expect: 0
|
||||
IO.print(5 - 3) // expect: 2
|
||||
IO.print(3.1 - 0.24) // expect: 2.86
|
||||
IO.print(3 - 2 - 1) // expect: 0
|
||||
|
||||
// Unary negation.
|
||||
var a = 3
|
||||
IO.write(-a) // expect: -3
|
||||
IO.print(-a) // expect: -3
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
IO.write(5 % 3) // expect: 2
|
||||
IO.write(10 % 5) // expect: 0
|
||||
IO.write(-4 % 3) // expect: -1
|
||||
IO.write(4 % -3) // expect: 1
|
||||
IO.write(-4 % -3) // expect: -1
|
||||
IO.write(-4.2 % 3.1) // expect: -1.1
|
||||
IO.write(4.2 % -3.1) // expect: 1.1
|
||||
IO.write(-4.2 % -3.1) // expect: -1.1
|
||||
IO.print(5 % 3) // expect: 2
|
||||
IO.print(10 % 5) // expect: 0
|
||||
IO.print(-4 % 3) // expect: -1
|
||||
IO.print(4 % -3) // expect: 1
|
||||
IO.print(-4 % -3) // expect: -1
|
||||
IO.print(-4.2 % 3.1) // expect: -1.1
|
||||
IO.print(4.2 % -3.1) // expect: 1.1
|
||||
IO.print(-4.2 % -3.1) // expect: -1.1
|
||||
|
||||
// Left associative.
|
||||
IO.write(13 % 7 % 4) // expect: 2
|
||||
IO.print(13 % 7 % 4) // expect: 2
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
// TODO: Error on mod by zero.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.write(5 * 3) // expect: 15
|
||||
IO.write(12.34 * 0.3) // expect: 3.702
|
||||
IO.print(5 * 3) // expect: 15
|
||||
IO.print(12.34 * 0.3) // expect: 3.702
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.write(1 + 2) // expect: 3
|
||||
IO.write(12.34 + 0.13) // expect: 12.47
|
||||
IO.write(3 + 5 + 2) // expect: 10
|
||||
IO.print(1 + 2) // expect: 3
|
||||
IO.print(12.34 + 0.13) // expect: 12.47
|
||||
IO.print(3 + 5 + 2) // expect: 10
|
||||
|
||||
// TODO: Unsupported RHS types.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var inclusive = 2..5
|
||||
IO.write(inclusive is Range) // expect: true
|
||||
IO.write(inclusive.min) // expect: 2
|
||||
IO.write(inclusive.max) // expect: 5
|
||||
IO.print(inclusive is Range) // expect: true
|
||||
IO.print(inclusive.min) // expect: 2
|
||||
IO.print(inclusive.max) // expect: 5
|
||||
|
||||
var exclusive = 2...5
|
||||
IO.write(exclusive is Range) // expect: true
|
||||
IO.write(exclusive.min) // expect: 2
|
||||
IO.write(exclusive.max) // expect: 4
|
||||
IO.print(exclusive is Range) // expect: true
|
||||
IO.print(exclusive.min) // expect: 2
|
||||
IO.print(exclusive.max) // expect: 4
|
||||
|
||||
// TODO: Non-number RHS.
|
||||
// TODO: Non-integer RHS.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
IO.write(123.toString == "123") // expect: true
|
||||
IO.write(-123.toString == "-123") // expect: true
|
||||
IO.write(-0.toString == "-0") // expect: true
|
||||
IO.write(12.34.toString == "12.34") // expect: true
|
||||
IO.write(-0.0001.toString == "-0.0001") // expect: true
|
||||
IO.print(123.toString == "123") // expect: true
|
||||
IO.print(-123.toString == "-123") // expect: true
|
||||
IO.print(-0.toString == "-0") // expect: true
|
||||
IO.print(12.34.toString == "12.34") // expect: true
|
||||
IO.print(-0.0001.toString == "-0.0001") // expect: true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
IO.write(123 is Num) // expect: true
|
||||
IO.write(123 is Object) // expect: true
|
||||
IO.write(123 is String) // expect: false
|
||||
IO.write(123.type == Num) // expect: true
|
||||
IO.print(123 is Num) // expect: true
|
||||
IO.print(123 is Object) // expect: true
|
||||
IO.print(123 is String) // expect: false
|
||||
IO.print(123.type == Num) // expect: true
|
||||
|
||||
Reference in New Issue
Block a user