mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Fix else working incorrectly from macros
Since the "skip ELSE blocks" variable is global, it used to get carried over from the macro's `if` to the outer's.
This commit is contained in:
@@ -39,7 +39,7 @@ uint32_t nListCountEmpty;
|
|||||||
char *tzNewMacro;
|
char *tzNewMacro;
|
||||||
uint32_t ulNewMacroSize;
|
uint32_t ulNewMacroSize;
|
||||||
int32_t nPCOffset;
|
int32_t nPCOffset;
|
||||||
bool executedIfBlock; /* If this is set, ELIFs cannot be executed anymore */
|
bool executeElseBlock; /* If this is set, ELIFs cannot be executed anymore */
|
||||||
|
|
||||||
static uint32_t str2int2(uint8_t *s, int32_t length)
|
static uint32_t str2int2(uint8_t *s, int32_t length)
|
||||||
{
|
{
|
||||||
@@ -360,8 +360,8 @@ conditional : if
|
|||||||
|
|
||||||
if : T_POP_IF const '\n' {
|
if : T_POP_IF const '\n' {
|
||||||
nIFDepth++;
|
nIFDepth++;
|
||||||
executedIfBlock = !!$2;
|
executeElseBlock = !$2;
|
||||||
if (!executedIfBlock)
|
if (executeElseBlock)
|
||||||
lexer_SetMode(LEXER_SKIP_TO_ELIF);
|
lexer_SetMode(LEXER_SKIP_TO_ELIF);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -370,11 +370,11 @@ elif : T_POP_ELIF const '\n' {
|
|||||||
if (nIFDepth <= 0)
|
if (nIFDepth <= 0)
|
||||||
fatalerror("Found ELIF outside an IF construct\n");
|
fatalerror("Found ELIF outside an IF construct\n");
|
||||||
|
|
||||||
if (executedIfBlock) {
|
if (!executeElseBlock) {
|
||||||
lexer_SetMode(LEXER_SKIP_TO_ENDC);
|
lexer_SetMode(LEXER_SKIP_TO_ENDC);
|
||||||
} else {
|
} else {
|
||||||
executedIfBlock = !!$2;
|
executeElseBlock = !$2;
|
||||||
if (!executedIfBlock)
|
if (executeElseBlock)
|
||||||
lexer_SetMode(LEXER_SKIP_TO_ELIF);
|
lexer_SetMode(LEXER_SKIP_TO_ELIF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,7 +384,7 @@ else : T_POP_ELSE '\n' {
|
|||||||
if (nIFDepth <= 0)
|
if (nIFDepth <= 0)
|
||||||
fatalerror("Found ELSE outside an IF construct\n");
|
fatalerror("Found ELSE outside an IF construct\n");
|
||||||
|
|
||||||
if (executedIfBlock)
|
if (!executeElseBlock)
|
||||||
lexer_SetMode(LEXER_SKIP_TO_ENDC);
|
lexer_SetMode(LEXER_SKIP_TO_ENDC);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@@ -394,6 +394,7 @@ endc : T_POP_ENDC '\n' {
|
|||||||
fatalerror("Found ENDC outside an IF construct\n");
|
fatalerror("Found ENDC outside an IF construct\n");
|
||||||
|
|
||||||
nIFDepth--;
|
nIFDepth--;
|
||||||
|
executeElseBlock = false;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
13
test/asm/if-macro.asm
Normal file
13
test/asm/if-macro.asm
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
m: macro
|
||||||
|
if 0
|
||||||
|
WARN "3"
|
||||||
|
else
|
||||||
|
WARN "5"
|
||||||
|
endc
|
||||||
|
endm
|
||||||
|
|
||||||
|
if 1
|
||||||
|
m
|
||||||
|
else
|
||||||
|
WARN "12"
|
||||||
|
endc
|
||||||
2
test/asm/if-macro.err
Normal file
2
test/asm/if-macro.err
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
warning: if-macro.asm(10) -> if-macro.asm::m(5): [-Wuser]
|
||||||
|
5
|
||||||
0
test/asm/if-macro.out
Normal file
0
test/asm/if-macro.out
Normal file
Reference in New Issue
Block a user