From 00f57bbc8778f8c42960906fd55364cb2e56fac3 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 13 Jun 2011 10:03:26 +0000 Subject: [PATCH] Fix/workaround for a problem with nested macros. git-svn-id: svn://svn.cc65.org/cc65/trunk@5053 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/macro.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index d56a4c48c..522db7ac2 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -654,17 +654,17 @@ static int MacExpand (void* Data) /* We're expanding a macro. Check if we are expanding one of the * macro parameters. */ +ExpandParam: if (Mac->ParamExp) { /* Ok, use token from parameter list, but don't use its line info */ TokSet (Mac->ParamExp, LI_SLOT_INV); - + /* Set pointer to next token */ Mac->ParamExp = Mac->ParamExp->Next; /* Done */ return 1; - } /* We're not expanding macro parameters. Check if we have tokens left from @@ -689,10 +689,10 @@ static int MacExpand (void* Data) if (CurTok.Tok == TOK_MACPARAM) { /* Start to expand the parameter token list */ - Mac->ParamExp = Mac->Params [CurTok.IVal]; + Mac->ParamExp = Mac->Params[CurTok.IVal]; - /* Recursive call to expand the parameter */ - return MacExpand (Mac); + /* Go back and expand the parameter */ + goto ExpandParam; } /* If it's an identifier, it may in fact be a local symbol */ @@ -730,7 +730,6 @@ static int MacExpand (void* Data) /* The token was successfully set */ return 1; - } /* No more macro tokens. Do we have a final token? */ @@ -741,9 +740,21 @@ static int MacExpand (void* Data) FreeTokNode (Mac->Final); Mac->Final = 0; + /* Problem: When a .define style macro is expanded within the call + * of a classic one, the latter may be terminated and removed while + * the expansion of the .define style macro is still active. Because + * line info slots are "stacked", this runs into a CHECK FAILED. For + * now, we will fix that by removing the .define style macro expansion + * immediately, once the final token is placed. The better solution + * would probably be to not require AllocLineInfoSlot/FreeLineInfoSlot + * to be called in FIFO order, but this is a bigger change. + */ + /* End of macro expansion and pop the input function */ + FreeMacExp (Mac); + PopInput (); + /* The token was successfully set */ return 1; - } MacEnd: -- 2.39.5