QB64-Phoenix-Edition / QB64pe

The QB64 Phoenix Edition Repository
https://qb64phoenix.com
Other
128 stars 26 forks source link

QB45 Compatible SUB/FUNCTION #504

Open SteveMcNeill opened 4 months ago

SteveMcNeill commented 4 months ago

In QB45, the following is perfectly acceptable (though not pretty):

PRINT "Hello"
SUB foo
    PRINT " World"
END SUB
foo

Subs and Functions can appear anywhere in the source, and compile with no issues. One didn't usually see this in QB45 as the IDE had a habit of removing SUB/FUNCTION and placing them at the end of the code, and which one interacted with in separate tabs using F2 (if my memory is correct on all that). If one wants to see this type of code in action, write the BAS file in some other editor (such as NotePad) and then just use QB45 to compile and run it from the command-line. It works 100%, with zero issues.

The most important bonus for SUB/FUNCTION working like this is: 1) For library files. QB45 only uses single .BM library files. They don't have to be broken up into .BI for the top of the code and .BM for the bottom of the code. One $INCLUDE is enough to hold the whole library properly. 2) This would be a good step forward to add in support for FN functionality, as FN would just basically be a local FUNCTION after this.

grymmjack commented 2 months ago

For library files. QB45 only uses single .BM library files. They don't have to be broken up into .BI for the top of the code and .BM for the bottom of the code. One $INCLUDE is enough to hold the whole library properly.

I would love this! It's a PITA to have to conditionally predict and include stuff in the existing archaic way.