Page 1 of 1

Do not compile unused procedures

Posted: Sun May 01, 2005 10:43 pm
by Justin
when using generic includes with lots of functions the small exe filesize can go away. i known i can use TB

Re: Do not compile unused procedures

Posted: Mon May 02, 2005 9:11 am
by PB
I've been asking Fred for this for years. :)

Posted: Mon May 02, 2005 8:38 pm
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?

Posted: Mon May 02, 2005 9:39 pm
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)

Posted: Mon May 02, 2005 10:09 pm
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?

Posted: Mon May 02, 2005 11:34 pm
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.

Posted: Tue May 03, 2005 1:17 am
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

Posted: Tue May 03, 2005 8:50 am
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.