Suggestion : Compiler Directive

BlitzMax Forums/BlitzMax Programming/Suggestion : Compiler Directive

Armitage 1982(Posted 2012) [#1]
Is this still impossible to add your own compiler directives for conditional compilation to BlitzMax ?

Maybe a pre-processor source code addon?

Try not to talk about constant, global or variable flag please. It's not a correct solution.


Maybe one of the last feature we could ask to Mark !?


Oddball(Posted 2012) [#2]
I've been requesting this for ages. I doubt it'll ever get added.


ima747(Posted 2012) [#3]
the CE ide supports post scripts and I believe there's some directive stuff in there as well... when paired with brucy's BMK that is. Also cross compiling from MacOS...

Last edited 2012


col(Posted 2012) [#4]
+10 for this please for this to be added, please Mark :)


ProfJake(Posted 2012) [#5]
Yes, definitely.

This is one of those little neat features that I am really missing in Max.
It would be nice to at least be able to check if certain modules (and their functions, classes etc)
were imported, since there are no namespaces.

Maybe something along the lines of:

?Not Imported("brl.math")
' Provide own functions with the same API
?


.. or alternatively just a test for a define (naming-scheme?):

?_MOD_BRL_MATH
' ..
?


This would make for a much greater reusability of modules.

Pretty please? :)

Last edited 2012


Grey Alien(Posted 2015) [#6]
Just bumping this. I guess there's still no way to create your own conditional compile time constants? I need this because I only want to import a library if the constant is true instead of having to manually comment it out (so I don't have to ship it with certain builds)


Brucey(Posted 2015) [#7]
While bmk is easy enough to "fix", bcc would also require changes, which I find highly unlikely to occur in the near future.


Grey Alien(Posted 2015) [#8]
:-(

Now I have to put rem end rem around the import and includes + use a standard Const for code I want to run.


Yasha(Posted 2015) [#9]
You could try hacking the C preprocessor into Max, for full C-style macro support instead (and with it, #if/#endif). Here's an attempt:

1) rename bin/bmk to bin/bmk_real

2) save the following script as bin/bmk:



3) run program normally:

'test
#define FOO 1
#define BAR "bar"
#define dbl(X) ((X) * 2)

#If FOO == 1
Print dbl(FOO)    'prints 2
#Else
#  If 1
Print BAR
#  EndIf
#EndIf


I'm not experienced with awk so someone else could probably do a much better job, but surprisingly it actually seems to work (OSX, MaxIDE). No recompilation of Max tools required.

All it does is replace Max style 'comments with C-style //comments, and ensure that #if, #else etc. are capitalized correctly. It also removes the GCC annotations from the output (just running with -P would destroy line numbering). Note that while it corrects keyword capitalization (because the IDE won't let you write it without capitals), it doesn't change the expression syntax, so you still have to use ==, && and so on.

A more advanced version could conceivably get rid of the conflict with #label, but I assume nobody uses that in practice. Since this version compiles file.bmx.tmp.bmx instead of file.bmx, it probably also plays absolute hell with quick builds and Import, so adding some lines to rename the generated assembly/object files (the hidden ones - final executables are named as expected) might be useful (or maybe that's the point where you ought to start modifying BMK itself, I don't know; thoughts?).


Grey Alien(Posted 2015) [#10]
Blimey, that's pretty advanced stuff there. Now if only BRL could make this kind of thing official, so useful!