replace the horrible error system with multiple returns

This commit is contained in:
2026-05-28 17:28:57 +02:00
parent 0b16cc4513
commit f181cfe675
18 changed files with 138 additions and 199 deletions

View File

@@ -290,7 +290,9 @@ func main[argc: i64, argv: ptr] : i64
c := chip8_create()
buffer : Blob = must(io.read_binary_file?(path))
~buffer, ok := io.read_binary_file(path)
if !ok
panic("failed to read file")
for i in 0..buffer->size
c->memory[0x200 + i] = buffer->data[i]

View File

@@ -26,9 +26,13 @@ func main[argc: i64, argv: ptr] : i64
if i < url_len
path = str.substr(url, i, url_len - i)
addr : i64 = must(net.resolve?(host))
~addr, ok := net.resolve(host)
if !ok
panic("failed to resolve host")
s : i64 = must(net.connect?(addr, 80))
~s, ok := net.connect(addr, 80)
if !ok
panic("failed to connect")
// TODO: add string builder to std
req := "GET "

View File

@@ -15,7 +15,11 @@ func part2[l1: Array, l2: Array] : void
io.println_i64(out)
func main[] : i64
lines : Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
l1 := []
l2 := []

View File

@@ -40,7 +40,11 @@ func part2[data: Array] : void
io.println_i64(out)
func main[] : i64
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
data := []
for i in 0..lines->size

View File

@@ -56,7 +56,11 @@ func part2[lines: Array] : void
io.println_i64(out)
func main[] : i64
lines : Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
part1(lines)
part2(lines)

View File

@@ -47,7 +47,11 @@ func part2[updates: Array, rules_left: Array, rules_right: Array] : void
io.println_i64(out)
func main[] : i64
data := must(io.read_text_file?("input.txt")) |> str.split("\n\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
data := str.split(input, "\n\n")
rules_left := []
rules_right := []

View File

@@ -61,7 +61,11 @@ func part2[equations: Array] : void
io.println_i64(out)
func main[] : i64
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
equations := []
for i in 0..lines->size

View File

@@ -47,7 +47,11 @@ func part2[lines: Array] : void
io.println_i64(password)
func main[] : i64
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
part1(lines)
part2(lines)

View File

@@ -54,7 +54,11 @@ func part2[ranges: Array] : void
io.println_i64(sum)
func main[] : i64
ranges := must(io.read_text_file?("input.txt")) |> str.split(",")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
ranges := str.split(input, ",")
part1(ranges)
part2(ranges)

View File

@@ -45,7 +45,11 @@ func part2[lines: Array] : void
io.println_i64(sum)
func main[] : i64
lines := must(io.read_text_file?("input.txt")) |> str.split("\n")
~input, ok := io.read_text_file("input.txt")
if !ok
panic("failed to open input.txt")
lines := str.split(input, "\n")
part1(lines)
part2(lines)

View File

@@ -1,5 +1,7 @@
func main[] : i64
s : i64 = must(net.listen?(net.pack_addr(127, 0, 0, 1), 8000))
~s, ok := net.listen(net.pack_addr(127, 0, 0, 1), 8000)
if !ok
panic("failed to listen")
io.println("Listening on port 8000...")

View File

@@ -1,5 +1,7 @@
func main[] : i64
s : net.UDPSocket = must(net.create_udp_server?(net.pack_addr(127, 0, 0, 1), 8000))
~s, ok := net.create_udp_server(net.pack_addr(127, 0, 0, 1), 8000)
if !ok
panic("net.create_udp_server failed")
io.println("Listening on port 8000...")
while true