Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.elseif doesn't seem to work inside macros #41

Open
sdt opened this issue Sep 14, 2021 · 1 comment
Open

.elseif doesn't seem to work inside macros #41

sdt opened this issue Sep 14, 2021 · 1 comment

Comments

@sdt
Copy link

sdt commented Sep 14, 2021

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
Copy link
Author

sdt commented Sep 14, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant