Added allocator test

This commit is contained in:
2025-03-10 16:58:17 +01:00
parent 7807271f43
commit 325dd126f9
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import mem
main() {
mgr := new(Allocator)
mgr.block = mem.alloc(2 * 1024 * 1024)
mgr.current = 0
a := new(Point)
a = mgr.block + mgr.current
mgr.current += 16
b := new(Point)
b = mgr.block + mgr.current
mgr.current += 16
a.x = 1
a.y = 2
b.x = 3
b.y = 4
assert a.x == 1
assert a.y == 2
assert b.x == 3
assert b.y == 4
}
struct Allocator {
block *any
current int
}
struct Point {
x int
y int
}

View File

@ -70,6 +70,7 @@ var programs = []struct {
{"index-dynamic", 0},
{"struct", 0},
{"struct-lifetime", 0},
{"allocator", 0},
{"len", 0},
{"cast", 0},
{"function-pointer", 0},