bcc
bcc copied to clipboard
Preprocessor directives
I had a look at preprocessor handling. I thought about adding support to more complex thingies (and + or) but after checking it more deeply, it already does this thing!
?(win32 or linux) or debug
print "I am running either windows or linux - or I just get debugged"
?
(of course this does NOT work with vanilla blitzmax).
The suggestion
So I suggest to use this in some source files we already had to adjust to make them work with "NG". There is no need for cumbersome lines of conditionals doing the same (especially the things with ARM/Android/Linux/Raspi).
I know that the usage of "non-ascii-chars" in the conditionals block will lead to errors in vanilla. So this breaks backwards compatibility.
The new thing
Another thing I would like to see is some kind of "constant" definition (in the likes of "define", "isdef" etc.). Why would we benefit from it? It removes a bit of "cludge" in some scenarios:
?define("linuxbased", linux | android | ...)
?
?linuxbased
print "running on a linux based OS."
?not linuxbased
print "You surely paid for your OS."
?
Above allows to externalize the definition of constants the parser currently has (linuxx86, linuxx64 ...). so that "special" vars are only available when really needed. This does not enforce the removal of such constants - but there might be a variety of checks being really long to include all potential targets/variants.
So what should have to be done to use that?
In the case of a "define(...)" the "?" should be some kind of "single line ?" - if it is somehow possible to keep it conform to "vanilla". As this seems not to be the case you will have to keep with the variant I used above. An "internal" function "define" should handled in the parser (stm = "define") as long as parsing a preprocessor expression. The define then adds to the "env" what the expression in the second parameter suggested.
This should also allow for a "defineString" to allow even string representations of things (maybe autogenerated bmx-files ?).
All of this could even get extended to some of the BMK-NG-function set. Just prepend everything with "NG_" and it should behave backwards compatible as all of these conditionals will be "0" in vanilla bmx and wont lead to execution of the innerlaying code.
PS: Again the reminder: do you know a method to stop the "?"-parsing in vanilla so it could be done in a single line (?define...). The only I can think of is using '?define(...)
(commenting out) but this adds another variant for editors to distinguish. Not the most perfect solution.
That '?define()
portion of course allows to stay backwards compatible because it enables the usage of conditionals consisting of only alphanumerical characters (you create a new variable first using "define" and then ?myvar
on it).
EDIT: I found something "useable" but still looking a bit odd: `?'everything after the ' char is ignored and the whole line is interpreted as a single "?" so it stops previously defined conditionals). While this makes things stay within the "?..." approach, it breaks previous started conditionals. So this is an option, but a "dangerous" one.
Conclusion
To keep backwards compatible source files might use a mixed approach:
'variant A
'?define("purelinux", linux & not android & not raspi)
'variant B
?'define("purelinuxB", linux & not android & not raspi)
?purelinux
print "Seems I run linux on a desktop"
?not purelinux
print "Running on something linux, mac or whatever based."
?
Your thoughts?