Files
aji/tests/conformance/source/layer6/resource_param.aji
T
dev c18fb7acc1 Phase 6A: .aji layer 6 (intrinsics, resources, narrowing, unsafe operations)
- intrinsics from the registry as plain calls: fallible ones are outcome
  matches or `or trap` (E7006 otherwise), infallible ones plain calls
- resource operands by name, borrowed mut for the one operation and ended
  on every edge; a mut binding/parameter passes as is; `mut f` is E7006
- closes consume with `move` (E7003); no inserted closes (E3002/E3001)
- data operands explicit (ref/mut/byte string, E7005 otherwise)
- file<…>, stream, listener types; cap.narrow.prefix with cap_error edges
- ref/mut unchecked s[i] (also as a binding) and assume(c) under
  effects [unsafe]; boundary left to the verifier (E6001)
- trusted is reserved and rejected (E7006)
- parameter names preserved; generated names avoid them (normative)
- parser: >> closes two type arguments
- conformance: `equivalent:` compares the run record with a reference
  AIR program (hello, file_copy, tcp_echo, narrow ok/not_subset/invalid,
  random)
- spec 15, grammar, quick reference (io_error match fixed), plan, examples
2026-10-05 12:16:54 +03:00

25 lines
587 B
Rust

// A function borrows a resource through a mut<file<…>> parameter; the caller lends it with `mut f`.
// expect: run
// grant: dst=fs.write:/out
// result: null
// file: /out/a.txt=ab
// phase: 6
// spec: docs/spec/15-source-language.md
module demo.resourceparam
fn put(f: mut<file<write>>, byte: u8) -> void
effects [fs.write]
{
var one: [u8; 1] = [byte; 1];
fs.write_all(f, ref one) or trap;
}
fn main(dst: cap<fs.write>) -> void
effects [fs.write]
{
let f = fs.create(dst, b"/out/a.txt") or trap;
put(mut f, 97);
put(mut f, 98);
fs.close(move f) or trap;
}