aboutsummaryrefslogtreecommitdiff
path: root/bf.lang
diff options
context:
space:
mode:
Diffstat (limited to 'bf.lang')
-rw-r--r--bf.lang20
1 files changed, 6 insertions, 14 deletions
diff --git a/bf.lang b/bf.lang
index c42f73d..0ce6389 100644
--- a/bf.lang
+++ b/bf.lang
@@ -1,3 +1,5 @@
+type byte := char;
+
func putstr(char[] str) {
int i := 0;
while (str[i] != '\0') {
@@ -6,16 +8,6 @@ func putstr(char[] str) {
}
}
-func int strlen(char[] str) {
- int i := 0;
- char c := str[i];
- while (c != '\0') {
- i = i + 1;
- c = str[i];
- }
- return i;
-}
-
func int[] makejumpmap(char[] src, int srclen) {
int[] jm := new int[srclen];
int[] stack := new int[srclen];
@@ -51,18 +43,18 @@ func int[] makejumpmap(char[] src, int srclen) {
func interpret(char[] src, int srclen) {
int[] jm := makejumpmap(src, srclen);
- char[] mem := new char[4088];
+ byte[] mem := new char[4088];
int ip := 0;
int memp := 0;
while (src[ip] != '\0') {
// putint(ip); putc('\n');
char c := src[ip];
- if (c == '+') {mem[memp] = mem[memp] + char(1);}
- if (c == '-') {mem[memp] = mem[memp] - char(1);}
+ if (c == '+') {mem[memp] = mem[memp] + byte(1);}
+ if (c == '-') {mem[memp] = mem[memp] - byte(1);}
if (c == '>') {memp = memp + 1;}
if (c == '<') {memp = memp - 1;}
if (c == '.') {putc(mem[memp]);}
- if (c == ',') {mem[memp] = char(getc());}
+ if (c == ',') {mem[memp] = byte(getc());}
if (c == '[') {
if (mem[memp] == '\0') {
ip = jm[ip];