flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Help with macro (Reusing macro parameters as "prefix&am

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 15 Oct 2010, 11:34
Hi guys,

I'd like to implement a macro "c_instance". Example:

Code:
c_instance MyVar, TypeStructVar    


and it should generate the following code:

Code:
MyVar <TypeStructVar>
_call TypeStructVar_Init, MyVar    


As you can see, we have used a macro argument as part of a name (TypeStructVar -> TypeStructVar_Init)

Is that possible to do with macros?

In a similar way, I'd like to implement also this macro. Example:

Code:
mcall  MyVar.Function1, param1, param2, param3...    


and it generates the following code:

Code:
_call  MyVar.Function1, MyVar, param1, param2, param3, ...    


In the above "mcall" macro we are extracting "MyVar"...not sure if that's possible to do in FASM macros...

Thanks!


Last edited by alorent on 15 Oct 2010, 11:50; edited 1 time in total
Post 15 Oct 2010, 11:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20012
Location: In your JS exploiting you and your system
revolution 15 Oct 2010, 11:37
Is this for a COM interface?

It looks similar to the macros in COM32.INC (in the Windows download)
Post 15 Oct 2010, 11:37
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 15 Oct 2010, 11:50
Hi revolution,

Well, I'm trying to implement a light "OO" interface. Didn't know there was something similar in COM32.INC.

Anyway, I can see such functionality in COM32.INC Sad

Any help?

Thanks!
Post 15 Oct 2010, 11:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20012
Location: In your JS exploiting you and your system
revolution 15 Oct 2010, 12:04
Wel the first one looks easy:
Code:
macro c_instance name, type {
      name <type>
   _call type#_Init,name
}

c_instance MyVar, TypeStructVar    
The second one looks not so easy. The preprocessor does not support substrings.
Post 15 Oct 2010, 12:04
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 15 Oct 2010, 14:26
Thanks a lot revolution!

As you can see, the second macro has a dot "." that separates the substring that we need (i.e., "MyVar.Function1"). Does that dot help?

Thanks again!
Post 15 Oct 2010, 14:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Oct 2010, 14:46
I'd suggest changing macro syntax to something like:
Code:
mcall MyVar, method, arg1, arg2, ...
    

That way things will get much simpler.

Or, at least use some other character which is not part of symbol name. Something like "MyVar:method". That way you can separate two symbols from single macro argument by using "match" directive.
Post 15 Oct 2010, 14:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 15 Oct 2010, 15:10
Hi vid,

Thanks for the information. Yes, I also afraid the "dot" might lead into troubles. I also like your ":" solution. I'm trying to define as something like:

Code:
macro mcall instance_method, [params]
{
   match instance:method, instance_method
   \{
    _call instance\#.method\#, params \} }

    


but I get error when I call the macro:

Code:
mcall MyInstance:MyMethod, eax, ebx    


It says "undefined symbol "MyInstance.method"

Any help?

Thanks!
Post 15 Oct 2010, 15:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8311
Location: Kraków, Poland
Tomasz Grysztar 15 Oct 2010, 15:52
It should be:
Code:
_call instance\#.\#method, params    
Post 15 Oct 2010, 15:52
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 15 Oct 2010, 17:08
Thanks Tomasz!

That worked as expected! Very Happy
Post 15 Oct 2010, 17:08
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.