flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > A macro cannot purge itself?

Author
Thread Post new topic Reply to topic
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Is there a way for a macro to purge itself?

The code below outputs "hello",0,"hello",0 instead of "hello",0,"hello".

Code:
macro db [args] {
common
db args,0
purge db
}

db "hello"
db "hello"    
Post 21 Dec 2010, 15:43
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7709
Location: Kraków, Poland
Tomasz Grysztar
No, it is not possible for a macro to purge itself. Inside macro only the previous definitions of it are seen, so "purge" removes the last from the stack of previous definition of that macro:
Code:
macro db [args] { ; level 1 macro
common 
db args,0 
purge db 
}

macro db [args] { ; level 2 macro
common
db args ; now it calls level 1 macro
purge db ; now it removes level 1 macro, so next time the 0 level - original DB directive will be used
}

db "hello" 
db "hello"    
Post 21 Dec 2010, 15:58
View user's profile Send private message Visit poster's website Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Ah I see. So removing the level 1 macro removes both the level 1 and level 2 macros.
Post 22 Dec 2010, 06:19
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7709
Location: Kraków, Poland
Tomasz Grysztar
No, level 2 stays there. Try adding some DISPLAY into the level 2 macro and see what happens.
Post 22 Dec 2010, 10:32
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.

Powered by rwasa.