aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/stub.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/stub.zig')
-rw-r--r--src/frontend/stub.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/frontend/stub.zig b/src/frontend/stub.zig
new file mode 100644
index 0000000..d6e7fc8
--- /dev/null
+++ b/src/frontend/stub.zig
@@ -0,0 +1,57 @@
+const std = @import("std");
+const Action = @import("../actions.zig").Action;
+const IOInterface = @import("io_interface.zig").IOInterface;
+
+pub const ActionStack = struct {
+ stream: std.ArrayList(Action),
+
+ pub fn init(allocator: std.mem.Allocator) ActionStack {
+ return ActionStack{
+ .stream = std.ArrayList(Action).init(allocator),
+ };
+ }
+
+ pub fn deinit(self: *ActionStack) void {
+ self.stream.deinit();
+ }
+
+ pub fn scheduleAction(self: *ActionStack, action: Action) !void {
+ try self.stream.append(action);
+ }
+
+ pub fn next(self: *ActionStack) ?Action {
+ return self.stream.popOrNull();
+ }
+};
+
+pub const IO = struct {
+ allocator: std.mem.Allocator,
+ as: ActionStack,
+ out_as: ActionStack,
+
+ pub fn displayMessage(self: *IO, str: []const u8) anyerror!void {
+ _ = self;
+ std.log.info("{s}\n", .{str});
+ }
+
+ pub fn waitForTick(self: *IO) anyerror!Action {
+ const a = self.as.next() orelse return error.NoAvailableAction;
+
+ try self.out_as.scheduleAction(a);
+
+ return a;
+ }
+
+ pub fn init(allocator: std.mem.Allocator, as: ActionStack) !IOInterface {
+ var io = try allocator.create(IO);
+ io.allocator = allocator;
+ io.as = as;
+ io.out_as = ActionStack.init(allocator);
+ return IOInterface.init(io);
+ }
+
+ pub fn deinit(self: *IO) void {
+ self.out_as.deinit();
+ self.allocator.destroy(self);
+ }
+};