commit a1fb7231b0e8dd1e435ad63df66d1df510d66376 Author: Bertram Felgenhauer Date: Sun Jan 11 13:24:14 2026 +0100 move parse state definitions diff --git a/src/asm.c b/src/asm.c index 43eccca..2b441ef 100644 --- a/src/asm.c +++ b/src/asm.c @@ -260,6 +260,17 @@ static void cleanmem(), nocmnt(); static void automaton(), dfashell(), expand(), encode(); #endif +/* ************************* Parse state **************************** */ + +#define SNIL 0 +#define SLBL 1 +#define SVAL 2 +#define SCOM 3 +#define SPSE 4 +#define SFOR 5 +#define SROF 6 +#define SERR -1 + /* ************************** Functions ***************************** */ static ref_st * @@ -1531,17 +1542,6 @@ encode(sspnt) /* ******************************************************************* */ -#define SNIL 0 -#define SLBL 1 -#define SVAL 2 -#define SCOM 3 -#define SPSE 4 -#define SFOR 5 -#define SROF 6 -#define SERR -1 - -/* ******************************************************************* */ - static int blkfor(expr, dest) char *expr, *dest; commit 25490e73018bcb158d9191037892f96bd4139b6f Author: Bertram Felgenhauer Date: Sun Jan 11 13:26:04 2026 +0100 thread `dest` argument into `lineswitch` diff --git a/src/asm.c b/src/asm.c index 2b441ef..a24c15e 100644 --- a/src/asm.c +++ b/src/asm.c @@ -220,13 +220,13 @@ static void textout(), errprn(); #ifdef NEW_STYLE #ifndef SERVER -static void lineswitch(char *, uShrt, line_st *); +static void lineswitch(char *, char *, uShrt, line_st *); #endif static int globalswitch(char *, uShrt, uShrt, uShrt); static int trav2(char *, char *, int); static int normalize(long); static int blkfor(char *, char *); -static int equtbl(char *); +static int equtbl(char *, char *); static int equsub(char *, char *, int, ref_st *); static ref_st *lookup(char *); static grp_st *addsym(char *, grp_st *); @@ -618,8 +618,9 @@ globalswitch(str, idx, loc, lspnt) #ifndef SERVER static void -lineswitch(str, idx, aline) /* line switch */ +lineswitch(str, dest, idx, aline) /* line switch */ char *str; + char *dest; uShrt idx; line_st *aline; { @@ -1630,8 +1631,9 @@ blkfor(expr, dest) /* ******************************************************************* */ static int -equtbl(expr) +equtbl(expr, dest) char *expr; + char *dest; { line_st *cline, *pline = NULL; uChar i; @@ -1671,7 +1673,7 @@ equtbl(expr) #ifndef SERVER else if (*token == com_sym) { aline = aline->nextline; - lineswitch(aline->vline, i, aline); + lineswitch(aline->vline, dest, i, aline); } #endif else @@ -1765,7 +1767,7 @@ trav2(buffer, dest, wdecl) } #ifndef SERVER else - lineswitch(buffer, idxp, aline); + lineswitch(buffer, dest, idxp, aline); #endif } return wdecl; @@ -1809,7 +1811,7 @@ trav2(buffer, dest, wdecl) if (statefine) return SNIL; else if (wdecl <= SLBL) - return equtbl((char *) buffer + idxp); + return equtbl((char *) buffer + idxp, dest); else errprn(APPERR, aline, token); commit 8542d4257cfe047d43e13574f4d0b53e370a961f Author: Bertram Felgenhauer Date: Sun Jan 11 13:31:11 2026 +0100 move `;ASSERT` handling into `lineswitch()` This allows assertions immediately following an `equ` to work, both with and without SERVER defined. Example: ;redcode foo equ 42 ;assert 0 nop foo Before this patch, the assertion would only trigger when SERVER was defined. diff --git a/src/asm.c b/src/asm.c index a24c15e..8d7877b 100644 --- a/src/asm.c +++ b/src/asm.c @@ -219,9 +219,7 @@ static void textout(), errprn(); /* ***************** conforming local prototypes ******************** */ #ifdef NEW_STYLE -#ifndef SERVER static void lineswitch(char *, char *, uShrt, line_st *); -#endif static int globalswitch(char *, uShrt, uShrt, uShrt); static int trav2(char *, char *, int); static int normalize(long); @@ -244,9 +242,7 @@ static void automaton(char *, stateCol, mem_struct *); static void dfashell(char *, mem_struct *); static void expand(uShrt), encode(uShrt); #else -#ifndef SERVER static void lineswitch(); -#endif static int globalswitch(), trav2(), normalize(); static int blkfor(), equtbl(), equsub(); static ref_st *lookup(); @@ -616,7 +612,6 @@ globalswitch(str, idx, loc, lspnt) /* ******************************************************************* */ -#ifndef SERVER static void lineswitch(str, dest, idx, aline) /* line switch */ char *str; @@ -624,11 +619,33 @@ lineswitch(str, dest, idx, aline) /* line switch */ uShrt idx; line_st *aline; { + int evalerr; uChar i; i = (uChar) idx; get_token(str, &i, token); to_upper(token); + if (strcmp(token, "ASSERT") == 0) { + long result; + + trav2((char *) str + i, dest, SVAL); + + if (SWITCH_V) { + sprintf(outs, currentAssertMsg, dest); + textout(outs); + } + if ((evalerr = eval_expr(dest, &result)) < OK_EXPR) + errprn(BASERR, aline, ""); + else { + if (evalerr == OVERFLOW) + errprn(OFLERR, aline, ""); + noassert = FALSE; + if (result == 0L) + errprn(CHKERR, aline, ""); + } + } + +#ifndef SERVER if (strcmp(token, "DEBUG") == 0) { get_token(str, &i, token); to_upper(token); @@ -654,8 +671,8 @@ lineswitch(str, dest, idx, aline) /* line switch */ errprn(IGNORE, aline, str); } } -} #endif +} /* ******************************************************************* */ @@ -1669,14 +1686,10 @@ equtbl(expr, dest) pline = pline->nextline = cline; } else MEMORYERROR; - } -#ifndef SERVER - else if (*token == com_sym) { + } else if (*token == com_sym) { aline = aline->nextline; lineswitch(aline->vline, dest, i, aline); - } -#endif - else + } else break; } } else @@ -1739,37 +1752,8 @@ trav2(buffer, dest, wdecl) return wdecl; case COMMTOKEN: - if ((wdecl == SNIL) && (statefine == 0)) { - - uChar idx; - - idx = idxp; - get_token(buffer, &idx, token); - to_upper(token); - if (strcmp(token, "ASSERT") == 0) { - long result; - - trav2((char *) buffer + idx, dest, SVAL); - - if (SWITCH_V) { - sprintf(outs, currentAssertMsg, dest); - textout(outs); - } - if ((evalerr = eval_expr(dest, &result)) < OK_EXPR) - errprn(BASERR, aline, ""); - else { - if (evalerr == OVERFLOW) - errprn(OFLERR, aline, ""); - noassert = FALSE; - if (result == 0L) - errprn(CHKERR, aline, ""); - } - } -#ifndef SERVER - else - lineswitch(buffer, dest, idxp, aline); -#endif - } + if ((wdecl == SNIL) && (statefine == 0)) + lineswitch(buffer, dest, idxp, aline); return wdecl; case CHARTOKEN: