Page 1 of 1
PB4 Wish - Macro parameter count and recursion
Posted: Tue Sep 28, 2004 10:31 pm
by tinman
With the upcoming pb4 which is meant to have macros, it would be very cool if we could have some sort of compiler symbol which represents the number of arguments passed to a macro.
Kind of like `0 in Blitz 2 (IIRC).
Edit: being able to write recursive macros would also be an advantage.
Posted: Fri Oct 01, 2004 12:10 pm
by Psychophanta
I request for the most similar FASM syntax as possible

It's the easiest

Posted: Fri Oct 01, 2004 2:43 pm
by GedB
I'll seecond the FASM request.
Posted: Fri Oct 01, 2004 3:03 pm
by naw
Dont mean to steal the thread (sorry) just 1 reply will suffice
What will macros do for me? Do you mean <I>macros</I> in terms of recording common IDE key sequences? Or is it something more than that. Its just that there seems to be a lot of *excitement* about this - and, well - I think I must have missed the point....
In MS Excel (for instance) I can create some VBA quickly and easily by recording a Macros (format a colum, Insert a Row etc) so I think my understanding of <I>macro</I> must be different to yours...
Ta - N
Posted: Fri Oct 01, 2004 3:38 pm
by tinman
It's a sequence of code or whatever that you can insert in your code wherever you put the appropriate symbol.
Think of constants but with more complex capabilities than numbers and strings.
Posted: Fri Oct 01, 2004 4:54 pm
by naw
Mm! Ok, thanks Tinman, I get it. But... I think if I used the same Block of code > 2 times, I'd create a procedure for it, so perhaps I'm not so bothered about Macros's.
Appreciate your explanation, though

Posted: Fri Oct 01, 2004 7:31 pm
by PB
> if I used the same Block of code > 2 times, I'd create a procedure for it,
> so perhaps I'm not so bothered about Macros's.
Macros are not just for replacing procedures... you can replace ANY code
with a macro. For example, a lot of my apps use the MessageBeep API to
make a sound, using MessageBeep_(#MB_ICONASTERISK). With macros,
I can replace this command with something much shorter, like Chime().
Whenever the compiler sees Chime() it replaces it with the longer version.
Same functionality and end-result, but much less typing in the source.

Posted: Sat Oct 02, 2004 12:10 am
by naw
- I think I would still use a procedure. But, if I understood ASM (for example) then I can see how this might be invaluable... In the longrun, I find it makes maintenance and Bug-fixes much easier to manage because I use descriptively named Procedures that are re-used in my code many times to describe my *logic-flow* (almost no comments). Lots of code that is replaced by the IDE sounds like hard work to maintain to me.
But that said, you and Tinman are way more competant PB'ers than I am, so although *I* dont care about Macros, its probably good that you do
- anyway, dont want to steal Tinmans thread...
Posted: Mon Oct 04, 2004 7:38 pm
by blueznl
here's a good example for a macro
i don't like to use POKEB etc. as it's not very readable, so i'd use a macro that creates a new variation:
in pb:
POKEB( x , y )
would be:
BYTE( x ) = y
to me, the second form is much more readable than the first (well, if fred needs another wish, here is another one

)
Posted: Tue Oct 05, 2004 9:03 am
by Psychophanta
... or "put y at BYTE(x)", it is even more readable

Posted: Fri Oct 08, 2004 11:40 am
by Kazmirzak
There is a different between macros and functions:
Maybe you want to make a collection of macros with your own commands, maybe you don't like the Word 'gagdet' and you write a macro for each gadget-function so that you now use "MoveWindow" instead of "MoveGadget" and so on (just an example)
There are two ways:
1. You write an include-file with lots of functions
2. You write an include-file with lots of macros.
The great advantage of macros is that they are only included in your code when they are needed, so your exe will still be small. Functions are all included even if they arent needed, so your exe will grow. And the second thing is that functions have a little slow down effect - because all the parameters go to the stack, then the function reads the stack - macros replace the code itself with the new code so no stack and no function call is needed!
So MACROS are perfect!
Posted: Fri Oct 08, 2004 11:52 am
by El_Choni
Macros are also in my wishlist, but they're not that "perfect" if not properly used, I mean, you shouldn't use them instead of procedures all the time because each time the macro is used, the PB code gets replaced by the macro code, and this *does* take space in the final exe.
Regards,