avra icon indicating copy to clipboard operation
avra copied to clipboard

.elseif doesn't seem to work inside macros

Open sdt opened this issue 3 years ago • 1 comments

Hello,

I seem to have run into a problem trying to create a macro that uses .elseif

The code below fails with:

broken.asm(14) : Error : [Macro: broken.asm: 8:] Found no label/variable/constant named

; broken.asm
.macro BROKEN
.endm

.macro BROKEN_i
    .if @0 % 3 == 0
        .message "fizz"
    .elseif @0 % 5 == 0
        .message "buzz"
    .else
        .message @0
    .endif
.endm
BROKEN [7]

The same logic split into nested .else .if blocks works as expected.

; working.asm
.macro WORKING
.endm

.macro WORKING_i
    .if @0 % 3 == 0
        .message "fizz"
    .else
        .if @0 % 5 == 0
            .message "buzz"
        .else
            .message @0
        .endif
    .endif
.endm
WORKING [7]

The .elseif code works normally outside of macros.

Thanks!

sdt avatar Sep 14 '21 08:09 sdt

I've a had a little bit of a dig around. It looks as though the elseif processing in check_conditional or spool_conditional gets ahead of the macro expansion somehow.

Tracing out the data string that get_expr sees, in the working case, @0 is already expanded out:

7 % 3 == 0
7 % 5 == 0

In the broken case, the .if expression is expanded, but the .elseif expression is not:

7 % 3 == 0
@0 % 5 == 0

sdt avatar Sep 14 '21 08:09 sdt