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:
@@ -4,5 +4,5 @@ class Foo {
|
||||
|
||||
// Classes inherit the argument-less "new" one by default.
|
||||
var foo = new Foo
|
||||
IO.write(foo is Foo) // expect: true
|
||||
IO.write(foo.toString) // expect: Foo
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
|
||||
@@ -2,6 +2,6 @@ class Foo {
|
||||
+ other { return "Foo " + other }
|
||||
}
|
||||
|
||||
IO.write(new Foo + "value") // expect: Foo value
|
||||
IO.print(new Foo + "value") // expect: Foo value
|
||||
|
||||
// TODO: Other expressions following a constructor, like new Foo.bar("arg").
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Foo {
|
||||
new { IO.write("zero") }
|
||||
new(a) { IO.write(a) }
|
||||
new(a, b) { IO.write(a + b) }
|
||||
new { IO.print("zero") }
|
||||
new(a) { IO.print(a) }
|
||||
new(a, b) { IO.print(a + b) }
|
||||
|
||||
toString { return "Foo" }
|
||||
}
|
||||
@@ -13,5 +13,5 @@ new Foo("one", "two") // expect: onetwo
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = new Foo // expect: zero
|
||||
IO.write(foo is Foo) // expect: true
|
||||
IO.write(foo.toString) // expect: Foo
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class A {
|
||||
new(arg) {
|
||||
IO.write("new A " + arg)
|
||||
IO.print("new A " + arg)
|
||||
_field = arg
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class A {
|
||||
class B is A {
|
||||
new(arg1, arg2) {
|
||||
super(arg2)
|
||||
IO.write("new B " + arg1)
|
||||
IO.print("new B " + arg1)
|
||||
_field = arg1
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class B is A {
|
||||
class C is B {
|
||||
new {
|
||||
super("one", "two")
|
||||
IO.write("new C")
|
||||
IO.print("new C")
|
||||
_field = "c"
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ var c = new C
|
||||
// expect: new A two
|
||||
// expect: new B one
|
||||
// expect: new C
|
||||
IO.write(c is A) // expect: true
|
||||
IO.write(c is B) // expect: true
|
||||
IO.write(c is C) // expect: true
|
||||
IO.print(c is A) // expect: true
|
||||
IO.print(c is B) // expect: true
|
||||
IO.print(c is C) // expect: true
|
||||
|
||||
IO.write(c.aField) // expect: two
|
||||
IO.write(c.bField) // expect: one
|
||||
IO.write(c.cField) // expect: c
|
||||
IO.print(c.aField) // expect: two
|
||||
IO.print(c.bField) // expect: one
|
||||
IO.print(c.cField) // expect: c
|
||||
|
||||
Reference in New Issue
Block a user