From c2ffe63cc3c07f96a407204d21462aaaea769900 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Thu, 14 Apr 2022 18:24:48 +0100 Subject: [PATCH] (uxnasm) Fix valid macro names being rejected. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Macro names that begin with the name of an opcode were being rejected incorrectly. “STA” would not be a valid macro name since it is an opcode, but “STACK” should be fine. --- src/uxnasm.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/uxnasm.c b/src/uxnasm.c index fdc746b..6fd743c 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -99,30 +99,27 @@ findlabel(char *name) return NULL; } -static Uint8 -findmode(char *s) -{ - int i = 0; - while(s[0]) { - switch(s[0]) { - case '2': i |= (1 << 5); break; /* mode: short */ - case 'r': i |= (1 << 6); break; /* mode: return */ - case 'k': i |= (1 << 7); break; /* mode: keep */ - } - s++; - } - return i; -} - static Uint8 findopcode(char *s) { int i; for(i = 0; i < 0x20; i++) { + int m = 0; if(!scmp(ops[i], s, 3)) continue; if(!i) i |= (1 << 7); /* force keep for LIT */ - return i |= findmode(s + 3); + while(s[3 + m]) { + if(s[3 + m] == '2') + i |= (1 << 5); /* mode: short */ + else if(s[3 + m] == 'r') + i |= (1 << 6); /* mode: return */ + else if(s[3 + m] == 'k') + i |= (1 << 7); /* mode: keep */ + else + return 0; /* failed to match */ + m++; + } + return i; } return 0; }