diff options
author | Julien Dessaux | 2022-02-18 01:07:53 +0100 |
---|---|---|
committer | Julien Dessaux | 2022-02-18 01:07:53 +0100 |
commit | 629923b3c97c0d52bc354f5294567b1fefa698e5 (patch) | |
tree | ff16901684d7ae07991a44c86beb2fcf8bc70455 | |
parent | fixed the funge stack types (diff) | |
download | zigfunge98-629923b3c97c0d52bc354f5294567b1fefa698e5.tar.gz zigfunge98-629923b3c97c0d52bc354f5294567b1fefa698e5.tar.bz2 zigfunge98-629923b3c97c0d52bc354f5294567b1fefa698e5.zip |
Began implementing the funge98 stack stack
Diffstat (limited to '')
-rw-r--r-- | src/main.zig | 2 | ||||
-rw-r--r-- | src/stackStack.zig | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index c2869f0..ba33d96 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const stack = @import("stack.zig"); +const stackStack = @import("stackStack.zig"); pub fn main() anyerror!void { std.log.info("All your codebase are belong to us.", .{}); diff --git a/src/stackStack.zig b/src/stackStack.zig new file mode 100644 index 0000000..820010f --- /dev/null +++ b/src/stackStack.zig @@ -0,0 +1,46 @@ +const std = @import("std"); +const stack = @import("stack.zig"); +const vector = std.meta.Vector(2, i64); + +pub const StackStack = struct { + data: std.ArrayList(stack.Stack), + toss: *stack.Stack, + pub fn deinit(self: *StackStack) void { + for (self.data.items) |*s| { + s.deinit(); + } + self.data.deinit(); + } + pub fn duplicate(self: *StackStack) !void { + return self.toss.*.duplicate(); + } + pub fn init(allocator: std.mem.Allocator) !StackStack { + var ss = std.ArrayList(stack.Stack).init(allocator); + errdefer ss.deinit(); + var toss = try ss.addOne(); + toss.* = stack.Stack.init(allocator); + return StackStack{ + .data = ss, + .toss = toss, + }; + } + pub fn pop(self: *StackStack) i64 { + return self.toss.*.pop(); + } + pub fn popVector(self: *StackStack) [2]i64 { + return self.toss.*.popVector(); + } + pub fn push(self: *StackStack, n: i64) !void { + return self.toss.*.append(n); + } + pub fn pushVector(self: *StackStack, v: [2]i64) !void { + return self.toss.*.pushVector(v); + } + pub fn swap(self: *StackStack) !void { + return self.toss.*.swap(); + } +}; + +test "all" { + std.testing.refAllDecls(@This()); +} |