Landin library reference source

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

1import core/io
2
3exercise: () -> (ok: bool) ! io.empty_path | io.path_contains_nul | io.path_too_long =
4    ok = false
5    source: [2]u8 = [65, 66]
6    mut scratch: [3]u8 = zeroed
7    terminated := try io.terminate_path(source[0..<2], scratch[0..<3])
8    return when terminated.val <> 65 or scratch[2] <> 0
9    _ = io.terminate_path(source[0..<2], scratch[0..<1]) else (problem)
10        ok = problem == io.path_too_long and scratch[0] == 65
11        return
12    end
13end exercise
14
15public main: () -> (code: i32) =
16    code = 1
17    ok := exercise() else false
18    if ok then
19        code = 42
20    end if
21end main