Added allocator test
This commit is contained in:
35
tests/programs/allocator.q
Normal file
35
tests/programs/allocator.q
Normal 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
|
||||
}
|
@ -70,6 +70,7 @@ var programs = []struct {
|
||||
{"index-dynamic", 0},
|
||||
{"struct", 0},
|
||||
{"struct-lifetime", 0},
|
||||
{"allocator", 0},
|
||||
{"len", 0},
|
||||
{"cast", 0},
|
||||
{"function-pointer", 0},
|
||||
|
Reference in New Issue
Block a user