flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [FASM1] Defining macro and struc for the same thing

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 959
Location: Belarus
DimonSoft
We all know that there are really two kinds of macros in FASM1: macro and struc. The first thing is used for lexemes that are at the beginning of a line, the second—for the second lexemes in a line, if the first lexeme wasn’t a macro/turned out to be a label without colon :.

I often find myself writing something like
Code:
struc Foo params&
{
  ; All stuff goes here
  ...
}

macro Foo params&
{
  local ..a
  ..a Foo params
}    


The idea is that I sometimes want to have a more readable and flexible way for defining complex data but I definitely don’t want to repeat myself twice, so the “fake” label is a way to go. While the macro is pretty small, it still is boilerplate and gets quite annoying soon.

Besides, the struct macro definition would become smaller if there was some language-level solution to the problem.

I considered a few possible solutions and while some of them would be convenient for me personally, I’m not sure any of them would be a good solution in general.

1) Leave it as it is.
It just works. The macro and struc features are relatively independent from each other and neither is privileged.

2) Special “smacto” (struct + macro) keyword which would do the equivalent of the code in my example.
Adding a new keyword (no matter whether it exists in any vocabulary and how crazy it is) just to remove a pretty small piece of boilerplate doesn’t seem right from design point of view. But that would definitely solve the problem.

3) Shifting privileges to struc’s.
The idea is that since struc invokation is basically an equivalent of using data definition directives, so struc “should” automatically define the equivalent macro unless the same-named macro is present. Looks good at first glance but would definitely break some code if introduced now.

I wonder what other people (and Tomasz especially) think.
Post 07 Dec 2021, 12:06
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1083
Roman
Quote:

Special “smacto”

If smacto.
Do fields in smacto : Data,Initialize,code,procs,destroy
More excellent variant.

Field Data auto place in section data or section '.bss'

For example smacto A copy data to smacto B data.
Quote:
A::B 5,4


Mean copy from five element four elements.


Last edited by Roman on 08 Dec 2021, 03:52; edited 1 time in total
Post 07 Dec 2021, 13:58
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 169
Location: Russia
macomics
DimonSoft wrote:
Code:
struc Foo params&
{
  ; All stuff goes here
  ...
}

macro Foo params&
{
  local ..a
  ..a Foo params
}    


Code:
; Once for any other structure
macro That struct*, params& { local ..a
  ..a struct params }

struc Foo params&
{
  ; All stuff goes here
  ...
}

struc Foo1 par*, arg&
{
  ; All stuff goes here
  ...
}

struc Foo2
{
  ; All stuff goes here
  ...
}

That Foo    arg0, arg1, arg2, "str"
That Foo    arg3, arg1, arg4, "new"
That Foo1   arg5, arg6
That Foo2    
Post 07 Dec 2021, 17:56
View user's profile Send private message 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.