BM Precompiler?

BlitzMax Forums/BlitzMax Beginners Area/BM Precompiler?

Retimer(Posted 2008) [#1]
Has anyone release some form of alternate precompiler for blitzmax, that supports defines like below?

#define Profiling=1

#If Profiling

#Else

#


Or anything like it?

?Debug,?nodebug,?win32, etc isn't cutting it for me right now.


Dreamora(Posted 2008) [#2]
There was a preprocessor that allowed profiling.
But that was quite some time ago and I think it died down.

No idea why, but given the fact that there isn't a serious developer market to sell it to at a reasonable price, the effort needed to keep this up to date with all the changes that happened between 1.18 and 1.26 language wise might have been too large.


Retimer(Posted 2008) [#3]
Ah well, thanks for the info. Can only hope Mark will throw a bit more attention to blitzmax and not let it die down slowly like its older siblings (or so it seems).


Dreamora(Posted 2008) [#4]
Don't think so, as it got some nice features recently with reflection and reflection on its own opens a whole lot of new paths ("interfaces" like java, delegates for method pointer etc)


TaskMaster(Posted 2008) [#5]
You could probably cheat, and make a quick little app that read the BMX file line by line and did the post-processing creating actual different files and then running the compiler against them...


Czar Flavius(Posted 2008) [#6]
I'm suprised this doesn't already exist.


Retimer(Posted 2008) [#7]
I could TaskMaster, and I wouldn't have too many problems doing so. However, one of the reasons I moved to BM so I wouldn't have to do workarounds like that to get things done so unprofessionally, and I don't really have the patience or time to do it professionally for something that I, and i'm sure several others believe should already be supported by 'home base'.

@Czar, I am too. I hadn't gotten to this point in dev on my project until now, but I assumed that there were several options for this around.

Would top it off if some of the custom ide's out there added this feature as a plugin. I wouldn't mind paying extra for it as an addon.


H&K(Posted 2008) [#8]
I still think this is an IDE problem, and not a languange one. However I can see how at least tacit support by Mark, (say a brief), would help in this situation.


Czar Flavius(Posted 2008) [#9]
Something like Blide could add it easily. Just parse the code before sending it to be compiled. If people are going to do this seriously, (which noone probably is but I can still hope) then they should agree a standard syntax for the precompiler.

Enums are something I sorely miss from my days of C, that could be hacked in with a precompiler. They're just constants with unique integer values. It would save me having to redefine a long bunch of constants whenever I add/remove from my attempts to get enums.


Retimer(Posted 2008) [#10]
Blide & that would make blitzmax a dream come true for me.


grable(Posted 2008) [#11]
After reading this thread i finally sat down and thought about how to get preprocessing with the least amount of work.
I ended up using OllyDbg on BCC and eventually patched it to pass any bmx file through a preprocessor before compilation, and it works!

The beauty of this hack, is that all the other tools are oblivious to its existence, so they should work without modification.
And it wasn't much work once i figured out how, BRL could probably do it cleaner though. ;)

I made this for Windows btw. The code itself should work on the other platforms, but the patch is windows specific as its all i have access to.


If anyone is feeling adventuress, heres how to try it out:

Before you mess with your blitz install, please take a backup of the entire bin directory just in case.

Since this is a binary patch it only works on BCC v1.28.

Download the patch bcc_ppc_patch.delta3
(you need xdelta3 to apply the patch.)
Then copy the file to "C:\Program Files\BlitzMax\bin"

How to apply the patch. Open a new console window and enter this:
cd "C:\Program Files\BlitzMax\bin"
ren bcc.exe bcc.exe.backup
xdelta3 -d -s bcc.exe.backup bcc_ppc_patch.delta3 bcc.exe

Then you need to set a system wide environment variable with your preferred preprocessor.
BCC_MODE = program "%s" "%s"
The first %s is the INPUT, the second is the OUTPUT (they are replaced later by bcc).

The executable must be in a folder on the path.
To disable preprocessing delete the environment variable.

Note that a temporary file ppc.out is created in the working directory, it can safely be deleted when the compilation is done.


Heres how i use M4 as my preprocessor. I had to use a batch file, as m4 doesn't seem to have an output switch:

bccppc.cmd
@echo off
m4 %1 > %2
rem or if you prefer gcc
rem gcc -E -P -C -x c -nostdinc %1 > %2
BCC_MODE = bccppc.cmd "%s" "%s"

And finally a test blitz source to check if M4 is working properly:
define( MESSAGE, "Hello World!")
Framework BRL.StandardIO
Print MESSAGE



Have fun! =)


Retimer(Posted 2008) [#12]
I don't quite understand the define use here, bear with me =P.

so, if I put this:

define(PROFILING, 1)

If PROFILING
 ''This code will be compiled
else
 ''This code wont?
end if


Sorry i've just woke up, but it looks like it just defines a variable, and would compile everything anyways. Can you explain this in more detail?
Or is this just an example proving that it can be done with a bit more work?


grable(Posted 2008) [#13]
Its just a test to see if M4 is working, the normal BCC would complain about the define() function not existing.

So your code looks like this after processing:
If 1
 ''This code will be compiled
else
 ''This code wont?
end if
Meaning you would have to use the preprocessors conditionals instead of BlitzMaxs.

Heres a better example using C preprocessing syntax that would give the result you expect.
#define PROFILING

#ifdef PROFILING
 ''This code will be compiled
#else
 ''This code wont!
#endif


I realize this is in the Beginners Area, so people might not know how to use this. But this is where the tread was ;)
maybe i should cross post?


Czar Flavius(Posted 2008) [#14]
In C you can do something like this:

#define timesten(x) x * 10

y = timesten(5);

This turns into

y = 5 * 10;

(Which the compiler will automatically turn to 50 anyway)

Just a simple example but it allows you to cleanly place complicated expressions in your code without needing a (slow?) function to do it.

I use functions to work out what pixel is in which tile etc that can be done using macros (the #define things).


The BM limited precompiler uses the ? symbol, perhaps we should follow suit in case a popular precompiler is added officially?

?define PROFILING 1