Hiya

My macro looks like this:
#macro _push( _arg );

push( _arg );
#endmacro;
I'd like this macro to work in any of following cases:
const

_CONST1 := 1;
_CONST2 := 2;
procedure _proc;
var
b : byte;
w : word;
d : dword;
begin _proc;
_push( 1 );
_push( eax );
_push( dx );
_push( bl );
_push( (type string edi) );
_push( b );
_push( w );
_push( d );
_push( _CONST1 | _CONST2 );
end _proc;

please help me to modify the macro.

clone-d.
Posted on 2003-01-30 09:48:56 by clone-d

Hiya

My macro looks like this:
#macro _push( _arg );

push( _arg );
#endmacro;
I'd like this macro to work in any of following cases:
const

_CONST1 := 1;
_CONST2 := 2;
procedure _proc;
var
b : byte;
w : word;
d : dword;
begin _proc;
_push( 1 );
_push( eax );
_push( dx );
_push( bl );
_push( (type string edi) );
_push( b );
_push( w );
_push( d );
_push( _CONST1 | _CONST2 );
end _proc;

please help me to modify the macro.

clone-d.


Well, doing all that starts to get convoluted and ugly.
It's also one area where HLA v1.x's compile-time language
has gotten a bit cheap. Actually, that's not true, the compile-time
language handles this stuff fairly well, it's the HLA v1.x implementation
of the compile-time language that's problematic (i.e., some things
are defined just the way you want them, but they don't always work
properly). In any case, the stuff you want to look up are the compile-time
functions @isconst, @isreg, @ismemory, etc. These functions return true
or false if their argument falls into the specified category. So you wind up
coding stuff like the following:



#macro _push( arg );

#if( @isConst( arg ))

...

#elseif( @isreg8( arg ))

...

#elseif( @isreg16( arg ))
...
#elseif ....

etc.

#endmacro;

Take a look at the "stdout.put" macro in the stdout.hhf header
file for some examples of this.

I will warn you, it's a lot of work to handle every case properly
and work around some of the bugs in HLA v1.x :-(
As big as the stdout.put macro is, it's still far from complete.

One of the big plans I have for HLA v2.0 is to implement a new
kind of macro that I call "templates" that will simplify this kind
of stuff. But I still haven't quite figured out how I want to do that.

Oh, btw, do realize that using crazy macros like this *really* slows
down the compilation of an HLA program. HLA macros, because
of limitations in flex and bison, don't have the most efficient implementation
you can devise. 1,000 lines of macro code probably compile at between
1/10th and 1/100th the speed of a normal source file (of course, if each
macro expands to 10 lines of code, you'd expect this, but macros are
quite a bit slower than even this would suggest).
Cheers,
Randy Hyde
Posted on 2003-02-01 01:48:26 by rhyde
here goes a new problem:
c:\tmp\test_macro>hla test_macro

CONST
REG
NEITHER
NEITHER
Assembling: test_macro.asm
clone-d.
P.S. I think you should remove the auto-appending a .hla extension to filename (or at least first try to find given file and if none found, then try adding .hla)
Posted on 2003-02-01 03:00:45 by clone-d

here goes a new problem:
c:\tmp\test_macro>hla test_macro

CONST
REG
NEITHER
NEITHER
Assembling: test_macro.asm
clone-d.
P.S. I think you should remove the auto-appending a .hla extension to filename (or at least first try to find given file and if none found, then try adding .hla)


Did you really mean to pass "a" rather than "arg" as the m1 argument in the m2 macro invocation? (Or is this just a typo?).

First trying to find the file is probably a good idea. I'll add that to my list.
Randy Hyde
Posted on 2003-02-01 20:21:09 by rhyde
Did you really mean to pass "a" rather than "arg" as the m1 argument in the m2 macro invocation? (Or is this just a typo?).

Yeah? I meantPosted on 2003-02-02 05:53:08 by clone-d


Yeah? I meantPosted on 2003-02-03 20:56:17 by rhyde