Page 1 of 1

CompilerDefine ?

Posted: Wed Apr 14, 2010 10:35 am
by Melissa
Right now PB's macro engine forcing us to writing things that way:

Code: Select all

Macro KKND(DebugProc, SystemDrive)
DebugProc("MS Windows removal initiated...")
; ...code-code-code...
DebugProc("Work completed ^^ !")
EndMacro
; ...code-code-code...
CompilerIf #PB_Compiler_Debugger : KKND(Debug, Drive)
CompilerElse : OpenConsole() : KKND(PrintN, Drive)
CompilerEndIf
...But why such code templation is allowed only through macro's parameters, quite restricted in their content ? IMHO, above code would look a lot better as:

Code: Select all

Macro KKND(SystemDrive)
CompilerIf #PB_Compiler_Debugger : CompilerDefine DebugProc #[Debug]#
CompilerElse : CompilerDefine DebugProc #[PrintN]# : CompilerEndIf
DebugProc("MS Windows removal initiated...")
; ...code-code-code...
DebugProc("Work completed ^^ !")
EndMacro
; ...code-code-code...
KKND(Debug, Drive)
Ability to define and use your own inlining templates at any place inside program is already offered by our beloved FAsm, of course, yet some more high-level alternatives for PB would be really handy, if you ask me...

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 11:35 am
by Foz
You are attacking this from the wrong angle:

Code: Select all

Macro DebugProc(value)
  CompilerIf #PB_Compiler_Debugger
    Debug value
  CompilerElse
    OpenConsole() : PrintN(value)
  CompilerEndIf
EndMacro
Macro KKND(SystemDrive)
  DebugProc("MS Windows removal initiated...")
  ; ...code-code-code...
  DebugProc("Work completed ^^ !")
EndMacro

KKND("test")

MessageRequester("", "Pausing")

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 11:53 am
by #NULL
oh, you got an answer already.
anyway:

Code: Select all


; ####################### define only once.. 

CompilerIf #PB_Compiler_Debugger
  
  Macro DebugProc(param)
    Debug (param)
  EndMacro
  
CompilerElse
  
  OpenConsole()
  Macro DebugProc(param)
    PrintN(param)
  EndMacro
  
CompilerEndIf


Macro KKND(SystemDrive)
DebugProc("MS Windows removal initiated...")
; ...code-code-code...
DebugProc("Work completed ^^ !")
EndMacro

; #######################


KKND("bla:\")

Delay(2000) ; ..to keep the program running a bit


Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 1:49 pm
by Melissa
Just as planned. OK, you are right too, people. Kind of:

Code: Select all

Macro ScanBuffer(CellSize, Buffer)
CompilerSelect CellSize
CompilerCase 1 : CompilerDefine TypeName #[Byte]#, TypeLetter #[B]#
CompilerCase 2 : CompilerDefine TypeName #[Word]#, TypeLetter #[W]#
CompilerCase 4 : CompilerDefine TypeName #[Long]#, TypeLetter #[I]#
CompilerCase 8 : CompilerDefine TypeName #[Quad]#, TypeLetter #[Q]#
CompilerEndSelect
Define *Ptr.TypeName = Buffer
While *Ptr\TypeLetter = 0 : *Ptr + SizeOf(TypeName) : Wend
; ...code-code-code...
EndMacro
...And what if I also need completely different template 'TypeLetter' in another macro ?

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 2:06 pm
by Foz
Take a leaf from PureBasic for this kind of stuff: The Peek and Poke functions: PeekB, PeekS, etc

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 2:40 pm
by Melissa
Foz, fu~... Let's just pretend that I didn't heard that statement. Please, search a bit around that forum for speed comparison between PeekX\PokeX and pointers.

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 4:00 pm
by Foz
*sigh* Please calm down. I was talking about the style.

I meant something like this:

Code: Select all

Macro ScanBufferB(Buffer)
  Define *Ptr.Byte = Buffer
  While *Ptr\b = 0 : *Ptr + SizeOf(Byte) : Wend
  ; ...code-code-code...
EndMacro
Macro ScanBufferW(Buffer)
  Define *Ptr.Word = Buffer
  While *Ptr\w = 0 : *Ptr + SizeOf(Word) : Wend
  ; ...code-code-code...
EndMacro

Re: CompilerDefine ?

Posted: Wed Apr 14, 2010 5:23 pm
by Kaeru Gaman
ermn... I think Macros have the insert chars abylity with the # sign...
so, why don't you take B, W, L , Q for the CellSize parameter instead of 1, 2, 4, 8 ?
you'll have to ype it manually anyways.

Re: CompilerDefine ?

Posted: Thu Apr 15, 2010 6:38 am
by Melissa
*sigh* Please calm down. I was talking about the style.
Ah, that (sorry)... Well, I'm already using such naming convention a lot: http://www.purebasic.fr/english/viewtop ... 12&t=41767
But such methodic only good for procedure blocks, 'cause defining of macros in macro just impossible right now.
ermn... I think Macros have the insert chars abylity with the # sign...
so, why don't you take B, W, L , Q for the CellSize parameter instead of 1, 2, 4, 8 ?
you'll have to ype it manually anyways.
Oh, yes: and additional parameter for typename. Let me just quote myself:
But why such code templation is allowed only through macro's parameters, quite restricted in their content ?

Re: CompilerDefine ?

Posted: Thu Apr 15, 2010 9:57 am
by Kaeru Gaman
just quoting yourself doesn't help making your point clearer...

I don't get your point, but maybe your wish is just of cosmetic matters...
*shrug* so far, nothing to concern me in any way.