From: Lukas Krickl Date: Tue, 5 Nov 2024 11:16:50 +0000 (+0100) Subject: Added the ability to use defined consts inside of defines X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=f954eff469916cd9d5ed94edd219989705cd5507;p=ulas%2F.git Added the ability to use defined consts inside of defines --- diff --git a/src/ulas.c b/src/ulas.c index a7767aa..7e2a234 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -803,6 +803,21 @@ void ulas_trimend(char c, char *buf, unsigned long n) { } } +void ulas_preprocexpand_rec(struct ulas_preproc *pp) { + // expand macro result again to allow + // defines to appear in the macro + ulas_strensr(&pp->line2, strlen(pp->line.buf) + 1); + sprintf(pp->line2.buf, "%s", pp->line.buf); + unsigned long n = strlen(pp->line.buf); + pp->exp_depth++; + if (pp->exp_depth > ULAS_PREPROC_MAX_MACRO_DEPTH) { + ULASERR("Max macro recursion depth reached\n"); + return; + } + ulas_preprocexpand(pp, pp->line2.buf, &n); + pp->exp_depth--; +} + char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, unsigned long *n) { const char *praw_line = raw_line; @@ -855,6 +870,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, } else { strncat(pp->line.buf, def->value, val_len); } + ulas_preprocexpand_rec(pp); } break; } @@ -959,18 +975,7 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, strncat(pp->line.buf, tocat, tocatlen); } } - // expand macro result again to allow - // defines to appear in the macro - ulas_strensr(&pp->line2, strlen(pp->line.buf) + 1); - sprintf(pp->line2.buf, "%s", pp->line.buf); - unsigned long n = strlen(pp->line.buf); - pp->exp_depth++; - if (pp->exp_depth > ULAS_PREPROC_MAX_MACRO_DEPTH) { - ULASERR("Max macro recursion depth reached\n"); - goto end; - } - ulas_preprocexpand(pp, pp->line2.buf, &n); - pp->exp_depth--; + ulas_preprocexpand_rec(pp); goto end; } } diff --git a/tests/t0.s b/tests/t0.s index 10a7bee..66b53bd 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -168,7 +168,8 @@ toplevel 5, 6 xor a, a #endif -#define DEFARG 1 +#define DEFDEF 1 +#define DEFARG DEFDEF #macro defarg .db $1 + 1, $2