asar
asar copied to clipboard
macros are not namespaced
org $0000
norom
macro Foo()
print "foo"
db $00
endmacro
namespace Private
Random: db $01
macro Bar()
print "bar"
db $02
endmacro
namespace off
%Foo()
dw Private_Random
%Private_Bar()
Output:
test.asm:19 (called from test.asm:19): error: (Emacro_not_found): Macro 'Private_Bar' wasn't found. [%Private_Bar()]
foo
Errors were detected while assembling the patch. Assembling aborted. Your ROM has not been modified.
(Only tested with Asar 1.91.)
Currently, namespaces as a feature exist for labels only. Macros or defines are unaffected by them. So in the example above, the macro's global name is still just "Bar".
Would be useful to support, I guess, though I'm also 60% sure adding macros and defines to namespaces retroactively would break a lot of existing patches... 🤔
Ah, that wasn't obvious to me from the manual. Still, it seems intuitive to me to assume that any identifier would support namespacing, not just some subset of them, so I do support... supporting it. But indeed, backwards-compatibility seems... troublesome. Dare I suggest adding a keyword setting for it? Or maybe this is something that can be put in Asar 2 and included in migration notes or something to that effect.
For what its worth, programming languages that implement macros via a preprocessor (like C++) also have this limitation. They also aren't namespaced there. Though Asar doesn't do that, and I agree namespaced macros (and defines and functions, for that matter) would be a good idea. For that matter, I'd also prefer if Asar didn't use underscore to qualify namespaces, but that's a different topic.
If we changed this, we could do what Asar 1.9 is doing and first have a release or two that only deprecates the feature, followed by a release that outright removes it.