compiler/tests/fixtures/runtime/library-shared-pool/main.ldn
skip to the library navigation
1import core/mem
2import core/pool
3
4exercise: () -> (ok: bool) ! mem.out_of_memory =
5 ok = false
6 mut backing: [64]u8 = zeroed
7 mut slots: [1]pool.slot = zeroed
8 mut space: pool.space = zeroed
9 slab := try pool.over(space, addr backing[0], 64, 16, 1, 1, slots[0..<1])
10 address := try mem.allocate(slab, usize(16), usize(1))
11 address.val = 42
12 return when address.val <> 42 or pool.live(slab) <> 1
13 _ = mem.allocate(slab, usize(1), usize(1)) else (problem)
14 _ = problem
15 mem.release(slab, address, usize(16))
16 ok = pool.live(slab) == 0 and pool.frees(slab) == 1
17 return
18 end
19end exercise
20
21public main: () -> (code: i32) =
22 code = 1
23 ok := exercise() else false
24 if ok then
25 code = 42
26 end if
27end main