app: add initial files

This commit is contained in:
Arran Ireland
2025-01-05 22:25:53 +00:00
parent 35e086b22a
commit 23edae31a1
6 changed files with 67 additions and 0 deletions

2
app/driver.zig Normal file
View File

@@ -0,0 +1,2 @@
pub const Default = LinkLocal;
pub const LinkLocal = @import("driver/LinkLocal.zig");

1
app/driver/LinkLocal.zig Normal file
View File

@@ -0,0 +1 @@
// TODO: Implement.

1
app/main.zig Normal file
View File

@@ -0,0 +1 @@
// TODO: Implement.

25
app/os/Clock.zig Normal file
View File

@@ -0,0 +1,25 @@
const std = @import("std");
const Timer = std.time.Timer;
const Clock = @import("../Clock.zig");
const Self = @This();
timer: Timer,
pub fn init() Timer.Error!Self {
return .{
.timer = try Timer.start(),
};
}
pub fn monotonicMicros(ptr: *anyopaque) u64 {
const self: *Self = @ptrCast(@alignCast(ptr));
return self.timer.read();
}
pub fn clock(self: *Self) Clock {
return .{
.ptr = self,
.monotonicMicrosFn = monotonicMicros,
};
}

25
app/os/Os.zig Normal file
View File

@@ -0,0 +1,25 @@
const std = @import("std");
const Timer = std.time.Timer;
const System = @import("../System.zig");
pub const Clock = @import("os/Clock.zig");
pub const Rng = @import("os/Rng.zig");
const Self = @This();
clock: Clock,
rng: Rng,
pub fn init() Timer.Error!Self {
return Self{
.clock = try Clock.init(),
.rng = Rng.init(),
};
}
pub fn system(self: *Self) System {
return System{
.clock = self.clock.clock(),
.rng = self.rng.rng(),
};
}

13
app/os/Rng.zig Normal file
View File

@@ -0,0 +1,13 @@
const std = @import("std");
const Rng = @import("../../System.zig").Rng;
const Self = @This();
pub fn init() Self {
return .{};
}
pub fn rng(self: *Self) Rng {
_ = self;
return std.crypto.random;
}