diff --git a/tests/programs/allocator.q b/tests/programs/allocator.q new file mode 100644 index 0000000..4b39208 --- /dev/null +++ b/tests/programs/allocator.q @@ -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 +} \ No newline at end of file diff --git a/tests/programs_test.go b/tests/programs_test.go index 899cbb7..953de1f 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -70,6 +70,7 @@ var programs = []struct { {"index-dynamic", 0}, {"struct", 0}, {"struct-lifetime", 0}, + {"allocator", 0}, {"len", 0}, {"cast", 0}, {"function-pointer", 0},