aboutsummaryrefslogtreecommitdiff
path: root/src/stack.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-08-14 00:08:32 +0200
committerJulien Dessaux2022-08-14 00:08:32 +0200
commit307183aad7d2a2d2bf8253621cd120441d487d00 (patch)
treed7e31b41d1f9d71a09e3478f248c30b69a193b29 /src/stack.zig
parentAdd environment handling (diff)
downloadzigfunge98-307183aad7d2a2d2bf8253621cd120441d487d00.tar.gz
zigfunge98-307183aad7d2a2d2bf8253621cd120441d487d00.tar.bz2
zigfunge98-307183aad7d2a2d2bf8253621cd120441d487d00.zip
Implemented the y command requirements
Diffstat (limited to '')
-rw-r--r--src/stack.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/stack.zig b/src/stack.zig
index e02cb20..09edd2e 100644
--- a/src/stack.zig
+++ b/src/stack.zig
@@ -147,6 +147,16 @@ pub const Stack = struct {
const emptyResult2 = [_]i64{ 4, 5 };
try std.testing.expectEqualSlices(i64, empty.data.items, emptyResult2[0..]);
}
+ pub fn yCommandPick(self: *Stack, n: usize, h: usize) !void {
+ if (n > self.data.items.len) {
+ self.data.items.len = 1;
+ self.data.items[0] = 0;
+ } else {
+ const v = self.data.items[self.data.items.len - n];
+ self.data.items.len = h;
+ try self.push(v);
+ }
+ }
};
test "all" {