neilsf / xc-basic3

A BASIC cross compiler for MOS 6502-based machines
MIT License
44 stars 5 forks source link

Feature request: preprocessor directives #165

Closed locodarwin closed 2 years ago

locodarwin commented 2 years ago

Now that XC=BASIC is supporting multiple Commodore architectures, it would be useful to have preprocessor directives such as #define, #if, #else, and the like. This would allow single XC=BASIC source code files/modules to support multiple compile targets, for example. Consider the following example:

#define C64

#if PLUS4
const set_bg_color = $ff15
#elseif C64
const set_bg_color = $d021
#endif 

poke set_bg_color, 0

Could even tie some definitions to command line arguments, such as "--target=", so that preprocessing can switch between cases without altering the source code.

neilsf commented 2 years ago

I wanted to write a page about this in the docs but never had the time. So in short, there's GPP, a generic preprocessor that can be used with XC=BASIC code as well:

https://math.berkeley.edu/~auroux/software/gpp.html

Could even tie some definitions to command line arguments, such as "--target=", so that preprocessing can switch between cases without altering the source code.

Yeah, GPP can do that, too.