aboutsummaryrefslogtreecommitdiff
path: root/src/stackStack.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-05-05 22:28:07 +0200
committerJulien Dessaux2022-05-05 22:28:07 +0200
commit582bfc893c01cccec0aae7ea7eec18bcf97cd836 (patch)
tree3822ac4b2490fc3249093e3866d1615e20eaf470 /src/stackStack.zig
parentFinished implementing the funge field (diff)
downloadzigfunge98-582bfc893c01cccec0aae7ea7eec18bcf97cd836.tar.gz
zigfunge98-582bfc893c01cccec0aae7ea7eec18bcf97cd836.tar.bz2
zigfunge98-582bfc893c01cccec0aae7ea7eec18bcf97cd836.zip
Fixed a misunderstanding about allocations (I did too much go and nim!)
Diffstat (limited to 'src/stackStack.zig')
-rw-r--r--src/stackStack.zig26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/stackStack.zig b/src/stackStack.zig
index 15578d3..717be3d 100644
--- a/src/stackStack.zig
+++ b/src/stackStack.zig
@@ -1,25 +1,27 @@
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),
+ allocator: std.mem.Allocator,
+ data: std.ArrayList(*stack.Stack),
toss: *stack.Stack,
pub fn deinit(self: *StackStack) void {
- for (self.data.items) |*s| {
+ for (self.data.items) |s| {
s.deinit();
}
self.data.deinit();
+ self.allocator.destroy(self);
}
- pub fn init(allocator: std.mem.Allocator) !StackStack {
- var ss = std.ArrayList(stack.Stack).init(allocator);
- errdefer ss.deinit();
- var s = try ss.addOne();
- s.* = stack.Stack.init(allocator);
- return StackStack{
- .data = ss,
- .toss = s,
- };
+ pub fn init(allocator: std.mem.Allocator) !*StackStack {
+ var ss = try allocator.create(StackStack);
+ errdefer allocator.destroy(ss);
+ ss.allocator = allocator;
+ ss.data = std.ArrayList(*stack.Stack).init(allocator);
+ errdefer ss.data.deinit();
+ var s = try ss.data.addOne();
+ s.* = try stack.Stack.init(allocator);
+ ss.toss = s.*;
+ return ss;
}
pub inline fn toss(self: *StackStack) *stack.Stack {
return self.toss;