compiler/tests/fixtures/abi/r440-native-hosted/program.ldn
1-- C-owned startup uses the library's startup-independent services: the C
2-- library through hosted/libc and the hosted heap, with no argument root.
3import core/mem
4import hosted/heap
5import hosted/libc
6
7-- Private Landin names cannot replace the library's calls into libc.
8strlen: () -> (result: usize) = result = 99 end strlen
9malloc: () -> (result: usize) = result = 99 end malloc
10free: () -> (result: usize) = result = 99 end free
11
12public extern(c) l_length: (data: ptr u8) -> (length: usize) =
13 _ = strlen()
14 length = libc.strlen(data)
15end l_length
16
17public extern(c) l_copy: (input: i32, output: i32, buffer: ptr mut u8, length: usize) -> (count: usize) =
18 received := libc.read(input, buffer, length)
19 count = 0
20 if received == isize(length) then
21 count = usize(libc.write(output, buffer, length))
22 end if
23end l_copy
24
25public extern(c) l_heap: () -> (ok: bool) =
26 _ = malloc()
27 _ = free()
28 ok = false
29 mut provider: heap.system = heap.host()
30 block: ptr mut u8 = mem.allocate(provider, usize(64), usize(24)) else (problem)
31 _ = problem
32 return
33 end
34 block.val = 42
35 ok = block.val == 42 and usize(block) % 24 == 0
36 mem.free(provider, block, usize(64))
37end l_heap