Fix .endmacro not at the start of the line. Fix last commit

This commit is contained in:
mvax
2023-03-01 21:55:14 -05:00
parent 1c60bc5009
commit 0b71d1cfff
4 changed files with 46 additions and 10 deletions

View File

@@ -2522,7 +2522,7 @@ See: <tt><ref id=".ASCIIZ" name=".ASCIIZ"></tt>,<tt><ref id=".CHARMAP" name=".CH
<sect1><tt>.ENDMAC, .ENDMACRO</tt><label id=".ENDMACRO"><p> <sect1><tt>.ENDMAC, .ENDMACRO</tt><label id=".ENDMACRO"><p>
Marks the end of a macro definition. Note, <tt>.ENDMACRO</tt> should be on Marks the end of a macro definition. Note, <tt>.ENDMACRO</tt> should be on
its own line to successfully end the macro definition. It is possible to use its own line to successfully end the macro definition. It is possible to use
<tt><ref id=".DEFINE" name=".DEFINE"></tt> to create a symbol that references <tt><ref id=".DEFINE" name=".DEFINE"></tt> to create a symbol that references
<tt>.ENDMACRO</tt> without ending the macro definition. <tt>.ENDMACRO</tt> without ending the macro definition.

View File

@@ -394,14 +394,14 @@ void MacDef (unsigned Style)
int HaveParams; int HaveParams;
int LastTokWasSep; int LastTokWasSep;
/* For classic macros, remember if we are at the beginning of the line. /* For classic macros, remember if we are at the beginning of the line.
** If the macro name and parameters pass our checks then we will be on a ** If the macro name and parameters pass our checks then we will be on a
** new line, so set it now ** new line, so set it now
*/ */
LastTokWasSep = 1; LastTokWasSep = 1;
/* Save the position of the start of the macro definition to allow /* Save the position of the start of the macro definition to allow
** using Perror to display the error if .ENDMACRO isn't found ** using Perror to display the error if .ENDMACRO isn't found
*/ */
Pos = CurTok.Pos; Pos = CurTok.Pos;
@@ -504,8 +504,8 @@ void MacDef (unsigned Style)
while (1) { while (1) {
/* Check for end of macro */ /* Check for end of macro */
if (Style == MAC_STYLE_CLASSIC) { if (Style == MAC_STYLE_CLASSIC) {
/* In classic macros, if .endmacro is not at the start of the line /* In classic macros, if .endmacro is not at the start of the line
** it will be added to the macro definition instead of closing it. ** it will be added to the macro definition instead of closing it.
*/ */
if (CurTok.Tok == TOK_ENDMACRO && LastTokWasSep) { if (CurTok.Tok == TOK_ENDMACRO && LastTokWasSep) {
/* Done */ /* Done */
@@ -588,8 +588,8 @@ void MacDef (unsigned Style)
} }
++M->TokCount; ++M->TokCount;
/* Save if last token was a separator to know if .endmacro is at /* Save if last token was a separator to know if .endmacro is at
** the start of a line ** the start of a line
*/ */
LastTokWasSep = TokIsSep(CurTok.Tok); LastTokWasSep = TokIsSep(CurTok.Tok);

6
test/asm/err/bug2013.s Normal file
View File

@@ -0,0 +1,6 @@
; for PR #2013
; should produce error output:
; ... Error: '.ENDMACRO' expected for macro 'test'
.macro test
nop .endmacro

30
test/asm/val/bug2013.s Normal file
View File

@@ -0,0 +1,30 @@
; for PR #2013
.import _exit
.export _main
; this macro is invalid, but should not cause an error (if it is never expanded)
.macro invalid
nop .endmacro
.endmacro
.define temp_endmac .endmacro
.macro new_mac
.define startmac .macro
.define endmac .endmacro
temp_endmac
.undefine temp_endmac
new_mac
startmac dex2
dex
dex
endmac
_main:
ldx #$02
dex2
; x should be zero
txa
jmp _exit