Files
aji/tests/conformance/source/array_arguments/direct.air
T

43 lines
980 B
LLVM

; expect: run
; result: 42
; phase: 1
; spec: docs/spec/07a-air-instructions.md; docs/spec/15-source-language.md §5
; Independent format-0 baseline: temporary borrows end before the next access.
module test.array_arguments
air 0
lang 0.1
features [arrays, effects, ownership]
fn @first(%a: ref<array<u64, 2>>) -> u64
effects []
entry:
%index = const.usize 0
%element = borrow.index %a, %index
%value = load %element
borrow.end %element
ret %value
fn @set(%a: mut<array<u64, 2>>) -> void
effects []
entry:
%answer = const.u64 42
%index = const.usize 0
%element = borrow.index %a, %index
store %element, %answer
borrow.end %element
ret
fn @main() -> u64
effects []
entry:
%data = local.alloc array<u64, 2>
local.zero %data
%writer = borrow.mut %data
call @set(%writer)
borrow.end %writer
%reader = borrow.ref %data
%answer = call @first(%reader)
borrow.end %reader
local.zero %data
ret %answer