summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Dir.zig13
-rw-r--r--core/root.zig2
-rw-r--r--core/tape.zig11
3 files changed, 15 insertions, 11 deletions
diff --git a/core/Dir.zig b/core/Dir.zig
index 1be67378..3c74d704 100644
--- a/core/Dir.zig
+++ b/core/Dir.zig
@@ -46,17 +46,17 @@ pub fn ofName(name: []const u8) []const u8 {
/// (plan9port lib9 dirread, acme's dircmp): every name but `.` and `..`,
/// dotfiles too; a directory's, a link to one's too, ending in `/`; sorted
/// bytewise, the `/` counted; each ending in a newline.
-pub fn read(gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
+pub fn read(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
if (comptime !filesystem.platform_has_fs) return error.FileNotFound;
const local = filesystem.localPath(dir) orelse return error.NotLocal;
// Its own copy: the caller's may be a pane's, gone while the turn is out.
var own: [4096]u8 = undefined;
if (local.len > own.len) return error.NameTooLong;
@memcpy(own[0..local.len], local);
- return pardes.tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
+ return tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
}
-fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
+fn readHost(io: std.Io, gpa: std.mem.Allocator, local: []const u8) ![]u8 {
var entries: std.ArrayList([]u8) = .empty;
defer {
for (entries.items) |entry| gpa.free(entry);
@@ -64,7 +64,6 @@ fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
}
var total: usize = 0;
{
- const io = std.Io.Threaded.global_single_threaded.io();
var d = try std.Io.Dir.cwd().openDir(io, local, .{ .iterate = true });
defer d.close(io);
var it = d.iterate();
@@ -165,7 +164,7 @@ pub fn fit(p: *Pardes, pane: *Pane, cols: usize) void {
pub fn refresh(p: *Pardes, id: usize) !void {
const pane = p.panes[id] orelse return error.NoPane;
const serial = pane.serial;
- const names = try read(p.gpa, ofName(pane.file.?.path));
+ const names = try read(p.tape, p.gpa, ofName(pane.file.?.path));
// The pane may have closed while the turn was out.
const now = p.panes[id] orelse return p.gpa.free(names);
if (now.serial != serial) return p.gpa.free(names);
@@ -195,7 +194,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void {
}
var said: [limits.host_path_cap + 16]u8 = undefined;
const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit
- const names = read(p.gpa, dir) catch |err| {
+ const names = read(p.tape, p.gpa, dir) catch |err| {
p.gpa.free(name);
return p.reportError(from, what, err);
};
@@ -307,7 +306,7 @@ test "a directory reads as acme lists it: dotfiles kept, . and .. not, directori
try tmp.dir.symLink(io, "a", "link", .{ .is_directory = true });
var buf: [4096]u8 = undefined;
const dir = buf[0..try tmp.dir.realPath(io, &buf)];
- const names = try read(testing.allocator, dir);
+ const names = try read(&pardes.tape.none, testing.allocator, dir);
defer testing.allocator.free(names);
// Bytewise, as dircmp's memcmp: `.` before capitals before small
// letters, and `a.d/` before `a/` because `.` is before `/`.
diff --git a/core/root.zig b/core/root.zig
index 154467e5..53ee2ba2 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -608,7 +608,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{
.{ "Addon.zig", 48, "the process's addon libraries: the start's scan of their directories, dlopen, the crash mark; the host's, never a step's" },
.{ "Core.zig", 5, "the session's directory read once at its start (taped), a frame log (PARDES_FRAMES), a host_io type" },
.{ "Db.zig", 18, "the state file every session of the user shares: the authority's (`db`), off in every replica" },
- .{ "Dir.zig", 2, "a directory's listing, the function under tape.site(.dir_listing)" },
+ .{ "Dir.zig", 1, "a directory's listing, the function under tape.site(.dir_listing), its io the tape's" },
.{ "Effect.zig", 1, "host_io, named for the host entries it performs" },
.{ "FrameStats.zig", 7, "a frame's clock and log: frames are local, never digested" },
.{ "Handover.zig", 29, "a window carried to another process over a socket: the session's host" },
diff --git a/core/tape.zig b/core/tape.zig
index 52eb6c03..19fdccd1 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -806,8 +806,13 @@ pub const Tape = struct {
return t.value(.budget, overNow, .{ since_ns, budget_ns });
}
+ /// A body whose first parameter is an `std.Io` its caller does not pass
+ /// is handed the tape's (`args` are the rest): the only way core/ comes
+ /// to hold one.
fn call(t: *Tape, comptime s: Site, a: ?std.mem.Allocator, comptime f: anytype, args: anytype, comptime yields: bool) @typeInfo(@TypeOf(f)).@"fn".return_type.? {
const R = @typeInfo(@TypeOf(f)).@"fn".return_type.?;
+ const params = @typeInfo(@TypeOf(f)).@"fn".param_types;
+ const full = if (comptime params.len == args.len + 1 and params[0] == std.Io) .{t.io} ++ args else args;
comptime {
const Listed = if (@typeInfo(R) == .error_union) anyerror!@typeInfo(R).error_union.payload else R;
for (results) |T| {
@@ -815,7 +820,7 @@ pub const Tape = struct {
} else @compileError("tape: the site ." ++ @tagName(s) ++ " returns " ++ @typeName(R) ++ ", which tape.results does not list");
}
// No tape where there is no host to record or replay one.
- if (t.through) return if (yields) out(f, args) else @call(.auto, f, args);
+ if (t.through) return if (yields) out(f, full) else @call(.auto, f, full);
const id: u16 = @as(u16, host_fns.len) + @backingInt(s);
if (comptime s == .read_file) t.reading = args[1];
defer if (comptime s == .read_file) {
@@ -833,7 +838,7 @@ pub const Tape = struct {
}
// The host's own (a shell's spawn asking the shell), or one inside a
// site's syscall: the outer call is the record.
- if (t.host_side) return if (yields) out(f, args) else @call(.auto, f, args);
+ if (t.host_side) return if (yields) out(f, full) else @call(.auto, f, full);
// A syscall a speculating replica must not make: its input waits for
// the authority's answer.
if (yields and t.speculating) {
@@ -850,7 +855,7 @@ pub const Tape = struct {
t.record(.host, u16, &id);
t.seeFields();
t.host_side = true;
- const r = if (yields) out(f, args) else @call(.auto, f, args);
+ const r = if (yields) out(f, full) else @call(.auto, f, full);
t.host_side = false;
t.noteWrites();
t.record(.ret, R, &r);