Hello everyone

I am having some troubles with macros.
I would like to make a macro X_ with terminator X_e and keyword X_k, which would generate a record definition.
e.g.:


type
X_(abc);
X_k(a:dword);
X_k(b:dword);
X_k(c:dword);
X_e;

generates


type
abc:record
a:dword;
b:dword;
c:dword;
endrecord;

Do not ask WHY do I need a macro like this - I just DO ;-)

clone-d
Posted on 2003-01-27 12:20:54 by clone-d

Hello everyone

I am having some troubles with macros.
I would like to make a macro X_ with terminator X_e and keyword X_k, which would generate a record definition.
e.g.:


type
X_(abc);
X_k(a:dword);
X_k(b:dword);
X_k(c:dword);
X_e;

generates


type
abc:record
a:dword;
b:dword;
c:dword;
endrecord;

Do not ask WHY do I need a macro like this - I just DO ;-)

clone-d





How about:



program t;

#macro X_(recname);
recname:record

#keyword X_k(decl);
decl

#terminator X_e;
endrecord

#endmacro;

type
X_(abc);
X_k(a:dword);
X_k(b:dword);
X_k(c:dword);
X_e;

static
a:abc;

begin t;

mov( a.a, eax );
mov( a.b, ebx );
mov( a.c, ecx );


end t;

Posted on 2003-01-27 21:44:54 by rhyde
Okay.

Next question is - is it possible to accumulate the whole record and emit it on #terminator?
Like this(following code does not work):



#macro X_(recname):wholerec;
?wholerec := recname + ":record";
#keyword X_k(decl);
?wholerec := wholerec + decl;
#terminator X_e;
?wholerec := wholerec + "endrecord";
wholerec
#endmacro;


clone-d
Posted on 2003-01-28 03:48:45 by clone-d

Okay.

Next question is - is it possible to accumulate the whole record and emit it on #terminator?
Like this(following code does not work):



#macro X_(recname):wholerec;
?wholerec := recname + ":record";
#keyword X_k(decl);
?wholerec := wholerec + decl;
#terminator X_e;
?wholerec := wholerec + "endrecord";
wholerec
#endmacro;


clone-d


Sure, the following provides one way of doing it:



program t;

#macro X_(recname):theRecord;
?theRecord:string := @string(recname) + ":record ";

#keyword X_k(decl);
?theRecord := theRecord + @string( decl ) + "; ";

#terminator X_e;
@text( theRecord )
endrecord
#endmacro;

type
X_(abc);
X_k(a:dword);
X_k(b:dword);
X_k(c:dword);
X_e;

static
a:abc;

begin t;

mov( a.a, eax );
mov( a.b, ebx );
mov( a.c, ecx );


end t;


Posted on 2003-01-28 23:10:39 by rhyde