Skip to content
Permalink
Browse files

work with 0.3.0x

  • Loading branch information...
jfo committed Jan 13, 2019
1 parent 89bd752 commit 7b1c563a9bd20e084243bfa0c7435e3cb468ccf2
Showing with 8 additions and 4 deletions.
  1. +8 −4 bf.zig
12 bf.zig
@@ -32,7 +32,8 @@ fn seekForward(src: []const u8, srcptr: u16) !u16 {
}

pub fn bf(src: []const u8, storage: []u8) !void {
const stdout = &(io.FileOutStream.init(&(try io.getStdOut())).stream);
const stdout = try std.io.getStdOut();
var outbuf: [1]u8 = undefined;

var memptr: u16 = 0;
var srcptr: u16 = 0;
@@ -42,9 +43,12 @@ pub fn bf(src: []const u8, storage: []u8) !void {
'-' => storage[memptr] -%= 1,
'>' => memptr += 1,
'<' => memptr -= 1,
'[' => if (storage[memptr] == 0) srcptr = try seekForward(src, srcptr),
']' => if (storage[memptr] != 0) srcptr = try seekBack(src, srcptr),
'.' => try stdout.print("{c}", storage[memptr]),
'[' => if (storage[memptr] == 0) { srcptr = try seekForward(src, srcptr); },
']' => if (storage[memptr] != 0) { srcptr = try seekBack(src, srcptr); },
'.' => {
const char = try std.fmt.bufPrint(outbuf[0..], "{c}", storage[memptr]);
try stdout.write(char);
},
else => {}
}
srcptr += 1;

0 comments on commit 7b1c563

Please sign in to comment.
You can’t perform that action at this time.