Page 1 of 1

what exectly are macros?

Posted: Mon Jan 03, 2005 5:09 am
by Dreglor
i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?

Re: what exectly are macros?

Posted: Mon Jan 03, 2005 5:13 am
by PB
Here's how I know them:

viewtopic.php?t=2212

Don't know if there's any other major uses for them?

Re: what exectly are macros?

Posted: Mon Jan 03, 2005 8:22 am
by Max.²
Dreglor wrote:i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?
It is even possible - FASM does that for example - to replace built-in commands with own macros. There was a tip like

Code: Select all

macro inc v 
{
pushf
add v,1
popf
}
macro dec v 
{
pushf
sub v,1
popf
} 

The above works even with PB, if you let generate commented output, put the macro into the asm code and then let PB recompile the asm code. BTW, it is meant to speed optimize inc & dec for P4 (claims are that add/dec commands are faster)


What is quite common too, is the precalculation of data. Like you need an array a(0)=0 to a(99)=99. Instead of dynamically calculating it in your program or typing by hand, a macro fills the array each time you compile.

Posted: Mon Jan 03, 2005 8:41 am
by FloHimself

Code: Select all

!macro inc v 
!{ 
!pushf 
!add v,1 
!popf 
!} 
!macro dec v 
!{ 
!pushf 
!sub v,1 
!popf 
!} 

foo = 4
Debug foo
!dec [v_foo]
Debug foo 
there is no need to recompile. many macro features from fasm can be used in PB.

Re: what exectly are macros?

Posted: Tue Jan 04, 2005 1:36 pm
by Kale
Dreglor wrote:i been hear about macros being in 4.0,
and im wondering what exectly are they? what do they do?
Macros are a nice and convienient way to obfuscate and confuse code to make it unreadable by all that has not coded it! 8)

Posted: Tue Jan 04, 2005 2:43 pm
by Dare2
I have always thought of macros as a sort of "inline procedure" - but expanding out the code (putting the code in place of the macro) instead of calling the function. Thus marginally faster but marginally bloatier.

eg (and taking some liberties with Pure's yet to be seen syntax):

Code: Select all

MACRO r.l = myDumbMacro a.l, b.l
  local j.l
  j = a * 10
  r = j + b
EndMACRO

;-v-

Procedure myDumbProc(a.l, b.l)
  j = a * 10
  ProcedureReturn j + b
EndProcedure

result = myDumbMacro valueA, 2

; is effectively replaced with the machine code for
;  local_j = valueA * 10
;  result =local_ j + 2

-v-

result = MyDumbProc(valueA, 2)
Is this on track? Or totally wrong?

PS: I thought they improved readability! :)



EDIT: Lots of Apache errors happening in the forum.