diff --git a/makefile b/makefile index 24e2457..563ad91 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ RELEASE_flags=-DNDEBUG -O2 -g0 -s -DEBUG_flags=-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined +DEBUG_flags=-std=c99 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined .PHONY: all debug dest run debug test install uninstall format clean archive diff --git a/src/modal.c b/src/modal.c index bd87ae0..f3d95ae 100644 --- a/src/modal.c +++ b/src/modal.c @@ -44,17 +44,25 @@ static void device_write(char *s) { int acc = 0; - char c = *s, *cap = walk(s), *reg = regs['0']; - if(reg) { + char c = *s, *cap = walk(s), **reg = regs + '0'; + /* phase: ALU */ + if(*reg) { switch(c) { - case '+': - for(acc = sint(reg++); *reg; reg++) acc = acc + sint(reg); - break; + /* clang-format off */ + case '+': for(acc = sint(*reg++); *reg != 0; reg++) acc += sint(*reg); break; + case '-': for(acc = sint(*reg++); *reg != 0; reg++) acc -= sint(*reg); break; + case '*': for(acc = sint(*reg++); *reg != 0; reg++) acc *= sint(*reg); break; + case '/': for(acc = sint(*reg++); *reg != 0; reg++) acc /= sint(*reg); break; + case '%': for(acc = sint(*reg++); *reg != 0; reg++) acc %= sint(*reg); break; + case '&': for(acc = sint(*reg++); *reg != 0; reg++) acc &= sint(*reg); break; + case '^': for(acc = sint(*reg++); *reg != 0; reg++) acc ^= sint(*reg); break; + case '|': for(acc = sint(*reg++); *reg != 0; reg++) acc |= sint(*reg); break; + /* clang-format on */ } - dst_ += snprintf(dst_, 0x10, "%d\n", acc); + dst_ += snprintf(dst_, 0x10, "%d", acc); return; } - + /* phase: string */ if(*s == '(') s++, --cap; while(s < cap) { c = *s++; @@ -70,7 +78,7 @@ device_write(char *s) } static void -device_read(char *s) +device_read(void) { char c; while(fread(&c, 1, 1, stdin) && c >= ' ') @@ -90,7 +98,7 @@ write_reg(char r, char *reg) return; case '<': /* op: input */ case '~': - device_read(reg); + device_read(); return; case '^': /* op: join */ if(*reg == '(') reg++, --cap;