compiler/tests/fixtures/runtime/library-shared-small/main.ldn
1import core/mem
2import core/small
3
4exercise: () -> (ok: bool) ! mem.out_of_memory | mem.empty | mem.out_of_bounds =
5 ok = false
6 mut backing: [32]u8 = zeroed
7 mut state := mem.arena_over_unchecked(addr backing[0], 32)
8 mut values := small.new(item: i32, inline_slots: 1)
9 try small.push(values, state, i32(41))
10 return when small.length(addr values) <> 1 or mem.arena_used(state) <> 0
11 slot: ptr mut i32 = try small.at(values, usize(0))
12 slot.val = 42
13 value := try small.pop(values)
14 return when value <> 42
15 _ = small.pop(values) else (problem)
16 ok = problem == mem.empty and small.length(addr values) == 0
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