- 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
253 lines
6.8 KiB
Plaintext
253 lines
6.8 KiB
Plaintext
module demo.tcpecho
|
|
air 0
|
|
lang 0.1
|
|
features [arrays, capabilities, effects, ownership, resources]
|
|
|
|
fn @main(%listen: cap<net.listen>, %connect: cap<net.connect>) -> array<u8, 4>
|
|
effects [net.listen, net.connect, net.read, net.write]
|
|
entry:
|
|
%bytes_1 = local.alloc array<u8, 11>
|
|
%bytes_42 = local.alloc array<u8, 11>
|
|
%bytes_89 = local.alloc array<u8, 4>
|
|
%buf_108 = local.alloc array<u8, 4>
|
|
%back_125 = local.alloc array<u8, 4>
|
|
local.zero %bytes_1
|
|
%w_2 = borrow.mut %bytes_1
|
|
%i_3 = const.usize 0
|
|
%c_4 = const.u8 49
|
|
%e_5 = borrow.index %w_2, %i_3
|
|
store %e_5, %c_4
|
|
borrow.end %e_5
|
|
%i_6 = const.usize 1
|
|
%c_7 = const.u8 50
|
|
%e_8 = borrow.index %w_2, %i_6
|
|
store %e_8, %c_7
|
|
borrow.end %e_8
|
|
%i_9 = const.usize 2
|
|
%c_10 = const.u8 55
|
|
%e_11 = borrow.index %w_2, %i_9
|
|
store %e_11, %c_10
|
|
borrow.end %e_11
|
|
%i_12 = const.usize 3
|
|
%c_13 = const.u8 46
|
|
%e_14 = borrow.index %w_2, %i_12
|
|
store %e_14, %c_13
|
|
borrow.end %e_14
|
|
%i_15 = const.usize 4
|
|
%c_16 = const.u8 48
|
|
%e_17 = borrow.index %w_2, %i_15
|
|
store %e_17, %c_16
|
|
borrow.end %e_17
|
|
%i_18 = const.usize 5
|
|
%c_19 = const.u8 46
|
|
%e_20 = borrow.index %w_2, %i_18
|
|
store %e_20, %c_19
|
|
borrow.end %e_20
|
|
%i_21 = const.usize 6
|
|
%c_22 = const.u8 48
|
|
%e_23 = borrow.index %w_2, %i_21
|
|
store %e_23, %c_22
|
|
borrow.end %e_23
|
|
%i_24 = const.usize 7
|
|
%c_25 = const.u8 46
|
|
%e_26 = borrow.index %w_2, %i_24
|
|
store %e_26, %c_25
|
|
borrow.end %e_26
|
|
%i_27 = const.usize 8
|
|
%c_28 = const.u8 49
|
|
%e_29 = borrow.index %w_2, %i_27
|
|
store %e_29, %c_28
|
|
borrow.end %e_29
|
|
%i_30 = const.usize 9
|
|
%c_31 = const.u8 58
|
|
%e_32 = borrow.index %w_2, %i_30
|
|
store %e_32, %c_31
|
|
borrow.end %e_32
|
|
%i_33 = const.usize 10
|
|
%c_34 = const.u8 55
|
|
%e_35 = borrow.index %w_2, %i_33
|
|
store %e_35, %c_34
|
|
borrow.end %e_35
|
|
borrow.end %w_2
|
|
%b_36 = borrow.ref %bytes_1
|
|
%s_37 = slice.make %b_36
|
|
intrinsic net.listen(%listen, %s_37), ok -> @ok_38, err -> @err_40
|
|
ok_38(%ok_39: listener):
|
|
borrow.end %s_37
|
|
borrow.end %b_36
|
|
local.zero %bytes_42
|
|
%w_43 = borrow.mut %bytes_42
|
|
%i_44 = const.usize 0
|
|
%c_45 = const.u8 49
|
|
%e_46 = borrow.index %w_43, %i_44
|
|
store %e_46, %c_45
|
|
borrow.end %e_46
|
|
%i_47 = const.usize 1
|
|
%c_48 = const.u8 50
|
|
%e_49 = borrow.index %w_43, %i_47
|
|
store %e_49, %c_48
|
|
borrow.end %e_49
|
|
%i_50 = const.usize 2
|
|
%c_51 = const.u8 55
|
|
%e_52 = borrow.index %w_43, %i_50
|
|
store %e_52, %c_51
|
|
borrow.end %e_52
|
|
%i_53 = const.usize 3
|
|
%c_54 = const.u8 46
|
|
%e_55 = borrow.index %w_43, %i_53
|
|
store %e_55, %c_54
|
|
borrow.end %e_55
|
|
%i_56 = const.usize 4
|
|
%c_57 = const.u8 48
|
|
%e_58 = borrow.index %w_43, %i_56
|
|
store %e_58, %c_57
|
|
borrow.end %e_58
|
|
%i_59 = const.usize 5
|
|
%c_60 = const.u8 46
|
|
%e_61 = borrow.index %w_43, %i_59
|
|
store %e_61, %c_60
|
|
borrow.end %e_61
|
|
%i_62 = const.usize 6
|
|
%c_63 = const.u8 48
|
|
%e_64 = borrow.index %w_43, %i_62
|
|
store %e_64, %c_63
|
|
borrow.end %e_64
|
|
%i_65 = const.usize 7
|
|
%c_66 = const.u8 46
|
|
%e_67 = borrow.index %w_43, %i_65
|
|
store %e_67, %c_66
|
|
borrow.end %e_67
|
|
%i_68 = const.usize 8
|
|
%c_69 = const.u8 49
|
|
%e_70 = borrow.index %w_43, %i_68
|
|
store %e_70, %c_69
|
|
borrow.end %e_70
|
|
%i_71 = const.usize 9
|
|
%c_72 = const.u8 58
|
|
%e_73 = borrow.index %w_43, %i_71
|
|
store %e_73, %c_72
|
|
borrow.end %e_73
|
|
%i_74 = const.usize 10
|
|
%c_75 = const.u8 55
|
|
%e_76 = borrow.index %w_43, %i_74
|
|
store %e_76, %c_75
|
|
borrow.end %e_76
|
|
borrow.end %w_43
|
|
%b_77 = borrow.ref %bytes_42
|
|
%s_78 = slice.make %b_77
|
|
intrinsic net.connect(%connect, %s_78), ok -> @ok_79, err -> @err_81
|
|
err_40(%err_41: io_error):
|
|
borrow.end %s_37
|
|
borrow.end %b_36
|
|
trap
|
|
ok_79(%ok_80: stream):
|
|
borrow.end %s_78
|
|
borrow.end %b_77
|
|
%l_83 = borrow.mut %ok_39
|
|
intrinsic net.accept(%l_83), ok -> @ok_84, err -> @err_86
|
|
err_81(%err_82: io_error):
|
|
borrow.end %s_78
|
|
borrow.end %b_77
|
|
trap
|
|
ok_84(%ok_85: stream):
|
|
borrow.end %l_83
|
|
%client_88 = borrow.mut %ok_80
|
|
local.zero %bytes_89
|
|
%w_90 = borrow.mut %bytes_89
|
|
%i_91 = const.usize 0
|
|
%c_92 = const.u8 112
|
|
%e_93 = borrow.index %w_90, %i_91
|
|
store %e_93, %c_92
|
|
borrow.end %e_93
|
|
%i_94 = const.usize 1
|
|
%c_95 = const.u8 105
|
|
%e_96 = borrow.index %w_90, %i_94
|
|
store %e_96, %c_95
|
|
borrow.end %e_96
|
|
%i_97 = const.usize 2
|
|
%c_98 = const.u8 110
|
|
%e_99 = borrow.index %w_90, %i_97
|
|
store %e_99, %c_98
|
|
borrow.end %e_99
|
|
%i_100 = const.usize 3
|
|
%c_101 = const.u8 103
|
|
%e_102 = borrow.index %w_90, %i_100
|
|
store %e_102, %c_101
|
|
borrow.end %e_102
|
|
borrow.end %w_90
|
|
%b_103 = borrow.ref %bytes_89
|
|
%s_104 = slice.make %b_103
|
|
intrinsic net.send_all(%client_88, %s_104), ok -> @ok_105, err -> @err_106
|
|
err_86(%err_87: io_error):
|
|
borrow.end %l_83
|
|
trap
|
|
ok_105:
|
|
borrow.end %s_104
|
|
borrow.end %b_103
|
|
borrow.end %client_88
|
|
local.zero %buf_108
|
|
%server_109 = borrow.mut %ok_85
|
|
%buf_110 = borrow.mut %buf_108
|
|
%s_111 = slice.make %buf_110
|
|
intrinsic net.recv(%server_109, %s_111), ok -> @ok_112, err -> @err_114
|
|
err_106(%err_107: io_error):
|
|
borrow.end %s_104
|
|
borrow.end %b_103
|
|
borrow.end %client_88
|
|
trap
|
|
ok_112(%ok_113: usize):
|
|
borrow.end %s_111
|
|
borrow.end %buf_110
|
|
borrow.end %server_109
|
|
%server_116 = borrow.mut %ok_85
|
|
%buf_117 = borrow.ref %buf_108
|
|
%s_118 = slice.make %buf_117
|
|
%c_119 = const.usize 0
|
|
%len_120 = sub.checked.usize %ok_113, %c_119
|
|
%s_121 = slice.sub %s_118, %c_119, %len_120
|
|
intrinsic net.send_all(%server_116, %s_121), ok -> @ok_122, err -> @err_123
|
|
err_114(%err_115: io_error):
|
|
borrow.end %s_111
|
|
borrow.end %buf_110
|
|
borrow.end %server_109
|
|
trap
|
|
ok_122:
|
|
borrow.end %s_121
|
|
borrow.end %s_118
|
|
borrow.end %buf_117
|
|
borrow.end %server_116
|
|
local.zero %back_125
|
|
%client_126 = borrow.mut %ok_80
|
|
%back_127 = borrow.mut %back_125
|
|
%s_128 = slice.make %back_127
|
|
intrinsic net.recv(%client_126, %s_128), ok -> @ok_129, err -> @err_131
|
|
err_123(%err_124: io_error):
|
|
borrow.end %s_121
|
|
borrow.end %s_118
|
|
borrow.end %buf_117
|
|
borrow.end %server_116
|
|
trap
|
|
ok_129(%ok_130: usize):
|
|
borrow.end %s_128
|
|
borrow.end %back_127
|
|
borrow.end %client_126
|
|
intrinsic net.close_stream(%ok_85), ok -> @ok_133, err -> @err_134
|
|
err_131(%err_132: io_error):
|
|
borrow.end %s_128
|
|
borrow.end %back_127
|
|
borrow.end %client_126
|
|
trap
|
|
ok_133:
|
|
intrinsic net.close_stream(%ok_80), ok -> @ok_136, err -> @err_137
|
|
err_134(%err_135: io_error):
|
|
trap
|
|
ok_136:
|
|
intrinsic net.close_listener(%ok_39), ok -> @ok_139, err -> @err_140
|
|
err_137(%err_138: io_error):
|
|
trap
|
|
ok_139:
|
|
%back_142 = local.load %back_125
|
|
ret %back_142
|
|
err_140(%err_141: io_error):
|
|
trap
|