From f07c9045f5bf60ccd821a33bb4ebf06d06fe7c48 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Thu, 27 Apr 2017 20:43:28 +0200 Subject: [PATCH] Prepare for macros being defined in "other ways" which are not yet put in the macro definition table. --- assemble.c | 4 ++-- macros.c | 23 ++++++++++++++--------- macros.h | 4 ++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/assemble.c b/assemble.c index b20c866..e1b1b9a 100644 --- a/assemble.c +++ b/assemble.c @@ -632,7 +632,7 @@ static int assemble( saveline = stmtno; list_level = -1; - mac = defmacro(maccp, &macstack, TRUE); + mac = defmacro(maccp, &macstack, CALLED_NOLIST); if (mac == NULL) { report(stack->top, "Failed to define macro " "called %s\n", label); } @@ -652,7 +652,7 @@ static int assemble( case P_MACRO: { - MACRO *mac = defmacro(cp, stack, FALSE); + MACRO *mac = defmacro(cp, stack, CALLED_NORMAL); return mac != NULL; } diff --git a/macros.c b/macros.c index 5dbc810..6b440b2 100644 --- a/macros.c +++ b/macros.c @@ -91,7 +91,8 @@ void read_body( break; } - if (!called && (list_level - 1 + list_md) > 0) { + if (!(called & CALLED_NOLIST) && + (list_level - 1 + list_md) > 0) { list_flush(); list_source(stack->top, nextline); } @@ -185,17 +186,21 @@ MACRO *defmacro( return NULL; } - /* Allow redefinition of a macro; new definition replaces the old. */ - mac = (MACRO *) lookup_sym(label, ¯o_st); - if (mac) { - /* Remove from the symbol table... */ - remove_sym(&mac->sym, ¯o_st); - free_macro(mac); + if (!(called & CALLED_NODEFINE)) { + /* Allow redefinition of a macro; new definition replaces the old. */ + mac = (MACRO *) lookup_sym(label, ¯o_st); + if (mac) { + /* Remove from the symbol table... */ + remove_sym(&mac->sym, ¯o_st); + free_macro(mac); + } } mac = new_macro(label); - add_table(&mac->sym, ¯o_st); + if (!(called & CALLED_NODEFINE)) { + add_table(&mac->sym, ¯o_st); + } argtail = &mac->args; cp = skipdelim(cp); @@ -245,7 +250,7 @@ MACRO *defmacro( gb = new_buffer(); - if (!called && !list_md) { + if (!(called & CALLED_NOLIST) && !list_md) { list_level--; levelmod = 1; } diff --git a/macros.h b/macros.h index 212ecc7..b4af2a6 100644 --- a/macros.h +++ b/macros.h @@ -46,6 +46,10 @@ MACRO *defmacro( STACK *stack, int called); +#define CALLED_NORMAL 0 +#define CALLED_NOLIST 1 +#define CALLED_NODEFINE 2 + STREAM *expandmacro( STREAM *refstr, MACRO *mac,