From 08ee35a3c6d5cf5ec89d55c6f25f4acdfe703b13 Mon Sep 17 00:00:00 2001 From: kdx Date: Thu, 19 Jan 2023 00:29:29 +0100 Subject: input is kinda ok --- exec.ha | 12 ++++++++---- test.bf | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/exec.ha b/exec.ha index 8b73c8b..3950bac 100644 --- a/exec.ha +++ b/exec.ha @@ -4,8 +4,10 @@ use os; fn exec(bf: *Brainfuck, b: []const u8) void = { for (let i = 0z; i < len(b); i += 1) { switch (b[i]) { - case '+' => bf.mem[bf.ptr] += 1; - case '-' => bf.mem[bf.ptr] -= 1; + case '+' => + bf.mem[bf.ptr] += 1; + case '-' => + bf.mem[bf.ptr] -= 1; case '<' => if (bf.ptr > 0) bf.ptr -= 1 @@ -16,8 +18,10 @@ fn exec(bf: *Brainfuck, b: []const u8) void = { bf.ptr += 1 else bf.ptr = 0; - case '.' => io::write(os::stdout, bf.mem[bf.ptr..bf.ptr])!; - case ',' => io::read(os::stdin, bf.mem[bf.ptr..bf.ptr])!; + case '.' => + io::write(os::stdout, bf.mem[bf.ptr .. bf.ptr + 1])!; + case ',' => + io::read(os::stdin, bf.mem[bf.ptr .. bf.ptr + 1])!; case => continue; }; }; diff --git a/test.bf b/test.bf index 3b759f3..3670b41 100644 --- a/test.bf +++ b/test.bf @@ -10,4 +10,4 @@ j+++ dawjdwadjwa A-da_d-wad AW-d_DW- -,.+,-.+..-.. +,.>,<.>..<.. -- cgit v1.2.3