From 19c70b8eaa1126f1648b009d99092432a5c88059 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 1 Sep 2017 18:14:43 +0200 Subject: Structs + typedefs --- bf.lang | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'bf.lang') 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]; -- cgit v1.2.3-70-g09d2