flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Singleton pattern

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 4249
Location: vpcmpistri
bitRAKE 16 Jun 2009, 05:35
Code:
macro __imp_ n {
        match =n,n \{
         display '__imp_' # `n,13,10
               extrn __imp_\#n :QWORD
         n equ __imp_\#n
    \}
    call [n]
}    
How it works? First, MACRO invocation replaces "n" in the MATCH line to become: MATCH =Name,Name. Next, if Name is referenced to another value with EQU then the MATCH will resolve to EQU value - which should not be Name. Otherwise Name does = Name.

Note how several macro calls result in only the first MATCH block being executed and all from the preprocessor because MATCH resolves EQU. This pattern can be used to create a list of unique items without searching the list for existing entries. The EQU could be a LOCAL name to encapsulate the abstraction.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 16 Jun 2009, 05:35
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.