PDA

View Full Version : Several tBasic Files



KF4GHG
30-07-2024, 19:38
Hi - I was wondering if I can create and later compile multi tBasic files into one executable? For example one.tBasic, two.tBasic into onetwo.exe. Thank You...

Yann_F_29
03-08-2024, 00:04
Hi - I was wondering if I can create and later compile multi tBasic files into one executable? For example one.tBasic, two.tBasic into onetwo.exe. Thank You...

Hi Ronnie.

Yes you can create several files and run/bundle them in a single way.

I use




'---Load modules
Uses "Console", "OS" ,"bundle" , "ui" , "file", "sapi"


' 1.12.0 Change name include files
' .1 correction ----
' .3 c-----
' 13.0 - resolve_sym
' 14.0 resolve_symbol conditionnal
' 15.0 test exist sourcefile
' ..
' ..
' ..
' ......
' 34 add macros "%%timehms%%" "%%timehm%%" "%%datejma%%" " %%dateamj%%" (9/6/23)


dim version_nbr as string = "V: 1.34.0 09-06-2023 " & $crlf
dim dbg_indent as string = "Dbg--|"
'
'
#BUNDLE Icon "D:\Users\Root\Desktop\ThinBasicStuff\00-exe-icon.ico"

%insert_no = 1 as byte
%insert_yes = 0 as byte

#Include "asm_1802_0_dbg_codes.tbasic"
#Include "asm_1802_0_dbg_get_options.tbasic"
#Include "asm_1802_2_functions.tbasic"
#Include "asm_1802_3_asm_main.tbasic"
#Include "asm_1802_3_define_org-equ.tbasic"
#Include "asm_1802_4_decode.tbasic"
#Include "asm_1802_4_look_symbol.tbasic"
#Include "asm_1802_5_ins_new_symbol.tbasic"
#Include "asm_1802_5_ins_unres_sym.tbasic"
#Include "asm_1802_6_extr_reg_num.tbasic"
#Include "asm_1802_7_evaluate_operand.tbasic"
#INCLUDE "asm_1802_8_analyse_operand.tbasic"
#INCLUDE "asm_1802_9_resolve_undef_symbols.tbasic"
'
'Start of main code
'




This the main file.


Lines 1 ,2 : Declaration of modules used , included files may declare additional modules

Lines 5 to 15 : Comments for keeping history of development

Lines 22 and other not displayed : Bundle directives

Lines 27 to 39 : Calls to different parts of code

Lines 39 --->>> : Main code

In my development, the main code starts with DIM of variables used thrugout the program.
And other files are functional parts.
So when working/debugging, I use ThinAir to open/edit the main file, and open only other modules I am working on.
An when I hit the run button in the main file, all open modified files are saved on disk, and execution begins.
The ThinBasic.exe does the work of openig all included files.

You should be aware that Included files should not declare same variables leading to duplicate declare error.

And something happened in earlier version of TB : The run button of ThinAir saves modified files opened, but the BUNDLE button did not.
This leaded me to have some problems :

- I modify included file , run in ThinAir with green arrow
- The file is saved , and the programs run.
- The code does correctly the work, but I see a typo in a message. I correct the typo, and start the Bundle phase.
- I run the generated exe...... The typo is still present :oops: . In fact the bundle process worked with previous fie version, And on the ThinAir screen the typo appears to be corrected.
so be careful to save all files before Bundle.




In this work the main file is about 300 lines long, and the total of the project is about 10000 lines.

Some of include files are used in another project, this leads to be rigourous in variables names/declarations.

This is my way of working, I guess there are other way of work.


Question to Eros/Petr : Does the pre process of execution could accept conditional pathes as does C preprocessor "IFdefined xxxx then .....



Yann

KF4GHG
03-08-2024, 15:48
Thank You...


Hi Ronnie.
Yes you can create several files and run/bundle them in a single way.
Yann

Petr Schreiber
05-08-2024, 11:54
Hi,

thank you for starting an interesting discussion!

Code structure
Looking at the script by Yann, I follow very similar structure in my project, with one modification:
- main file, the application, uses .tbasic extension
- secondary files with reusable code use .tbasicu (thinBasic Unit) extension

It does not change anything regarding behaviour, but I try to design .tbasicu files so they are self contained (have complete spec of module dependencies, for example), so I can grab them and use in another project.

Avoiding name clashes
The mentioned collision of variable names is something which is in other languages solved via namespaces.

ThinBASIC does not have this concept at the moment, but you could workaround it by having dedicated TYPE in each .tbasicu file.

For example, if I would have file "myMatematicalFunctions.tbasicu", then I could create the following pattern in the file:


TYPE tMyMathematicalFunctions
... add variables here
myVar AS LONG
myText AS STRING
END TYPE

DIM myMathematicalFunctions as tMyMathematicalFunctions


...then I can refer to the variables using myMathematicalFunctions.myVar, myMathematicalFunctions.myText.

That means I can have myVar, myText in other files too, but thanks to unique "prefix", collision risk is reduced.

Conditional paths
I am not sure I fully understand, but you can use:



#IF #DEF(someVariable)
' one branch of code
#ELSE
' another branch of code
#END IF


Please note there is no "THEN" used in this case.


Petr