q/tests/programs/allocator.q
2025-03-10 16:58:17 +01:00

35 lines
419 B
Plaintext

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
}