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

@ -3,3 +3,8 @@
?(?: ?:) \#6c
?(?: ?:) \108
?(?: ?:) \#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 */