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

Enforce required arguments for asm macros. #710

Closed
luckytyphlosion opened this issue Nov 18, 2018 · 2 comments
Closed

Enforce required arguments for asm macros. #710

luckytyphlosion opened this issue Nov 18, 2018 · 2 comments

Comments

@luckytyphlosion
Copy link
Member

Not all directives actually require an argument to work. For example, the macro get_protect_count requires a byte argument for the target as seen in the macro definition:

	.macro get_protect_count target
	.byte 0x51
	.byte \target
	.endm

However, omitting the argument will not produce a compile time error, and will instead output the following:

    .byte 0x51

From the docs:

.byte expects zero or more expressions, separated by commas. Each expression is assembled into the next byte.

Therefore, by not specifying an argument, it will just skip emitting a byte at all.

This can be fixed by using the :req specifier, which will enforce all arguments be specified:

	.macro get_protect_count target:req
	.byte 0x51
	.byte \target
	.endm

Example assembler error output:

data/battle_ai_scripts.s: Assembler messages:
data/battle_ai_scripts.s:2028: Error: Missing value for required parameter `target' of macro `get_protect_count'
@aaaaaa123456789
Copy link

Seems good to me. Nothing good can come out of broken macro usage.

@DizzyEggg
Copy link
Contributor

That's awesome Lucky. I always thought it had to be this way lol. And I had many bugs because of it, awesome find!

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

4 participants