Keep input format during arithmetic

This commit is contained in:
Devine Lu Linvega 2024-05-13 15:14:37 -07:00
parent f88bb1f137
commit 5419d9579a
2 changed files with 8 additions and 3 deletions

View File

@ -2,4 +2,9 @@
?(?: ?:) \101
?(?: ?:) \#6c
?(?: ?:) \108
?(?: ?:) \#6f
?(?: ?:) \#6f
?(?: ?:) \#ce
?(?: ?:) \#bb
?((?: ?0 ?1) ?:) + #34 #67

View File

@ -59,7 +59,7 @@ device_write(char *s)
char **reg = regs + '0';
/* phase: ALU */
if(*reg) {
int acc = sint(*reg++);
int hex = **reg == '#', acc = sint(*reg++);
/* clang-format off */
switch(*s) {
case '+': while(*reg) acc += sint(*reg++); break;
@ -76,7 +76,7 @@ device_write(char *s)
case '<': while(*reg) acc = acc < sint(*reg++); break;
}
/* clang-format on */
dst_ += snprintf(dst_, 0x10, "%d", acc);
dst_ += snprintf(dst_, 0x10, hex ? "#%x" : "%d", acc);
return;
} else {
/* phase: string */