Test code in includes

Everything else that doesn't fall into one of the other PB categories.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Test code in includes

Post by Perkin »

Just gave jaPBe a small try, using the test files as given in earlier post.

Using the cutter plugin ..
Compiling to executable the MyTestProc2() is still added to final executable even though it isn't being called.


-----

As said in previous post, I think I'll just have to comment out the test code when not testing or have it in its own file.

Again thanks to all.
%101010 = $2A = 42
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Test code in includes

Post by luis »

Bisonte wrote:If you want "not included" unused procedures...

jaPBe has a "Cutter" Plugin, that shredder the code to one big file with only the used procedures...
(for the final compile its very useful...)
Does it really work ?

I wanted to make something of that kind myself but I given up.

http://www.purebasic.fr/english/viewtop ... 54#p369254

Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
"Have you tried turning it off and on again ?"
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Test code in includes

Post by luis »

Perkin wrote: The resultant main project code runs as it should, but viewing the exe in a hex viewer, it looks like the MyTestProc2 is still included, even though it isn't called directly - only from the now not included test code.
The body of the procedure (the code) is not included, only its text (string) in the data section.
This is because the pb compiler generate all the code/data for all the procedures inside macros, and then SOME of them are never expanded.

http://www.purebasic.fr/english/viewtop ... 45#p318245

Code: Select all

; 
; #INCLUDED=1
; 
; Procedure MyTestProc()
macro MP0{
_Procedure0:
  PS0=4                                                                                                                                                                                                                                                     
; MessageRequester("Hey","I am here!")
  PUSH   dword _S1
  PUSH   dword _S2
  CALL  _PB_MessageRequester@8
; EndProcedure
  XOR    eax,eax
_EndProcedure1:
  RET
}
; 
; Procedure MyTestProc2()
macro MP2{
_Procedure2:
  PS2=4                                                                                                                                                                                                                                                     
; MessageRequester("Hey","I am here as well!")
  PUSH   dword _S3
  PUSH   dword _S2
  CALL  _PB_MessageRequester@8
; EndProcedure
  XOR    eax,eax
_EndProcedure3:
  RET
}
; 
; CompilerIf Defined(INCLUDED,#PB_Constant)=0
; 
; 
; MyTestProc()
  CALL  _Procedure0
_PB_EOP_NoValue:
  PUSH   dword 0
_PB_EOP:
  CALL  _PB_EndFunctions
  PUSH   dword [PB_MemoryBase]
  CALL  _HeapDestroy@4
  CALL  _ExitProcess@4
_PB_EndFunctions:
  RET
; 
MP0
; 
section '.data' data readable writeable
; 
_PB_DataSection:
_PB_OpenGLSubsystem: db 0
pb_public PB_DEBUGGER_LineNumber
  dd     -1
pb_public PB_DEBUGGER_IncludedFiles
  dd     0
pb_public PB_DEBUGGER_FileName
  db     0
_PB_ExecutableType: dd 0
public _SYS_StaticStringStart
_SYS_StaticStringStart:
_S1: db "I am here!",0
_S3: db "I am here as well!",0
_S2: db "Hey",0
pb_public PB_NullString
  db     0
public _SYS_StaticStringEnd
_SYS_StaticStringEnd:
align 4
align 4
s_s:
  dd     0
  dd     -1
align 4
; 
section '.bss' readable writeable
_PB_BSSSection:
align 4
; 
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
; 
align 4
PB_DataPointer rd 1
align 4
align 4
align 4
align 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:

I really want a option to make the PB parser generate a single, expanded, preprocessed source for me.
"Have you tried turning it off and on again ?"
User avatar
Bisonte
Addict
Addict
Posts: 1336
Joined: Tue Oct 09, 2007 2:15 am

Re: Test code in includes

Post by Bisonte »

luis wrote:
Bisonte wrote:If you want "not included" unused procedures...

jaPBe has a "Cutter" Plugin, that shredder the code to one big file with only the used procedures...
(for the final compile its very useful...)
Does it really work ?

I wanted to make something of that kind myself but I given up.

http://www.purebasic.fr/english/viewtop ... 54#p369254

Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
I think so... I tried it with the jaPBe source itself and it works there... only one big file and a lot of procedures are not
longer in the source.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Test code in includes

Post by Perkin »

luis wrote:
Perkin wrote: The resultant main project code runs as it should, but viewing the exe in a hex viewer, it looks like the MyTestProc2 is still included, even though it isn't called directly - only from the now not included test code.
The body of the procedure (the code) is not included, only its text (string) in the data section.
This is because the pb compiler generate all the code/data for all the procedures inside macros, and then SOME of them are never expanded.
So it's only the string data that's added?

I think that might be alright, I'll have to check through some of them to see.

Thanks.
%101010 = $2A = 42
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Test code in includes

Post by luis »

Bisonte wrote:
luis wrote: Does it really work ?

I wanted to make something of that kind myself but I given up.

http://www.purebasic.fr/english/viewtop ... 54#p369254

Just think of using one or more macros to build up a procedure body, or a procedure to be excluded by some conditional compilation. Does "cutter" works as expected here ? I doubt it.
I think so... I tried it with the jaPBe source itself and it works there... only one big file and a lot of procedures are not
longer in the source.
A simple example, you can make it more convoluted and find many other "hard" cases

Code: Select all


; unused1()
Macro genproc_start()
  Procedure unused1()
    Debug "unused1()"
EndMacro
  
Macro genproc_end()
    ProcedureReturn
  EndProcedure
EndMacro

genproc_start()
genproc_end()

; unused2()
Procedure unused2()
 unused1()  
EndProcedure

; used1()
Procedure used1()
  Debug "used1()"  
  ProcedureReturn
EndProcedure

Procedure Main() 
  used1()
EndProcedure

Main()

Perfectly valid, but fails with cutter and lead to the unneeded inclusion of unused1() with PB. As I said, I don't think there is a solution in existence working reliably.

Not until... http://www.purebasic.fr/english/viewtop ... =3&t=40658
"Have you tried turning it off and on again ?"
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Test code in includes

Post by Perkin »

That looks like it would be good.
%101010 = $2A = 42
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Test code in includes

Post by blueznl »

Two notes:

1. Trimming... look around, several tools were at one time posted. I hate the missing includes myself, so I added a 'trimming' version to CodeCaddy as well.

2. Includes... yeah, I would love to have a constant that would indicate if the include was executed by itself, or if it was included by another program. It would make it so much easier to maintain includes and quickly test them for bugs. I'd love it.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Test code in includes

Post by Sirius-2337 »

I would love to have a constant that would indicate if the include was executed by itself, or if it was included by another program.
You can do this by adding a Custom Constant in Compiler Options.
For example add "#IsExecutedByItself = 1". Then you can check whether the Constant is defined or not.
It won't be defined if the code is included by another code.
Post Reply