type inference for variables

This commit is contained in:
2026-05-13 14:01:44 +02:00
parent 5f2082ef57
commit 027245684d
37 changed files with 304 additions and 302 deletions

View File

@@ -3,7 +3,7 @@ func main[argc: i64, argv: ptr] : i64
io.println("ERROR: url is missing")
return 1
let url: str = mem.read64(argv + 8) as str
let url = mem.read64(argv + 8) as str
if str.len(url) <= 7
io.println("ERROR: invalid url (Did you forget \"http://\"?)")
@@ -13,16 +13,16 @@ func main[argc: i64, argv: ptr] : i64
io.println("ERROR: only http scheme is supported")
return 1
let url_len: i64 = str.len(url)
let url_len = str.len(url)
let host_start = 7
let i: i64 = host_start
let i = host_start
while i < url_len
if url[i] == '/'
break
i = i + 1
let host: str = str.substr(url, host_start, i - host_start)
let path: str = "/"
let host = str.substr(url, host_start, i - host_start)
let path = "/"
if i < url_len
path = str.substr(url, i, url_len - i)
@@ -31,7 +31,7 @@ func main[argc: i64, argv: ptr] : i64
let s: i64 = must(net.connect?(addr, 80))
// TODO: add string builder to std
let req: str = "GET "
let req = "GET "
req = str.concat(req, path)
req = str.concat(req, " HTTP/1.0\r\nHost: ")
req = str.concat(req, host)
@@ -39,16 +39,16 @@ func main[argc: i64, argv: ptr] : i64
net.send(s, req as ptr, str.len(req))
mem.free(req)
let header_buf: str = mem.alloc(8192) as str
let header_buf = mem.alloc(8192) as str
let header_size = 0
let found: bool = false
let end_index: i64 = -1
let found = false
let end_index = -1
while !found && header_size < 8192
let n: i64 = net.read(s, header_buf as ptr + header_size, 8192 - header_size)
let n = net.read(s, header_buf as ptr + header_size, 8192 - header_size)
if n <= 0
break
let current_size: i64 = header_size + n
let current_size = header_size + n
i = 0
while i <= current_size - 4
if header_buf[i] == '\r' && header_buf[i + 1] == '\n' && header_buf[i + 2] == '\r' && header_buf[i + 3] == '\n'
@@ -62,9 +62,9 @@ func main[argc: i64, argv: ptr] : i64
io.print_sized(header_buf as ptr + end_index, header_size as i64 - end_index)
mem.free(header_buf)
let buffer: ptr = mem.alloc(4096)
let buffer = mem.alloc(4096)
while true
let n: i64 = net.read(s, buffer, 4096)
let n = net.read(s, buffer, 4096)
if n <= 0
break
io.print_sized(buffer, n)