summaryrefslogtreecommitdiff
path: root/exec.ha
diff options
context:
space:
mode:
Diffstat (limited to 'exec.ha')
-rw-r--r--exec.ha24
1 files changed, 24 insertions, 0 deletions
diff --git a/exec.ha b/exec.ha
new file mode 100644
index 0000000..8b73c8b
--- /dev/null
+++ b/exec.ha
@@ -0,0 +1,24 @@
+use io;
+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 '<' =>
+ if (bf.ptr > 0)
+ bf.ptr -= 1
+ else
+ bf.ptr = mem_size - 1;
+ case '>' =>
+ if (bf.ptr < bf.ptr - 1)
+ 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 => continue;
+ };
+ };
+};