diff options
author | Julien Dessaux | 2022-06-09 23:17:53 +0200 |
---|---|---|
committer | Julien Dessaux | 2022-06-09 23:18:27 +0200 |
commit | 75fc1506e59c1eaa52971d20df72c7cbeca5ac82 (patch) | |
tree | 09ac84d955f9fc1f7c8bc5a11415f765296de42b /src/pointer.zig | |
parent | Added submodules for the spec and the mycology test suite (diff) | |
download | zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.tar.gz zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.tar.bz2 zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.zip |
Pass the sanity test
Diffstat (limited to '')
-rw-r--r-- | src/pointer.zig | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pointer.zig b/src/pointer.zig index dcbca46..485a485 100644 --- a/src/pointer.zig +++ b/src/pointer.zig @@ -203,11 +203,19 @@ pub const Pointer = struct { 'o' => return error.NotImplemented, '=' => return error.NotImplemented, 't' => return error.NotImplemented, - else => return error.NotImplemented, + else => if (!p.redirect(c)) { + if (c >= '0' and c <= '9') { + try p.ss.toss.push(c - '0'); + } else if (c >= 'a' and c <= 'f') { + try p.ss.toss.push(c - 'a' + 10); + } else { + p.reverse(); + } + }, } return null; } - fn exec(self: *Pointer) !?pointerReturn { + pub fn exec(self: *Pointer) !?pointerReturn { // Advances to the next instruction of the field and executes it // Returns non nil if the pointer terminated, and a return code if // the program should terminate completely @@ -279,7 +287,7 @@ pub const Pointer = struct { p.dy = 0; }, '?' => { - const directions = []i8{ 0, -1, 1, 0, 0, 1, -1, 0 }; + const directions = [_]i8{ 0, -1, 1, 0, 0, 1, -1, 0 }; const r = 2 * p.rand.intRangeAtMost(u8, 0, 3); p.dx = directions[r]; p.dy = directions[r + 1]; |