Added rest of ALU
This commit is contained in:
parent
25837b08f9
commit
0a1b6bfb5c
2
makefile
2
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
|
||||
|
||||
|
|
26
src/modal.c
26
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;
|
||||
|
|
Loading…
Reference in New Issue