Implemented length storage of allocated memory
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import io
|
||||
import log
|
||||
import sys
|
||||
|
||||
main() {
|
||||
collatz(12)
|
||||
@ -19,6 +19,6 @@ collatz(x Int) {
|
||||
return
|
||||
}
|
||||
|
||||
sys.write(1, " ", 1)
|
||||
io.out(" ")
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import io
|
||||
import log
|
||||
import sys
|
||||
|
||||
main() {
|
||||
fizzbuzz(15)
|
||||
@ -10,9 +10,9 @@ fizzbuzz(n Int) {
|
||||
|
||||
loop {
|
||||
switch {
|
||||
x % 15 == 0 { print("FizzBuzz", 8) }
|
||||
x % 5 == 0 { print("Buzz", 4) }
|
||||
x % 3 == 0 { print("Fizz", 4) }
|
||||
x % 15 == 0 { io.out("FizzBuzz") }
|
||||
x % 5 == 0 { io.out("Buzz") }
|
||||
x % 3 == 0 { io.out("Fizz") }
|
||||
_ { log.number(x) }
|
||||
}
|
||||
|
||||
@ -22,10 +22,6 @@ fizzbuzz(n Int) {
|
||||
return
|
||||
}
|
||||
|
||||
print(" ", 1)
|
||||
io.out(" ")
|
||||
}
|
||||
}
|
||||
|
||||
print(address Pointer, length Int) {
|
||||
sys.write(1, address, length)
|
||||
}
|
@ -1,9 +1,5 @@
|
||||
import sys
|
||||
import io
|
||||
|
||||
main() {
|
||||
print("Hello\n", 6)
|
||||
}
|
||||
|
||||
print(address Pointer, length Int) {
|
||||
sys.write(1, address, length)
|
||||
io.out("Hello\n")
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import io
|
||||
import log
|
||||
import sys
|
||||
|
||||
main() {
|
||||
n := 100
|
||||
@ -12,7 +12,7 @@ main() {
|
||||
|
||||
if isPrime(i) == 1 {
|
||||
if i != 2 {
|
||||
sys.write(1, " ", 1)
|
||||
io.out(" ")
|
||||
}
|
||||
|
||||
log.number(i)
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Open server and client in 2 terminals:
|
||||
// [1] q run examples/server
|
||||
// [2] curl http://127.0.0.1:8080
|
||||
import io
|
||||
import net
|
||||
import sys
|
||||
|
||||
@ -8,30 +9,30 @@ main() {
|
||||
socket := sys.socket(2, 1, 0)
|
||||
|
||||
if socket < 0 {
|
||||
sys.write(1, "socket error\n", 13)
|
||||
io.error("socket error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
if net.bind(socket, 8080) != 0 {
|
||||
sys.write(1, "bind error\n", 11)
|
||||
io.error("bind error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
if sys.listen(socket, 128) != 0 {
|
||||
sys.write(1, "listen error\n", 13)
|
||||
io.error("listen error\n")
|
||||
sys.exit(1)
|
||||
}
|
||||
|
||||
sys.write(1, "listening...\n", 13)
|
||||
io.out("listening...\n")
|
||||
|
||||
loop {
|
||||
conn := sys.accept(socket, 0, 0)
|
||||
|
||||
if conn >= 0 {
|
||||
sys.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n", 44)
|
||||
io.write(conn, "HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nHello\n")
|
||||
sys.close(conn)
|
||||
} else {
|
||||
sys.write(1, "error\n", 6)
|
||||
io.error("accept error\n")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import io
|
||||
import mem
|
||||
import sys
|
||||
|
||||
@ -9,8 +10,8 @@ main() {
|
||||
info := mem.alloc(24)
|
||||
|
||||
loop {
|
||||
sys.write(1, "$ ", 2)
|
||||
n := sys.read(0, command, length)
|
||||
io.out("$ ")
|
||||
n := io.in(command)
|
||||
|
||||
if n <= 0 {
|
||||
return
|
||||
|
@ -1,3 +1,4 @@
|
||||
import io
|
||||
import sys
|
||||
import thread
|
||||
import time
|
||||
@ -10,8 +11,8 @@ main() {
|
||||
}
|
||||
|
||||
work() {
|
||||
sys.write(1, "[ ] start\n", 10)
|
||||
io.out("[ ] start\n")
|
||||
time.sleep(10 * 1000 * 1000)
|
||||
sys.write(1, "[x] end\n", 8)
|
||||
io.out("[x] end\n")
|
||||
sys.exit(0)
|
||||
}
|
Reference in New Issue
Block a user