CompilerDefine ?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Melissa
User
User
Posts: 71
Joined: Tue Sep 22, 2009 3:13 pm

CompilerDefine ?

Post 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...
Last edited by Melissa on Thu Apr 15, 2010 6:39 am, edited 1 time in total.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: CompilerDefine ?

Post 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")
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: CompilerDefine ?

Post 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

User avatar
Melissa
User
User
Posts: 71
Joined: Tue Sep 22, 2009 3:13 pm

Re: CompilerDefine ?

Post 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 ?
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: CompilerDefine ?

Post by Foz »

Take a leaf from PureBasic for this kind of stuff: The Peek and Poke functions: PeekB, PeekS, etc
User avatar
Melissa
User
User
Posts: 71
Joined: Tue Sep 22, 2009 3:13 pm

Re: CompilerDefine ?

Post 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.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: CompilerDefine ?

Post 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
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CompilerDefine ?

Post 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.
oh... and have a nice day.
User avatar
Melissa
User
User
Posts: 71
Joined: Tue Sep 22, 2009 3:13 pm

Re: CompilerDefine ?

Post 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 ?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: CompilerDefine ?

Post 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.
oh... and have a nice day.
Post Reply