Author Topic: My $IFUSE strategy  (Read 60 times)

jcfuller

  • Full Member
  • ***
  • Posts: 146
    • View Profile
My $IFUSE strategy
« on: July 25, 2020, 08:12:48 AM »
A little more insight into my $IFUSE strategy.
JosÚ Roca first wrote his CWindow/Afx framework for PowerBASIC. He used a source code only approach because of the dead code removal of PB. This made it very easy to maintain.
He then decided to give FreeBasic a whirl and at first almost gave up. There was no way he could find to create the same format as he did with PowerBASIC. It was all or nothing. Finally he discovered the PRIVATE designation for sub/function in a Forum post. The help file was less clear at the time ( or did not exist at all). Only code that was used would be added to the exe. Now he could do exactly as he had done in PowerBASIC. The FreeBasic Cwindow/Afx framework is epic! I am not sure how FreeBasic does this. FreeBasic is basically a translator ( 64bit is is only a translator to c.(They are working on Gas64)) so it could be source level or the linker; ld may do it???

After getting permission to port a subset I quickly discovered I had no way to to achieve the used code only.
My memory fails me but I think the BCX source USE_xxxx gave me the idea of $IFUSE.
There are two parts.
All source that I want to  include or not in a source library I wrap with:

$IFUSE USE_Funcxxx
Function Funcxxx(a As Integer)As Integer
    ? "hello"
    Function = 1
End Function
$ENDUSE

And In the main source file I have
  $USE USE_Funcxxx
  $Include <MyLib.bi>

Yes that means you need to remember what library functions you need for the app you are writing. But the compiler will give you a hint in saying it can't find Funcxxx. High light name;use ctrl insert to copy.
Type $USE USE_. Place the caret after the underscore .Shift Insert to paste.
multiple USE_xxxxx can be typed on one line following the $USE

For this to work the $PP meta statement is placed top and bottom of the app you are coding.
Every source line is fed to my BCXPP.DLL. If it detects a $USE, items are placed in a c++ stl vector
If it detects an $IFUSE it checks this vector for matching names. If found the code is included. If not it is skipped.

I discovered by accident, after I implemented this, that MSVC++ will only add used code if it is all in one single file, which coincidentally is exactly how BCX works.

Wow you say that is a lot of checking of every line of code in your app.
What are the alternatives.
'------------------------------------------------------------------------------
normal "c/c++" approach is to use statically linked libraries but they are a lot of work to implement and maintain. Granularity can be a big PIA
'------------------------------------------------------------------------------
Just include all the source if MSVC will handle it anyway.

BCX reads all the source and translates it to c/c++.
MSVC++ compiles all the c/c++ and sends it to the linker.
LINK decides what is added to the EXE.

The CWindow/Afx Framework has thousands of lines of code.
lots of unnecessary work

'------------------------------------------------------------------------------

This is very useful if you have a very large accumulation of often used procedures.

I am open to other approaches.
What strategy do you use?

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

James





MrBcx

  • Administrator
  • Sr. Member
  • *****
  • Posts: 434
    • View Profile
Re: My $IFUSE strategy
« Reply #1 on: July 25, 2020, 10:16:10 AM »
JC -- I, for one, appreciate the thoughtful explanation. 

To answer your closing question, I don't (currently) have a strategy because
I haven't had the kind of challenge that you sought to solve with your solution. 

I am intrigued with the goal of BCX consuming some of Jose Roca's libraries.  At
the same time, I am a proponent of letting computers perform the tedious, laborious
heavy-lifting, so this all gives me something to chew on. 

You're right about the obvious approach would be to create standard .lib's and .h files
from Roca's work.  Every compiler system worth its salt does "dead code removal"
with pre-compiled libs.   

I'm a bit confused by your concern for maintenance and granularity of his code.  I thought
his libraries were already categorized.  And as for maintenance, other than modding for use
by BCX, how much maintenance do you foresee?

Are you planning to share any of your completed libraries anytime soon? 
« Last Edit: July 25, 2020, 10:23:57 AM by MrBcx »

jcfuller

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Re: My $IFUSE strategy
« Reply #2 on: July 25, 2020, 07:19:10 PM »
Kevin,
  To pour a bit of water on your enthusiasm (sorry) my port is primarily c++ and is all Unicode.
It was ported back in 2016 and I have not compared it with JosÚs latest code. His code is all hard coded Unicode and uses FreeBasic Classes liberally.
Mine is written in BCX ASCII -> c++ and unicoded using ULEX.

Going with the standard .lib direction would be a real nightmare with all the 32/64 bit compilers supported by BCX. The granularity I mentioned was based on tests I did several years ago, not focused on JosÚs library.
If more than one function is in an obj module all would be added to the exe even though only one function was called. To get the best granularity you would have just one or dependent functions in each obj module.
I don't see all that much maintenance but it would still be daunting using the above method.

I am testing using BcxAdp(Application Development Platform) the latest FbEdit hack. All my CWindow demos passed the tests. I still need to get the package sorted out but it should not be too long.
I am also testing the Fred Harris TCLib in conjunction with the CWindow. Looks good so far. Fred has a nice string class that I use a lot instead of std::(w)string



Note with $IFUSE you can create groups so you don't need individual $USE in you main source for all the functions you need in your app.

In your main source:
$USE USE_ALL_ONE

In your source library
$IFUSE USE_ALL_ONE
    $USE USE_AAA USE_BBB USE_CCC USE_DDD
$ENDUUSE

$IFUSE USE_ALL_TWO
    $USE USE_EEE USE_FFF USE_GGG USE_HHH
$ENDUSE

$IFUSE USE_AAA
  Function AAA() As int
 .....
  End Function
$ENDUSE
......
$IFUSE USE_BBB
  Sub BBB()
....
  End Sub
$ENDUSE


James

MrBcx

  • Administrator
  • Sr. Member
  • *****
  • Posts: 434
    • View Profile
Re: My $IFUSE strategy
« Reply #3 on: July 25, 2020, 09:27:12 PM »
JC - thanks for the update ... no surprises, no let downs.  It's all good.