From 5419d9579adc072b77adb56bd8ef25e95c83ee8f Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 13 May 2024 15:14:37 -0700 Subject: [PATCH] Keep input format during arithmetic --- examples/binary.modal | 7 ++++++- src/modal.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/binary.modal b/examples/binary.modal index 9a98afc..106f046 100644 --- a/examples/binary.modal +++ b/examples/binary.modal @@ -2,4 +2,9 @@ ?(?: ?:) \101 ?(?: ?:) \#6c ?(?: ?:) \108 -?(?: ?:) \#6f \ No newline at end of file +?(?: ?:) \#6f + +?(?: ?:) \#ce +?(?: ?:) \#bb + +?((?: ?0 ?1) ?:) + #34 #67 diff --git a/src/modal.c b/src/modal.c index 13a886c..08d4bc4 100644 --- a/src/modal.c +++ b/src/modal.c @@ -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 */