flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > problem with concatenation and empty macro parameters

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17341
Location: In your JS exploiting you and your system
revolution
I have a problem with concatenation when using an empty macro parameter
Code:
struc ABC_BAR {.value rd 1}

virtual at 0
   ABC_BAR ABC_BAR
end virtual

macro foo var1*,prefix*,structure,var2 {
  mov eax,var1
  if ~ structure eq
     mov edx,[eax+prefix#_#structure#.#var2]
        ;the above line has an "invalid address" error
        ;if "structure" is empty. The line looks like this:
        ;"mov edx,[eax+ABC_#.]" after macro expansion
  end if
}

foo baz,ABC,BAR,value ;this line is okay
foo baz,ABC           ;this line fails with "invalid address"    
The only working solution I have right now is this:
Code:
struc ABC_BAR {.value rd 1}

virtual at 0
   ABC_BAR ABC_BAR
end virtual

macro foo var1*,prefix*,structure,var2 {
  mov eax,var1
  if ~ structure eq xxx ;note the ugly "xxx"
     mov edx,[eax+prefix#_#structure#.#var2]
  end if
}

foo baz,ABC,BAR,value
foo baz,ABC,xxx    
But it is not nice with the XXX in there. Is there some other "clean" way I can solve this?
Post 18 Dec 2005, 00:57
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
This is because two # characters in a row are treated the same as \# - this was kept for the backward compatibility. The # character that is left then causes trouble to the parser. But you can use help of the "match" to save parser from handling such line:
Code:
  match any,structure
  \{
     mov edx,[eax+prefix#_#structure#.#var2]
  \}    


BTW, do you think I should remove that "multiple #" feature? It is not even documented anymore.
Post 18 Dec 2005, 01:46
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17341
Location: In your JS exploiting you and your system
revolution
Quote:
But you can use help of the "match" to save parser from handling such line.
Yep, that is much cleaner, thanks. I must be too tired, I should have seen that myself!

Quote:
BTW, do you think I should remove that "multiple #" feature? It is not even documented anymore.
Hmm, that is a tricky question to answer. If I want to be totally selfish then I would say it is okay to remove. Some time back I went through all my macros and changed them to use the "". But, of course, it is probably best to leave it in as long as possible to help with backward compatibility. I don't see anyone posting a message indicating it causing a problem that can't be solved.
Post 18 Dec 2005, 03:29
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
tomasz: IMO this problem shows is that you should remove ## feature.
Post 19 Dec 2005, 15:34
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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 YouTube, Twitter.

Website powered by rwasa.