mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 00:29:31 +00:00
Merge pull request #2498 from kugelfuhr/kugelfuhr/fix-include-in-macros
Fix .include within .macro/.repeat
This commit is contained in:
commit
5e5dd1d6c4
@ -156,3 +156,29 @@ void CheckInputStack (void)
|
||||
Error ("Open %s", IStack->Desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
InputStack RetrieveInputStack (void)
|
||||
/* Retrieve the current input stack. This will also clear it. Used when
|
||||
** including a file. The current input stack is stored together with the old
|
||||
** input file and restored when the file is closed.
|
||||
*/
|
||||
{
|
||||
/* We do not touch the counter so input sources are counted across
|
||||
** includes.
|
||||
*/
|
||||
InputStack S = IStack;
|
||||
IStack = 0;
|
||||
return S;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RestoreInputStack (InputStack S)
|
||||
/* Restore an old input stack that was retrieved by RetrieveInputStack(). */
|
||||
{
|
||||
CHECK (IStack == 0);
|
||||
IStack = S;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,17 @@
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* Opaque pointer to an input stack */
|
||||
typedef void* InputStack;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
@ -63,6 +74,15 @@ void CheckInputStack (void);
|
||||
** stuff on the input stack.
|
||||
*/
|
||||
|
||||
InputStack RetrieveInputStack (void);
|
||||
/* Retrieve the current input stack. This will also clear it. Used when
|
||||
** including a file. The current input stack is stored together with the old
|
||||
** input file and restored when the file is closed.
|
||||
*/
|
||||
|
||||
void RestoreInputStack (InputStack S);
|
||||
/* Restore an old input stack that was retrieved by RetrieveInputStack(). */
|
||||
|
||||
|
||||
|
||||
/* End of istack.h */
|
||||
|
@ -113,6 +113,7 @@ struct CharSource {
|
||||
token_t Tok; /* Last token */
|
||||
int C; /* Last character */
|
||||
int SkipN; /* For '\r\n' line endings, skip '\n\ if next */
|
||||
InputStack IStack; /* Saved input stack */
|
||||
const CharSourceFunctions* Func; /* Pointer to function table */
|
||||
union {
|
||||
InputFile File; /* File data */
|
||||
@ -321,6 +322,9 @@ static void UseCharSource (CharSource* S)
|
||||
S->Tok = CurTok.Tok;
|
||||
S->C = C;
|
||||
|
||||
/* Remember the current input stack */
|
||||
S->IStack = RetrieveInputStack ();
|
||||
|
||||
/* Use the new input source */
|
||||
S->Next = Source;
|
||||
Source = S;
|
||||
@ -347,7 +351,10 @@ static void DoneCharSource (void)
|
||||
|
||||
/* Restore the old token */
|
||||
CurTok.Tok = Source->Tok;
|
||||
C = Source->C;
|
||||
C = Source->C;
|
||||
|
||||
/* Restore the old input source */
|
||||
RestoreInputStack (Source->IStack);
|
||||
|
||||
/* Remember the last stacked input source */
|
||||
S = Source->Next;
|
||||
@ -1521,7 +1528,7 @@ CharAgain:
|
||||
/* In case of the main file, do not close it, but return EOF. */
|
||||
if (Source && Source->Next) {
|
||||
DoneCharSource ();
|
||||
goto Again;
|
||||
goto Restart;
|
||||
} else {
|
||||
CurTok.Tok = TOK_EOF;
|
||||
}
|
||||
|
1
test/asm/listing/070-include-macro.inc
Normal file
1
test/asm/listing/070-include-macro.inc
Normal file
@ -0,0 +1 @@
|
||||
foo:
|
13
test/asm/listing/070-include-macro.s
Normal file
13
test/asm/listing/070-include-macro.s
Normal file
@ -0,0 +1,13 @@
|
||||
.macro IncludeFile FilePath
|
||||
.proc bar
|
||||
.include FilePath
|
||||
.endproc
|
||||
.endmacro
|
||||
|
||||
IncludeFile "070-include-macro.inc"
|
||||
|
||||
.ifdef bar::foo
|
||||
.out "bar::foo is defined"
|
||||
.else
|
||||
.out "bar::foo is undefined"
|
||||
.endif
|
1
test/asm/listing/070-include-repeat.inc
Normal file
1
test/asm/listing/070-include-repeat.inc
Normal file
@ -0,0 +1 @@
|
||||
.out "include file"
|
4
test/asm/listing/070-include-repeat.s
Normal file
4
test/asm/listing/070-include-repeat.s
Normal file
@ -0,0 +1,4 @@
|
||||
.repeat 3
|
||||
.include "070-include-repeat.inc"
|
||||
.out "main file"
|
||||
.endrepeat
|
1
test/asm/listing/ref/070-include-macro.err-ref
Normal file
1
test/asm/listing/ref/070-include-macro.err-ref
Normal file
@ -0,0 +1 @@
|
||||
bar::foo is defined
|
6
test/asm/listing/ref/070-include-repeat.err-ref
Normal file
6
test/asm/listing/ref/070-include-repeat.err-ref
Normal file
@ -0,0 +1,6 @@
|
||||
include file
|
||||
main file
|
||||
include file
|
||||
main file
|
||||
include file
|
||||
main file
|
Loading…
Reference in New Issue
Block a user