mirror of
https://github.com/cc65/cc65.git
synced 2024-06-07 07:29:33 +00:00
Merge pull request #2013 from Movax12/fix-endmacro-not-at-start-of-line
Fix endmacro not at start of line
This commit is contained in:
commit
34189b85ab
|
@ -2522,7 +2522,19 @@ See: <tt><ref id=".ASCIIZ" name=".ASCIIZ"></tt>,<tt><ref id=".CHARMAP" name=".CH
|
|||
|
||||
<sect1><tt>.ENDMAC, .ENDMACRO</tt><label id=".ENDMACRO"><p>
|
||||
|
||||
Marks the end of a macro definition.
|
||||
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
|
||||
<tt><ref id=".DEFINE" name=".DEFINE"></tt> to create a symbol that references
|
||||
<tt>.ENDMACRO</tt> without ending the macro definition.
|
||||
|
||||
Example:
|
||||
|
||||
<tscreen><verb>
|
||||
.macro new_mac
|
||||
.define startmac .macro
|
||||
.define endmac .endmacro
|
||||
.endmacro
|
||||
</verb></tscreen>
|
||||
|
||||
See: <tt><ref id=".DELMACRO" name=".DELMACRO"></tt>,
|
||||
<tt><ref id=".EXITMACRO" name=".EXITMACRO"></tt>,
|
||||
|
|
|
@ -390,7 +390,20 @@ void MacDef (unsigned Style)
|
|||
{
|
||||
Macro* M;
|
||||
TokNode* N;
|
||||
FilePos Pos;
|
||||
int HaveParams;
|
||||
int LastTokWasSep;
|
||||
|
||||
/* 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
|
||||
** new line, so set it now
|
||||
*/
|
||||
LastTokWasSep = 1;
|
||||
|
||||
/* Save the position of the start of the macro definition to allow
|
||||
** using Perror to display the error if .endmacro isn't found
|
||||
*/
|
||||
Pos = CurTok.Pos;
|
||||
|
||||
/* We expect a macro name here */
|
||||
if (CurTok.Tok != TOK_IDENT) {
|
||||
|
@ -491,14 +504,16 @@ void MacDef (unsigned Style)
|
|||
while (1) {
|
||||
/* Check for end of macro */
|
||||
if (Style == MAC_STYLE_CLASSIC) {
|
||||
/* In classic macros, only .endmacro is allowed */
|
||||
if (CurTok.Tok == TOK_ENDMACRO) {
|
||||
/* 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.
|
||||
*/
|
||||
if (CurTok.Tok == TOK_ENDMACRO && LastTokWasSep) {
|
||||
/* Done */
|
||||
break;
|
||||
}
|
||||
/* May not have end of file in a macro definition */
|
||||
if (CurTok.Tok == TOK_EOF) {
|
||||
Error ("'.ENDMACRO' expected");
|
||||
PError (&Pos, "'.ENDMACRO' expected for macro '%m%p'", &M->Name);
|
||||
goto Done;
|
||||
}
|
||||
} else {
|
||||
|
@ -573,6 +588,11 @@ void MacDef (unsigned Style)
|
|||
}
|
||||
++M->TokCount;
|
||||
|
||||
/* Save if last token was a separator to know if .endmacro is at
|
||||
** the start of a line
|
||||
*/
|
||||
LastTokWasSep = TokIsSep(CurTok.Tok);
|
||||
|
||||
/* Read the next token */
|
||||
NextTok ();
|
||||
}
|
||||
|
|
6
test/asm/err/endmacro.s
Normal file
6
test/asm/err/endmacro.s
Normal 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/endmacro.s
Normal file
30
test/asm/val/endmacro.s
Normal 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
|
Loading…
Reference in New Issue
Block a user