Prepare for macros being defined in "other ways" which are not yet put in the macro definition table.

This commit is contained in:
Olaf Seibert
2017-04-27 20:43:28 +02:00
parent e4ec481d3d
commit f07c9045f5
3 changed files with 20 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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, &macro_st);
if (mac) {
/* Remove from the symbol table... */
remove_sym(&mac->sym, &macro_st);
free_macro(mac);
if (!(called & CALLED_NODEFINE)) {
/* Allow redefinition of a macro; new definition replaces the old. */
mac = (MACRO *) lookup_sym(label, &macro_st);
if (mac) {
/* Remove from the symbol table... */
remove_sym(&mac->sym, &macro_st);
free_macro(mac);
}
}
mac = new_macro(label);
add_table(&mac->sym, &macro_st);
if (!(called & CALLED_NODEFINE)) {
add_table(&mac->sym, &macro_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;
}

View File

@@ -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,