diff --git a/examples/array/array.q b/examples/array/array.q index 69c3e45..3d8571f 100644 --- a/examples/array/array.q +++ b/examples/array/array.q @@ -8,6 +8,6 @@ main() { buffer[2] = 'l' buffer[3] = 'l' buffer[4] = 'o' - io.out(buffer) + io.write(buffer) mem.free(buffer) } \ No newline at end of file diff --git a/examples/collatz/collatz.q b/examples/collatz/collatz.q index 0b92c3a..5df31c3 100644 --- a/examples/collatz/collatz.q +++ b/examples/collatz/collatz.q @@ -19,6 +19,6 @@ collatz(x int) { return } - io.out(" ") + io.write(" ") } } \ No newline at end of file diff --git a/examples/fizzbuzz/fizzbuzz.q b/examples/fizzbuzz/fizzbuzz.q index bcdc027..3862f0f 100644 --- a/examples/fizzbuzz/fizzbuzz.q +++ b/examples/fizzbuzz/fizzbuzz.q @@ -10,9 +10,9 @@ fizzbuzz(n int) { loop { switch { - x % 15 == 0 { io.out("FizzBuzz") } - x % 5 == 0 { io.out("Buzz") } - x % 3 == 0 { io.out("Fizz") } + x % 15 == 0 { io.write("FizzBuzz") } + x % 5 == 0 { io.write("Buzz") } + x % 3 == 0 { io.write("Fizz") } _ { fmt.decimal(x) } } @@ -22,6 +22,6 @@ fizzbuzz(n int) { return } - io.out(" ") + io.write(" ") } } \ No newline at end of file diff --git a/examples/hello/hello.q b/examples/hello/hello.q index 0475212..05029db 100644 --- a/examples/hello/hello.q +++ b/examples/hello/hello.q @@ -1,5 +1,5 @@ import io main() { - io.out("Hello\n") + io.write("Hello\n") } \ No newline at end of file diff --git a/examples/point/point.q b/examples/point/point.q index de2a763..b34c1cc 100644 --- a/examples/point/point.q +++ b/examples/point/point.q @@ -1,5 +1,5 @@ +import io import mem -import sys Point { x int @@ -29,6 +29,6 @@ print(p *Point) { out[5] = ' ' out[6] = '0' + p.y out[7] = '\n' - sys.write(1, out, 8) + io.write(out) mem.free(out) } \ No newline at end of file diff --git a/examples/prime/prime.q b/examples/prime/prime.q index fae869c..33fcbf5 100644 --- a/examples/prime/prime.q +++ b/examples/prime/prime.q @@ -12,7 +12,7 @@ main() { if isPrime(i) { if i != 2 { - io.out(" ") + io.write(" ") } fmt.decimal(i) diff --git a/examples/server/server.q b/examples/server/server.q index f90c1c7..edb8699 100644 --- a/examples/server/server.q +++ b/examples/server/server.q @@ -6,30 +6,30 @@ main() { socket := sys.socket(2, 1, 0) if socket < 0 { - io.error("socket error\n") + io.write("socket error\n") sys.exit(1) } if net.bind(socket, 8080) != 0 { - io.error("bind error\n") + io.write("bind error\n") sys.exit(1) } if sys.listen(socket, 128) != 0 { - io.error("listen error\n") + io.write("listen error\n") sys.exit(1) } - io.out("listening...\n") + io.write("listening...\n") loop { conn := sys.accept(socket, 0, 0) if conn >= 0 { - io.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n") + io.writeTo(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n") sys.close(conn) } else { - io.error("accept error\n") + io.write("accept error\n") } } } \ No newline at end of file diff --git a/examples/shell/shell.q b/examples/shell/shell.q index f5680d6..c866aa4 100644 --- a/examples/shell/shell.q +++ b/examples/shell/shell.q @@ -7,7 +7,7 @@ main() { command := mem.alloc(length) loop { - io.out("λ ") + io.write("λ ") n := io.in(command) if n <= 0 { diff --git a/examples/thread/thread.q b/examples/thread/thread.q index b878ce8..d8d8960 100644 --- a/examples/thread/thread.q +++ b/examples/thread/thread.q @@ -10,6 +10,6 @@ main() { } work() { - io.out("[ ] start\n") - io.out("[x] end\n") + io.write("[ ] start\n") + io.write("[x] end\n") } \ No newline at end of file diff --git a/lib/io/io.q b/lib/io/io.q index 98ee9fe..730ddf1 100644 --- a/lib/io/io.q +++ b/lib/io/io.q @@ -1,17 +1,3 @@ -import sys - -in(buffer []byte) -> int { - return sys.read(std.in, buffer, len(buffer)) -} - -out(buffer []byte) -> int { - return sys.write(std.out, buffer, len(buffer)) -} - -error(buffer []byte) -> int { - return sys.write(std.err, buffer, len(buffer)) -} - const { std { in 0 diff --git a/lib/io/read.q b/lib/io/read.q index 7756c17..deb777b 100644 --- a/lib/io/read.q +++ b/lib/io/read.q @@ -1,5 +1,9 @@ import sys -read(fd int, buffer []byte) -> int { +read(buffer []byte) -> int { + return sys.read(std.in, buffer, len(buffer)) +} + +readFrom(fd int, buffer []byte) -> int { return sys.read(fd, buffer, len(buffer)) } \ No newline at end of file diff --git a/lib/io/write.q b/lib/io/write.q index a46a22d..9d107dc 100644 --- a/lib/io/write.q +++ b/lib/io/write.q @@ -1,5 +1,9 @@ import sys -write(fd int, buffer []byte) -> int { +write(buffer []byte) -> int { + return sys.write(std.out, buffer, len(buffer)) +} + +writeTo(fd int, buffer []byte) -> int { return sys.write(fd, buffer, len(buffer)) } \ No newline at end of file