neilsf/XC-BASIC

Suggestion: include function to add additional source files before compilation

Closed this issue · 3 comments

Note: I don't need this right now!!! ;)

An include function to add additional source files would be nice. So you could write and add libraries (that need to be written in the future ;) ) or reccurring consts like colors, etc. Could also be helpful to cleanup larger projects

Eg.

include "consts.bas"
include "gfxlib.bas"

I'm not sure if it should be a requirement to put includes always at the beginning. Eg. this also could be nice:

include "consts.bas"

rem many, many code lines
.
.
.
rem end of many, many code lines

include "additional-data-lines.bas"

I think included files should be first injected to the main source, and then the whole source should be compiled. Which means that whatever you include, it depends on the nature of the statements where you have to include them. Constant declarations in the beginning for sure, but data could go anywhere.

This brings up more issues:

  • There must be some sign that separates compiler directives from BASIC statements, maybe the c-like # will do (e.g #include "consts.bas") - I'll check if it conflicts with variable type definition.
  • Must decide if recursive inclusion is allowed - i. e. A includes B and then B includes C - I'd say no for the sake of simplicity.
  • Must decide if directory traversal is allowed or the included sources must be in the same folder - would be good to make the same program compile well under Linux and Windows as well where directory separator characters are different.

I think I can try this in version 2.

As for the constants for colors, etc: I'm also thinking about creating pre-defined constants, like in C:
__BACKGROUND__
__BORDER__
__BLACK__
__WHITE__
Not sure about double underscores, but something similar...

In latest develop branch.