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
This commit is contained in:
1 parent
bdcf871e5d
commit
c18fb7acc1
39 files changed
+1309
-69
No files matched your search
+19
-25
@@ -1,32 +1,26 @@
|
||||
module examples.file_copy;
|
||||
// Run: aji run --grant fs_read=fs.read:/in --grant fs_write=fs.write:/out \
|
||||
// --vfs '/in/data.txt=some text' examples/file_copy.aji
|
||||
module examples.file_copy
|
||||
|
||||
fn copy(
|
||||
fs_read: cap<fs.read>,
|
||||
fs_write: cap<fs.write>,
|
||||
src: slice<u8>,
|
||||
dst: slice<u8>,
|
||||
alloc: cap<mem.alloc>
|
||||
) -> Result<void, IoError>
|
||||
effects [mem.alloc, fs.read, fs.write]
|
||||
fn copy(input: mut<file<read>>, output: mut<file<write>>) -> void
|
||||
effects [fs.read, fs.write]
|
||||
{
|
||||
let input = fs.open_read(fs_read, src)?;
|
||||
defer fs.close(move input);
|
||||
|
||||
let output = fs.open_write(fs_write, dst)?;
|
||||
defer fs.close(move output);
|
||||
|
||||
var region = region.create(alloc, limit = 64 KiB)?;
|
||||
defer region.destroy(move region);
|
||||
|
||||
let buffer = region.alloc_zeroed_array<u8>(mut region, 64 KiB)?;
|
||||
|
||||
while true {
|
||||
let n = fs.read(ref input, buffer)?;
|
||||
var buf: [u8; 64] = zero;
|
||||
loop {
|
||||
let n = fs.read(input, mut buf) or trap;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
fs.write_all(ref output, slice.prefix(buffer, n))?;
|
||||
fs.write_all(output, ref buf[0..n]) or trap;
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
fn main(fs_read: cap<fs.read>, fs_write: cap<fs.write>) -> void
|
||||
effects [fs.read, fs.write]
|
||||
{
|
||||
let input = fs.open_read(fs_read, b"/in/data.txt") or trap;
|
||||
let output = fs.create(fs_write, b"/out/copy.txt") or trap;
|
||||
copy(mut input, mut output);
|
||||
fs.close(move input) or trap;
|
||||
fs.close(move output) or trap;
|
||||
}
|
||||
+4
-6
@@ -1,10 +1,8 @@
|
||||
module examples.hello;
|
||||
// Run: aji run --grant stdout=io.write examples/hello.aji
|
||||
module examples.hello
|
||||
|
||||
fn main(
|
||||
stdout: cap<io.write>
|
||||
) -> Result<void, IoError>
|
||||
fn main(stdout: cap<io.write>) -> void
|
||||
effects [io.write]
|
||||
{
|
||||
io.stdout_write(stdout, "hello from aji\n")?;
|
||||
return Ok();
|
||||
io.stdout_write(stdout, b"hello from aji\n") or trap;
|
||||
}
|
||||
Reference in new issue
Block a user