cli: add explicit owning buffered file adapters
Add pinned std.io.reader and std.io.writer using safe source, explicit fixed allocation and file transfer. Finish/discard return complete resources; writer failures preserve pending data and prohibit unsound partial retries. Specify cursor, acceptance, failure and cleanup contracts in spec 16, RFC 0034, the API reference and source bundle. Add standalone conformance, independent byte oracles, task/GC stress, CLI/package/profile checks and hosted partial-write tests with a raised child quota to detect retries. Validation: 1061 conformance cases; 34 buffered cases with per-step GC and 12 schedule seeds; unit/Quick Reference, formatting, hosted smoke, 89 CLI checks, 115 source coverage constructs and reference generation.
This commit is contained in:
1 parent
3e1c0f34e8
commit
8d8bef8f3e
51 files changed
+1916
-8
No files matched your search
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.writer.Writer) -> void effects [] { std.io.writer.discard(move q); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => {}, std.io.reader.ReadResult::err(error) => { trap; } }
|
||||
exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 97u8); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.reader.Reader) -> void effects [fs.read] { mut file = q.file; std.io.reader.finish(move q); var bytes: [u8;1] = [0u8;1]; fs.read(file,mut bytes) or trap; trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.writer.Writer) -> void effects [fs.write] { match std.io.writer.finish(move q) { std.io.writer.FinishResult::ok(file) => { trap; }, std.io.writer.FinishResult::err(error) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var prefix: [u8;3] = [0u8;3];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut prefix)); }
|
||||
let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut prefix)); assert(prefix[0] == 100u8); assert(prefix[2] == 102u8); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// grant: src=fs.read:/out
|
||||
// file: /out/data=abcd
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn observed(src: cap<fs.read>,expected: usize) -> void effects [fs.read] {
|
||||
let file = fs.open_read(src,b"/out/data") or trap; var bytes: [u8;6] = [0u8;6]; match std.io.read_to_end_file(mut file,mut bytes) { std.io.ReadToEndResult::eof(n) => { assert(n == expected); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } fs.close(move file) or trap;
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); let blank: [u8;1] = [0u8;1];
|
||||
{ mut q = value; written(std.io.writer.write(q,b"abc")); written(std.io.writer.write(q,ref blank[0usize..0usize])); } observed(src,0usize);
|
||||
{ mut q = value; written(std.io.writer.write(q,b"d")); } observed(src,3usize);
|
||||
{ mut q = value; match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } observed(src,4usize);
|
||||
fs.close(finished_writer(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E4101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: mut<std.io.reader.Reader>) -> void effects [fs.read] {}
|
||||
fn bad(q: mut<std.io.reader.Reader>) -> void effects [fs.read,task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); var bytes: [u8;1] = [0u8;1]; std.io.reader.read(q,mut bytes); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// schedules: 12
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: mut<std.io.reader.Reader>) -> void effects [fs.read] { var bytes: [u8;3] = [0u8;3]; exact(std.io.reader.read_exact(q,mut bytes)); assert(bytes[0] == 97u8); }
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc,task.spawn,task.wait] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;3] = [0u8;3];
|
||||
{ mut q = value; scope s { let t = task.spawn(s,worker,q); task.join(move t); exact(std.io.reader.read_exact(q,mut bytes)); } }
|
||||
assert(bytes[0] == 100u8); fs.close(finished_reader(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap;
|
||||
match std.io.reader.new(move input,18446744073709551615usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } }
|
||||
match std.io.writer.new(move output,18446744073709551615usize,heap) { std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } }
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<mem.alloc>) -> std.io.reader.NewResult effects [] { return std.io.reader.new(move file,3usize,heap); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.reader.Reader) -> void effects [] { std.io.reader.finish(q); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.reader.Reader>,dest: slice_mut<u8>) -> void effects [] { std.io.reader.read(q,dest); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.writer.Writer>) -> void effects [] { std.io.writer.flush(q); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,284 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/case
|
||||
// grant: dst=fs.write:/case
|
||||
// grant: heap=mem.alloc:5
|
||||
// file: /case/input=abcdefgh
|
||||
// file: /case/output=abcdefgh
|
||||
// fuel: 2000000
|
||||
module test.buffered_model
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.bytes;
|
||||
fn prepare(contents: slice<u8>,dst: cap<fs.write>) -> void effects [fs.write] {
|
||||
let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap;
|
||||
}
|
||||
fn reads(contents: slice<u8>,capacity: usize,chunk: usize,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap;
|
||||
match std.io.reader.new(move file,capacity,heap) {
|
||||
std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => {
|
||||
var bytes: [u8;9] = [255u8;9]; var offset: usize = 0;
|
||||
{ mut q = value; loop {
|
||||
match std.io.reader.read(q,mut bytes[1usize..chunk+1usize]) {
|
||||
std.io.reader.ReadResult::err(error) => { trap; }, std.io.reader.ReadResult::ok(count) => {
|
||||
assert(count <= chunk); assert(offset + count <= contents.len);
|
||||
assert(std.bytes.equal(ref bytes[1usize..count+1usize],ref contents[offset..offset+count]));
|
||||
assert(bytes[0] == 255u8); for i in chunk+1usize..9usize { assert(bytes[i] == 255u8); }
|
||||
offset = offset + count; if count == 0usize { break; }
|
||||
}
|
||||
}
|
||||
} }
|
||||
assert(offset == contents.len);
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
fn exact(contents: slice<u8>,capacity: usize,requested: usize,prefix: usize,full: bool,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap;
|
||||
match std.io.reader.new(move file,capacity,heap) {
|
||||
std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => {
|
||||
var bytes: [u8;12] = [255u8;12];
|
||||
{ mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..requested+1usize]) {
|
||||
std.io.ReadExactResult::ok => { assert(full); }, std.io.ReadExactResult::eof(n) => { assert(not full); assert(n == prefix); }, std.io.ReadExactResult::err(error) => { trap; }
|
||||
} }
|
||||
assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix]));
|
||||
assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); fs.close(move file) or trap;
|
||||
}
|
||||
}
|
||||
}
|
||||
fn writes(contents: slice<u8>,capacity: usize,chunk: usize,flush: bool,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/case/output") or trap;
|
||||
match std.io.writer.new(move file,capacity,heap) {
|
||||
std.io.writer.NewResult::err(error) => { trap; }, std.io.writer.NewResult::ok(value) => {
|
||||
var offset: usize = 0;
|
||||
{ mut q = value; match std.io.writer.write(q,ref contents[0usize..0usize]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } }
|
||||
while offset < contents.len {
|
||||
let left = contents.len - offset; let count = if left < chunk { left } else { chunk };
|
||||
match std.io.writer.write(q,ref contents[offset..offset+count]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } }
|
||||
offset = offset + count;
|
||||
if flush { match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } }
|
||||
}
|
||||
}
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
}
|
||||
let file = fs.open_read(src,b"/case/output") or trap; var bytes: [u8;12] = [255u8;12];
|
||||
match std.io.read_to_end_file(mut file,mut bytes[1usize..11usize]) { std.io.ReadToEndResult::eof(n) => { assert(n == contents.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],contents)); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } }
|
||||
assert(bytes[0] == 255u8); assert(bytes[11] == 255u8); fs.close(move file) or trap;
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let blank: [u8;1] = [0u8;1];
|
||||
reads(ref blank[0usize..0usize],0usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],0usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],0usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(b"a",0usize,1usize,src,dst,heap);
|
||||
writes(b"a",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",0usize,3usize,src,dst,heap);
|
||||
writes(b"a",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",0usize,7usize,src,dst,heap);
|
||||
writes(b"a",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",0usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",1usize,1usize,src,dst,heap);
|
||||
writes(b"a",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",1usize,3usize,src,dst,heap);
|
||||
writes(b"a",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",1usize,7usize,src,dst,heap);
|
||||
writes(b"a",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",1usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",2usize,1usize,src,dst,heap);
|
||||
writes(b"a",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",2usize,3usize,src,dst,heap);
|
||||
writes(b"a",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",2usize,7usize,src,dst,heap);
|
||||
writes(b"a",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",2usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",5usize,1usize,src,dst,heap);
|
||||
writes(b"a",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",5usize,3usize,src,dst,heap);
|
||||
writes(b"a",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",5usize,7usize,src,dst,heap);
|
||||
writes(b"a",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",5usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"abc",0usize,1usize,src,dst,heap);
|
||||
writes(b"abc",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",0usize,3usize,src,dst,heap);
|
||||
writes(b"abc",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",0usize,7usize,src,dst,heap);
|
||||
writes(b"abc",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",0usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",1usize,1usize,src,dst,heap);
|
||||
writes(b"abc",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",1usize,3usize,src,dst,heap);
|
||||
writes(b"abc",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",1usize,7usize,src,dst,heap);
|
||||
writes(b"abc",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",1usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",2usize,1usize,src,dst,heap);
|
||||
writes(b"abc",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",2usize,3usize,src,dst,heap);
|
||||
writes(b"abc",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",2usize,7usize,src,dst,heap);
|
||||
writes(b"abc",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",2usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",5usize,1usize,src,dst,heap);
|
||||
writes(b"abc",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",5usize,3usize,src,dst,heap);
|
||||
writes(b"abc",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",5usize,7usize,src,dst,heap);
|
||||
writes(b"abc",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",5usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,9usize,8usize,false,src,dst,heap);
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<mem.alloc>) -> void effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,1usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { return; } }
|
||||
} fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E4002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: ref<std.io.writer.Writer>) -> void effects [] {}
|
||||
fn bad(q: ref<std.io.writer.Writer>) -> void effects [task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,37 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:6
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=abcdef
|
||||
// schedules: 12
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn work_read(value: std.io.reader.Reader) -> file<read> effects [fs.read] { var bytes: [u8;6] = [0u8;6]; { mut q = value; exact(std.io.reader.read_exact(q,mut bytes)); } assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); return finished_reader(move value); }
|
||||
fn work_write(value: std.io.writer.Writer) -> file<write> effects [fs.write] { { mut q = value; written(std.io.writer.write(q,b"abcdef")); } return finished_writer(move value); }
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc,task.spawn,task.wait] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let a = reader(move file,3usize,heap); let file = fs.create(dst,b"/out/data") or trap; let b = writer(move file,3usize,heap);
|
||||
scope s { let a = task.spawn(s,work_read,move a); let b = task.spawn(s,work_write,move b); fs.close(task.join(move a)) or trap; fs.close(task.join(move b)) or trap; } return 42;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;8] = [255u8;8];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut bytes[1usize..5usize]));
|
||||
match std.io.reader.read_exact(q,mut bytes[5usize..8usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 2usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
assert(bytes[0] == 255u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 100u8); assert(bytes[5] == 101u8); assert(bytes[6] == 102u8); assert(bytes[7] == 255u8);
|
||||
fs.close(finished_reader(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.reader.Reader>) -> void effects [fs.read] { mut storage = q.storage; mut bytes = buffer.view(storage); std.io.reader.read(q,bytes); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 100u8); fs.close(move file) or trap;
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap;
|
||||
match std.io.reader.new(move file,4usize,heap) {
|
||||
std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => {
|
||||
let (file,error) = struct.unpack(move error); var bytes: [u8;3] = [0u8;3]; exact(std.io.read_exact_file(mut file,mut bytes)); assert(bytes[0] == 97u8); fs.close(move file) or trap;
|
||||
}
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:0
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,0usize,heap); var bytes: [u8;7] = [0u8;7];
|
||||
{ mut q = value; match std.io.reader.read_exact(q,mut bytes) { std.io.ReadExactResult::eof(n) => { assert(n == 6usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } }
|
||||
assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); fs.close(finished_reader(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let narrow = cap.narrow.budget(heap,3usize) or trap; let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,narrow); fs.close(finished_reader(move value)) or trap;
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,narrow); fs.close(finished_writer(move value)) or trap;
|
||||
let allocation = own.new([0u8;3],narrow) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
assert(byte[0] == 97u8);
|
||||
match std.io.reader.finish(move value) {
|
||||
std.io.reader.FinishResult::ok(file) => { trap; },
|
||||
std.io.reader.FinishResult::unread(value) => {
|
||||
var tail: [u8;5] = [0u8;5]; { mut q = value; exact(std.io.reader.read_exact(q,mut tail)); }
|
||||
assert(tail[0] == 98u8); assert(tail[4] == 102u8); fs.close(finished_reader(move value)) or trap;
|
||||
}
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(value: std.io.reader.Reader) -> void effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { trap; }, std.io.reader.FinishResult::unread(value) => { return; } }
|
||||
} fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap);
|
||||
{ mut q = value; written(std.io.writer.write(q,b"ab")); written(std.io.writer.write(q,b"cd")); written(std.io.writer.write(q,b"ef")); }
|
||||
fs.close(finished_writer(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.writer.Writer>) -> void effects [fs.write] { ref storage = q.storage; ref bytes = buffer.view(storage); std.io.writer.write(q,bytes); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=z
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); }
|
||||
let (file,pending,failed) = struct.unpack(std.io.writer.discard(move value)); assert(pending == 3usize); assert(not std.option.is_some::<io_error>(failed)); fs.write_all(file,b"z") or trap; fs.close(move file) or trap;
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=abc
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap;
|
||||
match std.io.writer.new(move file,4usize,heap) {
|
||||
std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.write_all(file,b"abc") or trap; fs.close(move file) or trap; }
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<write>,heap: cap<mem.alloc>) -> void effects [mem.alloc] { match std.io.writer.new(move file,3usize,heap) { std.io.writer.NewResult::ok(q) => { trap; }, std.io.writer.NewResult::err(error) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,32 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:0
|
||||
// file: /out/data=abc
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,0usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } }
|
||||
fs.close(finished_writer(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<fs.read>) -> void effects [mem.alloc] { std.io.reader.new(move file,3usize,heap); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<append>,heap: cap<mem.alloc>) -> void effects [mem.alloc] { std.io.writer.new(move file,3usize,heap); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
Reference in new issue
Block a user