_stackalloc

This commit is contained in:
2026-05-30 21:01:01 +02:00
parent f181cfe675
commit 31b71a5e19
8 changed files with 46 additions and 37 deletions

View File

@@ -36,7 +36,7 @@ func chip8_create[] : CHIP8
fonts := [0xf0, 0x90, 0x90, 0x90, 0xf0, 0x20, 0x60, 0x20, 0x20, 0x70, 0xf0, 0x10, 0xf0, 0x80, 0xf0, 0xf0, 0x10, 0xf0, 0x10, 0xf0, 0x90, 0x90, 0xf0, 0x10, 0x10, 0xf0, 0x80, 0xf0, 0x10, 0xf0, 0xf0, 0x80, 0xf0, 0x90, 0xf0, 0xf0, 0x10, 0x20, 0x40, 0x40, 0xf0, 0x90, 0xf0, 0x90, 0xf0, 0xf0, 0x90, 0xf0, 0x10, 0xf0, 0xf0, 0x90, 0xf0, 0x90, 0x90, 0xe0, 0x90, 0xe0, 0x90, 0xe0, 0xf0, 0x80, 0x80, 0x80, 0xf0, 0xe0, 0x90, 0x90, 0x90, 0xe0, 0xf0, 0x80, 0xf0, 0x80, 0xf0, 0xf0, 0x80, 0xf0, 0x80, 0x80]
for i in 0..80
c->memory[i] = array.nth(fonts, i)
mem.free(fonts)
array.free(fonts)
c->pc = 0x200

View File

@@ -43,7 +43,7 @@ func part2[lines: Array] : void
for x in 1..lines->size-1
for y in 1..str.len(array.nth(lines, x))-1
if array.nth(lines, x)[y] == 'A'
s := mem.alloc(5) as str
s := _stackalloc(5) as str
s[0] = array.nth(lines, x - 1)[y - 1]
s[1] = array.nth(lines, x + 1)[y - 1]
s[2] = array.nth(lines, x + 1)[y + 1]

View File

@@ -7,7 +7,7 @@ func part1[lines: Array] : void
largest := 0
for j in 0..str.len(line)
for k in (j+1)..str.len(line)
s := mem.alloc(3) as str
s := _stackalloc(3) as str
s[0] = line[j]
s[1] = line[k]
s[2] = 0

View File

@@ -6,7 +6,7 @@ func main[] : i64
io.println("Listening on port 8000...")
resp := mem.alloc(60000)
addr := mem.alloc(16)
addr := _stackalloc(16)
while true
conn := net.accept(s, addr)
if conn < 0