diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-09-01 18:14:43 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-09-01 18:15:25 +0200 |
commit | 19c70b8eaa1126f1648b009d99092432a5c88059 (patch) | |
tree | bd4171a4d6ef5e8ae2b09e1c84bf3e2346374e97 /bf.lang | |
parent | 3d5d85e00f2a81efb62bb17f8e5db63fe5a49a61 (diff) |
Structs + typedefs
Diffstat (limited to 'bf.lang')
-rw-r--r-- | bf.lang | 20 |
1 files changed, 6 insertions, 14 deletions
@@ -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]; |