Page 1 of 3
Macros !!!!!
Posted: Wed Mar 30, 2005 1:39 am
by DoubleDutch
Code updated for 5.20+ (same as PureBasic's Macro)
Yep - PureBasic actually already has macros!!!!
Because PureBasic's assembler is FASM - you can use the features of fasm to create macros!!!
Code: Select all
!macro test
!{
MessageRequester("test","hello")
!}
!test
!test
This will make a macro called "test", by coding !test twice you will get two message requesters displayed one after the other!
-Anthony
Posted: Wed Mar 30, 2005 2:00 am
by Rescator
Wow! Awsome!
Hey Fred! Would it be safe to just use this as PureBasic's "macro"
Or is there possible issues?
This is cool, but I'm unsure how the compiler likes it.
But if Fred say it's cool, then we got a PB macro all ready to go,
and Fred don't have to write a single line of code,
just add a macro section to the documentation.

Posted: Wed Mar 30, 2005 2:20 am
by Tension
@DoubleDutch
Yes! Thanks!
And this would be probably remain valid for as long as PuerBasic uses fasm.
Re: Macros !!!!!
Posted: Wed Mar 30, 2005 3:10 am
by PB
That's fantastic, and simple to use, too.

In fact, the syntax is so pure
that I don't see why Fred would even need to add a native version of it.
Posted: Wed Mar 30, 2005 3:56 am
by dagcrack
May I say orgasmic!!? because it is. But although, why some of you guys would kill for macros? What do they have that I dont know of?
Oh by the way if I call !test I get assembler error [70] error invalid operand. but if I use just test it works ok. why is this? im an ASM nooblet .

Using 3.91 maybe thats the reason of my problem. ill update soon then.
Posted: Wed Mar 30, 2005 4:21 am
by DoubleDutch
If a Guru says its Fantastic and a Wizard says its Orgasmic then why am I still an Apprentice? hehe
-Anthony
Posted: Wed Mar 30, 2005 4:25 am
by Tension
lol!
At least you have a label. I'm still an undefined reference.
Posted: Wed Mar 30, 2005 4:36 am
by npath
@dagcrack,
There should be a space between '!' and 'test' as follows:
Code: Select all
!macro test
!{
MessageRequester("test","hello")
!}
! test
! test
Npath
Posted: Wed Mar 30, 2005 4:59 am
by Shannara
dagcrack wrote:May I say orgasmic!!? because it is. But although, why some of you guys would kill for macros? What do they have that I dont know of?
Oh by the way if I call !test I get assembler error [70] error invalid operand. but if I use just test it works ok. why is this? im an ASM nooblet .

Using 3.91 maybe thats the reason of my problem. ill update soon then.
Heh, in that sample, doing the same in a procedure would give the same result

What's the big thing about macros?

Posted: Wed Mar 30, 2005 6:15 am
by npath
I second that notion. What is the difference between the flat assembly macros and regular Pure procedures?
Npath
Posted: Wed Mar 30, 2005 8:29 am
by dagcrack
Thats basically what Im asking here.
@npath: Oh I didnt knew! lets blame the double dutch guy!

Re: Macros !!!!!
Posted: Wed Mar 30, 2005 9:10 am
by traumatic
AFAIK you can't use params with that approach, can you?

Posted: Wed Mar 30, 2005 10:35 am
by DoubleDutch
npath: Without a space works okay here - but it should also work with a space...
Shannara: In that example yes, but that was just a proof of concept. Macros expand code - but (normally) give more rapid execution. There are cases where code can actually slow down when expanded, bit this is kinda obvious and also depends on the processor used. I have worked on processors where cache was on 4k boundries! If your code goes over a 4k address boundry then you get a massive slow down!!!
npath: Do a procedure with more code in it and call it a few times, then do it via the macro method - time both... The size of the executable with the Procedure will be smaller, but slower (under normal conditions). The macro version will have a larger executable, but will be faster (again, under normal conditions)...
traumatic:
Ask a Wizard or a Guru!
There may be a way... do some experiments, take a few guesses. Don't forget that you can use the features of Fasm
-Anthony
Posted: Wed Mar 30, 2005 10:52 am
by S.M.
@traumatic
AFAIK you can't use params with that approach, can you?
It is possible:
Code: Select all
!macro ErrText string{
!JMP $+37
MessageBox_(0,0,0,0)
!Push 48
!Push 0
!Push [v_#string]
!Push 0
!CALL _MessageBoxA@16
!}
a$="Hello !"
!ErrText a$
Another nice example:
Code: Select all
!macro DISASM Count{
!PUSH ECX
!JMP $+19
DisASMCommand(0)
!MOV Ecx,Count
!MOV Eax,$+55
!PUSH ECX
!Call PB_DisASMCommand
!PUSH EAX
Debug GetDisASMString()
!POP EAX
!POP ECX
!LOOP $-47
!POP ECX
!}
!DISASM 3 ;Disassembles the next 3 ASM-Commands
A=5
regards
Stefan
Posted: Wed Mar 30, 2005 10:54 am
by leo1991
Macros are faster
Code: Select all
!macro test
!{
bla / 5 * 99
d = 70 * 100000 / (90 + 700)
l = a > c
d * 1000
!}
Procedure test()
bla / 5 * 99
d = 70 * 100000 / (90 + 700)
l = a > c
d * 1000
EndProcedure
#N = 100000000
t1 = GetTickCount_()
For I = 0 To #N
! test
Next
t1 = GetTickCount_() - t1
t2 = GetTickCount_()
For I = 0 To #N
test()
Next
t2 = GetTickCount_() - t2
out.s = "macro: "+Str(t1)+#CRLF$
out.s + "proc: "+Str(t2)
MessageRequester("result",out)