summaryrefslogtreecommitdiff
path: root/tests/bf
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bf')
-rw-r--r--tests/bf/bf.toc114
-rw-r--r--tests/bf/hw0.bf1
-rw-r--r--tests/bf/hw1.bf2
-rwxr-xr-xtests/bf/test.sh9
4 files changed, 0 insertions, 126 deletions
diff --git a/tests/bf/bf.toc b/tests/bf/bf.toc
deleted file mode 100644
index 2331467..0000000
--- a/tests/bf/bf.toc
+++ /dev/null
@@ -1,114 +0,0 @@
-getstdin ::= fn() []char {
-#C("extern void *stdin; extern char *fgets(char *buf, size_t sz, void *f);");
- contents : []char;
- contents_sz : int;
- contents_len : int;
- buffer : [1024]char;
- while #C("fgets(buffer, 1024, stdin)") {
- buffer_len : int;
- while buffer[buffer_len] {
- buffer_len = buffer_len + 1;
- }
- if contents_sz < contents_len + buffer_len {
- old_contents := contents;
- contents_sz = 2*contents_sz + 1024;
- contents = new(char, contents_sz);
- i := 0;
- while i < contents_len {
- contents[i] = old_contents[i];
- i = i + 1;
- }
- del(old_contents);
- }
- i := 0;
- while i < buffer_len {
- contents[contents_len] = buffer[i];
- contents_len = contents_len + 1;
- i = i + 1;
- }
- }
- contents[contents_len] = 0 as char;
- contents
-};
-
-puti ::= fn(x: int) {
- #C("#ifndef __TINYC__
-extern int printf(const char *fmt, ...);
-#endif
-");
- #C("printf(\"%ld\\n\", x);");
-};
-
-main ::= fn() {
- #C("extern int putchar(int c);");
- code := getstdin();
- tape_sz := 3;
- tape := new(int, tape_sz);
- ptr := tape_sz / 2;
- i := 0;
- while code[i] {
- // puti(ptr);
- // puti(tape_sz);
- if code[i] == '+' {
- tape[ptr] = tape[ptr]+1;
- } elif code[i] == '-' {
- tape[ptr] = tape[ptr]-1;
- } elif code[i] == '>' {
- ptr = ptr + 1;
- if ptr >= tape_sz {
- // extend to the right
- newtape := new(int, 2*tape_sz);
- j := 0;
- while j < tape_sz {
- newtape[j] = tape[j];
- j = j + 1;
- }
- tape_sz = tape_sz * 2;
- del(tape);
- tape = newtape;
- }
- } elif code[i] == '<' {
- ptr = ptr - 1;
- if ptr < 0 {
- // extend to the left
- newtape := new(int, 2*tape_sz);
- j := 0;
- while j < tape_sz {
- newtape[j+tape_sz] = tape[j];
- j = j + 1;
- }
- tape_sz = tape_sz * 2;
- del(tape);
- tape = newtape;
- ptr = ptr + tape_sz;
- }
- } elif code[i] == '[' {
- if !tape[ptr] {
- // jump to matching ]
- level := 0;
- while level >= 0 {
- i = i + 1;
- level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0});
- }
- }
- } elif code[i] == ']' {
- if tape[ptr] {
- // jump to matching [
- level := 0;
- while level <= 0 {
- i = i - 1;
- level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0});
- }
- }
- } elif code[i] == '.' {
- c := tape[ptr] as char;
- #C("putchar(c);");
- } elif code[i] == ',' {
- // Input doesn't really work, because you
- // need to send an EOF to end the program.
- }
- i = i + 1;
- }
- del(tape);
- del(code);
-};
diff --git a/tests/bf/hw0.bf b/tests/bf/hw0.bf
deleted file mode 100644
index ea2b641..0000000
--- a/tests/bf/hw0.bf
+++ /dev/null
@@ -1 +0,0 @@
-++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. \ No newline at end of file
diff --git a/tests/bf/hw1.bf b/tests/bf/hw1.bf
deleted file mode 100644
index db5525f..0000000
--- a/tests/bf/hw1.bf
+++ /dev/null
@@ -1,2 +0,0 @@
->++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----.>->
-+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. \ No newline at end of file
diff --git a/tests/bf/test.sh b/tests/bf/test.sh
deleted file mode 100755
index 8b76794..0000000
--- a/tests/bf/test.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-if [ "$(cat hw0.bf | ./bf.bin)" != "Hello World!" ]; then
- echo "hello world 0 failed."
- exit 1
-fi
-if [ "$(cat hw1.bf | ./bf.bin)" != "Hello World!" ]; then
- echo "hello world 1 failed."
- exit 1
-fi