flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > "Dereferencing" symbolic constants [SOLVED]

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 835
Location: Belarus
DimonSoft
Like thousands of FASM users, I'm trying to write my own set of OOP-macros. Just as an exercise to understand FASM macro-syntax better.

The thing I'm trying to do is to build a list of classes used by a program. Here's the macro I've managed to write:

Code:
Classes.Used equ

macro Define_UseClass
{
  macro UseClass name
  \{
display \`name#, 13, 10
    match =Classes.Used.#name , Classes.Used.#name
    \\{
      Classes.Used.#name equ TRUE
      match any , Classes.Used
      \\\{
        Classes.Used equ any, name
      \\\}
      match , Classes.Used
      \\\{
        Classes.Used equ name
      \\\}

;      match base , Classes.Base.\#name
;      \\\{
        Define_UseClass
        UseClass Classes.Base.\#name ;base
        purge Define_UseClass
;      \\\}
    \\}
  \}
}
Define_UseClass
    


As you can see, I store the following data:
• comma-separated list of classes in Classes.Used symbolic constant;
• a set of Classes.Used.* symbolic constants equal to TRUE for each class (to have only unique items);
• a set of Classes.Base.* symbolic items, which should contain ancestor names.

Now consider two classes: TObject (base class) and TControl (descendant). I add the following lines to the code:

Code:
Classes.Base.TControl equ TObject

UseClass TControl    


In this case UseClass macro should have been called twice: for TControl and then (recursively) for TObject. And it does, but display shows the following information:

Code:
TControl
Classes.Base.TControl
    


So, the question is: how to "dereference" Classes.Base.TControl to its "actual value" (TObject)?

Thanks.


Last edited by DimonSoft on 10 Jan 2013, 10:54; edited 1 time in total
Post 08 Jan 2013, 21:41
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: 17716
Location: In your JS exploiting you and your system
revolution
You also need to "escape" the #.
Code:
Classes.Used.\#name equ TRUE    
Post 08 Jan 2013, 22:32
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 835
Location: Belarus
DimonSoft
revolution wrote:
You also need to "escape" the #.
Code:
Classes.Used.\#name equ TRUE    

Well, that seems to be right. But when I had done this, I got a "name too long" error finally pointing to the line, where recursive macro "call" is performed.

BTW, is escaping the # operator really necessary here? name is a macro parameter, so the full name may be formed as soon as macro gets called and there seems to be no need to leave it for better times.
Post 09 Jan 2013, 08:44
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: 17716
Location: In your JS exploiting you and your system
revolution
DimonSoft wrote:
BTW, is escaping the # operator really necessary here?
Yes. If not then the outer macro will replace concatenate 'name' with the other text and give the incorrect code to the inner macro. You want 'name' to be replaced by the inner macro so you have to make sure that 'name' is not concatenated to early.
Post 09 Jan 2013, 12:56
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 835
Location: Belarus
DimonSoft
revolution wrote:
DimonSoft wrote:
BTW, is escaping the # operator really necessary here?
Yes. If not then the outer macro will replace concatenate 'name' with the other text and give the incorrect code to the inner macro. You want 'name' to be replaced by the inner macro so you have to make sure that 'name' is not concatenated to early.

Well, it is really necessary. Thanks.

Found about ten other mistakes and finally made it work. Something like that:

Code:
Classes.Used equ

macro Define_UseClass
{
  macro UseClass name
  \{
    match =Classes.Used.\#name , Classes.Used.\#name
    \\{
      Classes.Used.\#name equ TRUE

      match base , Classes.Base.\#name
      \\\{
        Define_UseClass
        UseClass base
        purge Define_UseClass
      \\\}

      match any , Classes.Used
      \\\{
        Classes.Used equ any, name
      \\\}
      match , DFL.Classes.Used
      \\\{
        Classes.Used equ name
      \\\}
    \\}
  \}
}
Define_UseClass

; -----------------------------------------

; The order should be from ancestors to descendants
;
Classes.Base.TObject equ
Classes.Base.TControl equ TObject

; Actual macro usage
;
UseClass TControl
    


Hope this may help somebody.
Post 10 Jan 2013, 10:52
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.