Landin library reference discuss source

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

1import core/mem
2
3public main: () -> (code: i32) =
4    code = 1
5    mut bytes: [8]u8 = zeroed
6    mem.fill(bytes[0..<8], u8('.'))
7    mem.copy(bytes[2..<8], "mem") else none
8    mem.copy(bytes[0..<2], "long") else none
9    return when mem.find(bytes[0..<8], u8('m')) <> 2
10      or bytes[0] <> u8('.') or bytes[5] <> u8('.')
11    mut slots: [4]u8 = zeroed
12    mut store := mem.storage_over(item: u8, base: addr slots[0], slots: 4)
13    _ = mem.admit(store, bytes[3]) else 9
14    first := mem.get(store, 0) else u8(0)
15    missing := mem.get(store, 1) else u8(0)
16    if first == u8('e') and missing == 0 and mem.length(store) == 1 then
17        code = 42
18    end if
19end main