- 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
28 lines
978 B
Rust
28 lines
978 B
Rust
// TCP echo over the deterministic loopback; streams and the listener are closed explicitly.
|
|
// expect: run
|
|
// grant: listen=net.listen
|
|
// grant: connect=net.connect
|
|
// result: [112,105,110,103]
|
|
// equivalent: phase2/run/tcp_echo.air
|
|
// phase: 6
|
|
// spec: docs/spec/15-source-language.md
|
|
module demo.tcpecho
|
|
|
|
fn main(listen: cap<net.listen>, connect: cap<net.connect>) -> [u8; 4]
|
|
effects [net.listen, net.connect, net.read, net.write]
|
|
{
|
|
let l = net.listen(listen, b"127.0.0.1:7") or trap;
|
|
let client = net.connect(connect, b"127.0.0.1:7") or trap;
|
|
let server = net.accept(l) or trap;
|
|
net.send_all(client, b"ping") or trap;
|
|
var buf: [u8; 4] = zero;
|
|
let n = net.recv(server, mut buf) or trap;
|
|
net.send_all(server, ref buf[0..n]) or trap;
|
|
var back: [u8; 4] = zero;
|
|
let m = net.recv(client, mut back) or trap;
|
|
net.close_stream(move server) or trap;
|
|
net.close_stream(move client) or trap;
|
|
net.close_listener(move l) or trap;
|
|
back
|
|
}
|