Landin library reference discuss source

compiler/tests/fixtures/runtime/library-shared-spill/main.ldn

1import core/arena
2import core/mem
3import core/spill
4
5exercise: () -> (ok: bool) ! mem.out_of_memory | mem.empty | mem.out_of_bounds =
6    ok = false
7    mut backing: [32]u8 = zeroed
8    mut space: arena.space = zeroed
9    memory := arena.over_unchecked(space, addr backing[0], 32)
10    mut values := spill.new(item: i32, inline_slots: 1)
11    try spill.push(values, memory, i32(41))
12    return when spill.length(addr values) <> 1 or arena.length(memory) <> 0
13    slot: ptr mut i32 = try spill.at(values, usize(0))
14    slot.val = 42
15    value := try spill.pop(values)
16    return when value <> 42
17    _ = spill.pop(values) else (problem)
18        ok = problem == mem.empty and spill.length(addr values) == 0
19        return
20    end
21end exercise
22
23public main: () -> (code: i32) =
24    code = 1
25    ok := exercise() else false
26    if ok then
27        code = 42
28    end if
29end main