flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to limit scope of a macro to the given procedure body.

Author
Thread Post new topic Reply to topic
MHajduk



Joined: 30 Mar 2006
Posts: 6029
Location: Poland
MHajduk
I'd like to ask here the following (maybe lame) question:
  • how to limit scope of a macro (or a set of macros) to the interior of the particular procedure, i.e. applicability of the aforementioned macros is limited strictly to the part of the source contained within the procedure definition, outside those macros should be "invisible" for the fasm compiler. Note that I don't want to decorate the names of the macros with preceding dots, underscores and other characters like that (names of the macros will start with letters).
How can I do that?
Post 10 Aug 2019, 17:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7410
Location: Kraków, Poland
Tomasz Grysztar
I assume this is about fasm 1, since fasmg has proper namespaces that work for macros, too.

You can make macros temporary by restoring them to their previous definition (or undefined state) with PURGE directive. To make this automatic, you can have some framework that would keep track of the macros that need to be PURGEd at the end of procedure. For example something like:
Code:
macro macroscope {
        define list@macroscope
}

macro .macro definition& {
        local buffer
        define buffer definition
        match name tail, buffer: \{
                match any, list@macroscope \\{ restore list@macroscope
                                               define list@macroscope any,name \\}
                match , list@macroscope \\{ restore list@macroscope
                                            define list@macroscope name \\}
        \}
        macro definition
}

macro endmacroscope {
        match list, list@macroscope \{
                irp name, list \\{
                        purge name
                \\}
        \}
        restore list@macroscope
}    
Code:
macroscope

        .macro test {
                display 'macro in scope'
        }

        test

endmacroscope

        test    ax,bx           ; back to normal x86 instruction    
Post 10 Aug 2019, 17:39
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6029
Location: Poland
MHajduk
Tomasz Grysztar wrote:
I assume this is about fasm 1, since fasmg has proper namespaces that work for macros, too.
Yes, that's right, I was thinking about fasm 1.

Thanks for the reply, this is exactly a solution I wanted. Smile
Post 10 Aug 2019, 17:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.