Do not compile unused procedures

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Do not compile unused procedures

Post by Justin »

when using generic includes with lots of functions the small exe filesize can go away. i known i can use TB
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Do not compile unused procedures

Post by PB »

I've been asking Fred for this for years. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i think it makes sense to turn pb into a two pass compiler...

in pass 1 look for all procedure and variable declarations (oh my, no more 'declare' statements... heaven...) and create a list of all called procedures

then, in pass 2, only compile what is used

i do think that makes sense, or doesn't it?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

sure is the way to go. but i have no idea of how difficult it can be to implement. and don't forget an option explicit for variables or just don't allow undeclared ones (asked so many times)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Not difficult at all. In fact there are a few for PB already out, which basically uses the PB compiler as a 2nd pass. PBDev anybody?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> i think it makes sense to turn pb into a two pass compiler

I think there are two main reasons why this hasn't been done (and this is
just my own speculation, and not fact):

(1) The extra slowdown that will be caused due to two passes. IMO: big deal.

(2) The "bad reputation" the compiler will get, because it can no longer be
classed as a "single pass" compiler. Frankly, I think a two pass compiler
would be more successful if advertised as two pass, because it would show
potential purchasers that it's more in-depth and thorough with its checking
than a single pass compiler. :) Better code optimization, etc.

> in pass 1 look for all procedure and variable declarations (oh my, no more
> 'declare' statements... heaven...) and create a list of all called procedures

Very easy to do; I even wrote a little tool that does that so I can see what's
unused before I create my exes. I think there's a plugin for jaPBe that does
this also.
Last edited by PB on Tue May 03, 2005 1:51 am, edited 3 times in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

imho,

An optional 1st pass could add so many optional features such as this and more (see the forum for other possibilities).

You could add a directive to the beginning of the source such as "PrePass" or similar to perform this extra pass.

Thus it remains a single pass compiler (by default).

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

I agree with Justin about that a 2 pass compiler will be useful to remove none used functions.
It will be also useful to analyse correctly variable status.
Because, currently we meet the following problem with global variables:

Code: Select all

Procedure test() 
  a + 20 
EndProcedure 

Global a.l 
a=10 
test() 
Debug a
The result is a= 10 and not 30.

But we can keep the current one pass compilation, and its speed efficiency, by giving to it the list of functions really used and variables status.
In fact, this list can be created during the code writing thinks to the editor capability rather than during a dedicated compiler pass.

For example, actually, JaPBe raises directly the list of all the functions and variables that are available in the code (which are used or not).
We can imagine distinguishing the used functions and referencing variable status, then giving this list to the single pass compiler.

Thus, this way of working needs two improvements:
- At the editor level: Its capability to raise the appropriate list of functions and variables (and any else). Let us note that the PureBasic standard editor already lists the procedures of a code.
- At the compiler level: its capability into receiving and analyzing the given list. The syntax would be similar to those of the already available compiler options.

This idea joins PB one.
Post Reply