- 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
216 lines
5.6 KiB
Plaintext
216 lines
5.6 KiB
Plaintext
module demo.filecopy
|
|
air 0
|
|
lang 0.1
|
|
features [arrays, capabilities, effects, ownership, resources]
|
|
|
|
fn @main(%src: cap<fs.read>, %dst: cap<fs.write>) -> void
|
|
effects [fs.read, fs.write]
|
|
entry:
|
|
%bytes_1 = local.alloc array<u8, 12>
|
|
%bytes_45 = local.alloc array<u8, 13>
|
|
%buf_92 = local.alloc array<u8, 4>
|
|
local.zero %bytes_1
|
|
%w_2 = borrow.mut %bytes_1
|
|
%i_3 = const.usize 0
|
|
%c_4 = const.u8 47
|
|
%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 105
|
|
%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 110
|
|
%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 47
|
|
%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 100
|
|
%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 97
|
|
%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 116
|
|
%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 97
|
|
%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 46
|
|
%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 116
|
|
%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 120
|
|
%e_35 = borrow.index %w_2, %i_33
|
|
store %e_35, %c_34
|
|
borrow.end %e_35
|
|
%i_36 = const.usize 11
|
|
%c_37 = const.u8 116
|
|
%e_38 = borrow.index %w_2, %i_36
|
|
store %e_38, %c_37
|
|
borrow.end %e_38
|
|
borrow.end %w_2
|
|
%b_39 = borrow.ref %bytes_1
|
|
%s_40 = slice.make %b_39
|
|
intrinsic fs.open_read(%src, %s_40), ok -> @ok_41, err -> @err_43
|
|
ok_41(%ok_42: file<read>):
|
|
borrow.end %s_40
|
|
borrow.end %b_39
|
|
local.zero %bytes_45
|
|
%w_46 = borrow.mut %bytes_45
|
|
%i_47 = const.usize 0
|
|
%c_48 = const.u8 47
|
|
%e_49 = borrow.index %w_46, %i_47
|
|
store %e_49, %c_48
|
|
borrow.end %e_49
|
|
%i_50 = const.usize 1
|
|
%c_51 = const.u8 111
|
|
%e_52 = borrow.index %w_46, %i_50
|
|
store %e_52, %c_51
|
|
borrow.end %e_52
|
|
%i_53 = const.usize 2
|
|
%c_54 = const.u8 117
|
|
%e_55 = borrow.index %w_46, %i_53
|
|
store %e_55, %c_54
|
|
borrow.end %e_55
|
|
%i_56 = const.usize 3
|
|
%c_57 = const.u8 116
|
|
%e_58 = borrow.index %w_46, %i_56
|
|
store %e_58, %c_57
|
|
borrow.end %e_58
|
|
%i_59 = const.usize 4
|
|
%c_60 = const.u8 47
|
|
%e_61 = borrow.index %w_46, %i_59
|
|
store %e_61, %c_60
|
|
borrow.end %e_61
|
|
%i_62 = const.usize 5
|
|
%c_63 = const.u8 99
|
|
%e_64 = borrow.index %w_46, %i_62
|
|
store %e_64, %c_63
|
|
borrow.end %e_64
|
|
%i_65 = const.usize 6
|
|
%c_66 = const.u8 111
|
|
%e_67 = borrow.index %w_46, %i_65
|
|
store %e_67, %c_66
|
|
borrow.end %e_67
|
|
%i_68 = const.usize 7
|
|
%c_69 = const.u8 112
|
|
%e_70 = borrow.index %w_46, %i_68
|
|
store %e_70, %c_69
|
|
borrow.end %e_70
|
|
%i_71 = const.usize 8
|
|
%c_72 = const.u8 121
|
|
%e_73 = borrow.index %w_46, %i_71
|
|
store %e_73, %c_72
|
|
borrow.end %e_73
|
|
%i_74 = const.usize 9
|
|
%c_75 = const.u8 46
|
|
%e_76 = borrow.index %w_46, %i_74
|
|
store %e_76, %c_75
|
|
borrow.end %e_76
|
|
%i_77 = const.usize 10
|
|
%c_78 = const.u8 116
|
|
%e_79 = borrow.index %w_46, %i_77
|
|
store %e_79, %c_78
|
|
borrow.end %e_79
|
|
%i_80 = const.usize 11
|
|
%c_81 = const.u8 120
|
|
%e_82 = borrow.index %w_46, %i_80
|
|
store %e_82, %c_81
|
|
borrow.end %e_82
|
|
%i_83 = const.usize 12
|
|
%c_84 = const.u8 116
|
|
%e_85 = borrow.index %w_46, %i_83
|
|
store %e_85, %c_84
|
|
borrow.end %e_85
|
|
borrow.end %w_46
|
|
%b_86 = borrow.ref %bytes_45
|
|
%s_87 = slice.make %b_86
|
|
intrinsic fs.create(%dst, %s_87), ok -> @ok_88, err -> @err_90
|
|
err_43(%err_44: io_error):
|
|
borrow.end %s_40
|
|
borrow.end %b_39
|
|
trap
|
|
ok_88(%ok_89: file<write>):
|
|
borrow.end %s_87
|
|
borrow.end %b_86
|
|
local.zero %buf_92
|
|
br @loop_93()
|
|
err_90(%err_91: io_error):
|
|
borrow.end %s_87
|
|
borrow.end %b_86
|
|
trap
|
|
loop_93:
|
|
%input_95 = borrow.mut %ok_42
|
|
%buf_96 = borrow.mut %buf_92
|
|
%s_97 = slice.make %buf_96
|
|
intrinsic fs.read(%input_95, %s_97), ok -> @ok_98, err -> @err_100
|
|
after_94:
|
|
intrinsic fs.close(%ok_42), ok -> @ok_116, err -> @err_117
|
|
ok_98(%ok_99: usize):
|
|
borrow.end %s_97
|
|
borrow.end %buf_96
|
|
borrow.end %input_95
|
|
%c_102 = const.usize 0
|
|
%cmp_103 = eq.usize %ok_99, %c_102
|
|
cbr %cmp_103, @then_104(), @else_105()
|
|
err_100(%err_101: io_error):
|
|
borrow.end %s_97
|
|
borrow.end %buf_96
|
|
borrow.end %input_95
|
|
trap
|
|
then_104:
|
|
br @after_94()
|
|
else_105:
|
|
br @endif_106()
|
|
endif_106:
|
|
%output_107 = borrow.mut %ok_89
|
|
%buf_108 = borrow.ref %buf_92
|
|
%s_109 = slice.make %buf_108
|
|
%c_110 = const.usize 0
|
|
%len_111 = sub.checked.usize %ok_99, %c_110
|
|
%s_112 = slice.sub %s_109, %c_110, %len_111
|
|
intrinsic fs.write_all(%output_107, %s_112), ok -> @ok_113, err -> @err_114
|
|
ok_113:
|
|
borrow.end %s_112
|
|
borrow.end %s_109
|
|
borrow.end %buf_108
|
|
borrow.end %output_107
|
|
br @loop_93()
|
|
err_114(%err_115: io_error):
|
|
borrow.end %s_112
|
|
borrow.end %s_109
|
|
borrow.end %buf_108
|
|
borrow.end %output_107
|
|
trap
|
|
ok_116:
|
|
intrinsic fs.close(%ok_89), ok -> @ok_119, err -> @err_120
|
|
err_117(%err_118: io_error):
|
|
trap
|
|
ok_119:
|
|
ret
|
|
err_120(%err_121: io_error):
|
|
trap
|