flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > FASM1: Skipping pieces of macro declaration

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 952
Location: Belarus
DimonSoft
It might be a stupid question but is it possible to skip certain pieces when building a macro declaration?

Say, I have an imaginary macro template that goes along the lines of
Code:
macro define_????? Name*, [Label, Type, Value]
{
  common
    match any , namelist \{ namelist equ namelist, Name \}
    match     , namelist \{ namelist equ Name \}
    label Name
  forward
    Label Type Value
    sizeof. # Label = $ - Label   ; <-- This line
  common
    sizeof. # Name = $ - Name
}    


Now I’d like to generate multiple macros with such structure, so I write a factory macro:
Code:
macro factory SmthName*
{
  macro define_ # SmthName Name*, [Label, Type, Value]
  \{
    ...
    ; Macro body goes here with proper escaping
    ...
  \}
}    


Finally, I have a symbolic constant (let’s call it CalcSize) and I want the line that calculates sizes of my data pieces (see macro template above) to only appear inside macros if the CalcSize constant equals 1.

I could write it this way:
Code:
macro factory SmthName*
{
  macro define_????? Name*, [Label, Type, Value]
  \{
    ...
    \forward
      Label Type Value
      match =1 , CalcSize
      \\{
        sizeof. # Label = $ - Label   ; <-- This line
      \\}
    \common
    ...
  \}
}    

but that would make every macro produced by the “factory” contain this check thus adding a lot of noise to the prepsrc.exe output. What I want is to make produced macros either contain or not contain the calculation depending on the constant value at the moment of their definition.

Is that even possible?
Post 06 Mar 2021, 18:01
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7919
Location: Kraków, Poland
Tomasz Grysztar
You could use a "macro builder" concept, which is a pattern that goes like this:
Code:
macro MacroBuilder.begin definition&
{
        macro MacroBuilder \{ macro definition \\{ \}
}

macro MacroBuilder.line content&
{
        macro MacroBuilder \{ MacroBuilder
                              content \}
}

macro MacroBuilder.end
{
        MacroBuilder
        \}
}    
You can use it to build a customized macro by choosing the exact lines that you want to have in the definition. For example:
Code:
MacroBuilder.begin Foo
rept 4 i:0
{
        MacroBuilder.line display `i
}
MacroBuilder.end    
builds a macro:
Code:
macro Foo {
        display '0'
        display '1'
        display '2'
        display '3'
}    
and you can of course use MATCH to define lines conditionally.
Post 06 Mar 2021, 18:55
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 952
Location: Belarus
DimonSoft
So, that’s just a matter of creating a chain of macro redefinitions each adding its own piece of the expected result, right?

As a side question (and since I still don’t feel being able to dig through the whole FASM source), I wonder what is the effect of multiple macro redefinitions on compiler memory usage? Is it worth purging a macro or restoring a symbolic constant than is no longer needed? This is what was the source of the original question, and three macro definitions seem like a tradeoff that may not be worth paying.


Last edited by DimonSoft on 06 Mar 2021, 19:54; edited 1 time in total
Post 06 Mar 2021, 19:22
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: 18170
Location: In your JS exploiting you and your system
revolution
You can test the memory usage to confirm, but my testing showed that using purge/restore/restruc used more memory than simply overwriting with a new value/definition and/or just ignoring it for the rest of the source.
Post 06 Mar 2021, 19:26
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.