flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg]Why do we use "!" in macro

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 657
l4m2
Quote:
When an identifer of macroinstruction in its definition is followed by "!" character, it defines the unconditional macroinstruction. This is a special kind of instruction class symbol, which is evaluated even in places where the assembly is suspended - like inside the conditional block whose condition is false, or inside a definition of another macroinstruction. This allows to define instructions that can be used where otherwise a directly stated "end if" or "end macro" would be required, as in the following example:

If we treat all macros as condictional ones, as said above sone fynctions won't work; if we treat all as uncondictional ones, factional macro loops forever.
What if uncondictional macro expanding only occur in the first layer?(when used it directly expand but wait when it is there again after expanding)
Post 27 Aug 2016, 10:31
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7796
Location: Kraków, Poland
Tomasz Grysztar
The unconditional macros in fasmg are there mainly to allow defining constructions that in fasm required use of preprocessor's FIX directive.
What in fasm looked like:
Code:
macro foo name
{
        macro name arg
        \{ content_start
}

endfoo fix content_end } definition_end


foo test
        ; ...
endfoo    
has the following equivalent in fasmg:
Code:
macro foo name
    esc macro name arg
        content_start
end macro

macro endfoo!
        content_end
    esc end macro
        definition_end
end macro


foo test
        ; ...
endfoo    
The unconditional macros are closely related to what FIX does in fasm's preprocessor - the macro is simply replaced with its contents everywhere and unconditionally. If you try to make recursive unconditional macro, it is similar to defining self-referencing symbolic constant with EQU:
Code:
test equ test! ; this would expand till infinity, fasmg signals an error    


l4m2 wrote:
What if uncondictional macro expanding only occur in the first layer?(when used it directly expand but wait when it is there again after expanding)
You can make something like this happen if you stack the unconditional macro on top of the conditional one, you can test this behavior with the following (highly artificial) sample:
Code:
macro test arg
        if arg > 0
        display `arg
end macro

macro test! arg
        test arg
        end if
end macro

        test 1

if 0
        test 2    
That inner macro cannot be made recursive in such case, but you can still get recursion if you define the inner macro under a different name.
Post 27 Aug 2016, 18:14
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.