1
0
Fork 0

Simplified the stack stack code

This commit is contained in:
Julien Dessaux 2022-02-20 23:17:50 +01:00
parent 8bd793daf0
commit 6997d07ac8
Signed by: adyxax
GPG key ID: F92E51B86E07177E

View file

@ -11,33 +11,18 @@ pub const StackStack = struct {
} }
self.data.deinit(); self.data.deinit();
} }
pub fn duplicate(self: *StackStack) !void {
return self.toss.*.duplicate();
}
pub fn init(allocator: std.mem.Allocator) !StackStack { pub fn init(allocator: std.mem.Allocator) !StackStack {
var ss = std.ArrayList(stack.Stack).init(allocator); var ss = std.ArrayList(stack.Stack).init(allocator);
errdefer ss.deinit(); errdefer ss.deinit();
var toss = try ss.addOne(); var s = try ss.addOne();
toss.* = stack.Stack.init(allocator); s.* = stack.Stack.init(allocator);
return StackStack{ return StackStack{
.data = ss, .data = ss,
.toss = toss, .toss = s,
}; };
} }
pub fn pop(self: *StackStack) i64 { pub inline fn toss(self: *StackStack) *stack.Stack {
return self.toss.*.pop(); return self.toss;
}
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();
} }
}; };