Blitz Preprocessor Released As Open Source

Community Forums/Showcase/Blitz Preprocessor Released As Open Source

Michael Reitzenstein(Posted 2003) [#1]
I have just released the Unofficial BlitzBasic Preprocessor as open source under the GPL lisence. You can download the full source code and EXE here. If you make any improvements to the source, I ask that you send them to huntersd@... for possible inclusion in newer releases.

I am releasing this as free and open source because...

1) It is important to have things a standard, and if some people had the preprocessor and others did not code sharing would become a problem

2) I can't develop it forever and the open source model is the best for fast and efficient bug swatting

The Unofficial BlitzBasic Preprocessor is still in heavy development.

[EDIT - Here is some more information]
The Unofficial BlitzBasic Preprocessor is a preprocessor for (amazingly enough!) BlitzBasic, Blitz3D and BlitzPlus. Its purpose is to preprocessor source files to add features easily that would otherwise be hard for the user to implement in pure Blitz code.

Currently, it features:

Option Explicit - Completion 100%
Enabled with a simple #Option Explicit, the preprocessor will warn of implicit variable declarations in the source code it is passed.

Macros - Completion 100%
Macros can be defined with the following syntax:

#defmacro SomeMacro
Arg1 = Arg2 + Arg3
CallSomeFunction( Arg1, Arg2, Arg4 )
#enddefmacro

#macro SomeMacro, a, b, c, d


...would generate...

a = b + c
CallSomeFunction( a, b, d )


Inline Functions - Completion 50% [General inline code completed but you cannot yet inline calls automatically]

Currently, you can call an inline function with the following syntax:

#inline FunctionName, Arg1, Arg2, Arg3, ...
#setinlineresult FunctionResult


...would be the same as...
FunctionResult = FunctionName( Arg1, Arg2, Arg3 )


Defining/IfDefs - Completion 100%

An example of the commands in use:

#ifndef ThisSourceIncluded

	#define ThisSourceIncluded
	
	Print "Source File Not Already Included"
	
#ifelse

	Print "Source File Already Included"

#ifend


Not implemented is the C style attaching things to them.

Including code from a central directory - Completion 100%

#Include "source.bb"


Will include "source.bb" from the central source directory rather than relative to the main source files path.

Type Writing Commands - Completion 100%

The following directives are implemented:

#WriteType Type_Name, Pointer.Type_Name, Stream_Handle
#ReadType Type_Name, Pointer.Type_Name, Stream_Handle
#PokeType Type_Name, Pointer.Type_Name, Bank_Handle, Offset
#PeekType Type_Name, Pointer.Type_Name, Bank_Handle, Offset
#SizeOf Type_Name, Pointer.Type_Name, VariableToStore


These commands do NOT recurse through all non null pointers in the type and store the 'children' too, they simply deal with ints, strings and floats.


hub(Posted 2003) [#2]
Thanks Michael, but how to use it. Is there some documentation about this ?


Michael Reitzenstein(Posted 2003) [#3]
OK yeah that's the next thing :)

Until then, please visit here for a random list of all the features...


Ian Thompson(Posted 2003) [#4]
Great work Michael.

I was thinking of doing something similar for ages but never got around to it.

Thanks.


Michael Reitzenstein(Posted 2003) [#5]

Great work Michael.

I was thinking of doing something similar for ages but never got around to it.



Feel free to contribute to this one to help get it going better!


LineOf7s(Posted 2003) [#6]
I rang the Pope to see if we could set you up as St Michael but he said they've already got one. Sorry. :o)


Ian Thompson(Posted 2003) [#7]
Will do Michael.

Any more documentation in the pipeline?


Michael Reitzenstein(Posted 2003) [#8]
Ian - I posted a quick overview just then, but I have a feeling I will need to do some more than that! I just don't have time right now unfortunatly...


Zo Zo Zee Zar(Posted 2003) [#9]
BIG IT UP LARGE STYLIE


Michael Reitzenstein(Posted 2003) [#10]
FYI, I am porting this to C# for speed and ease of use.


Michael Reitzenstein(Posted 2003) [#11]
The C# preprocessor's framework is now completely added - it sits between the IDE and BlitzCC, and while ugly console windows come up it otherwise works flawlessly.


Phil Newton(Posted 2003) [#12]
Will you be releasing the C# source code at any point?


Michael Reitzenstein(Posted 2003) [#13]
Yes, and the C# source is actually designed to *be* open source, not like the rubbish source of the original.

I understand some people will not like the use of C# but honestly it is definitely for the better.


Phil Newton(Posted 2003) [#14]
Excellent =D

Great work, and I can't wait to play with the C# version =)


Michael Reitzenstein(Posted 2003) [#15]
Well it might not be long.

#Include (including from a central source directory) and #define, #ifdef, #ifndef, #elseif, #endif are all added!


Michael Reitzenstein(Posted 2003) [#16]
The defines are also much more snazzy now too - they do what C's defines do too.

#define bLaH HAHAHAHA
#ifdef bLaH
Print bLaH
#endif


will become

Print HAHAHAHA


(They are case sensitive)

This does a simple replace, so it works inside of strings and everywhere else, which IMHO is better that way (not to mention very easy to code!)


Michael Reitzenstein(Posted 2003) [#17]
[Edited for the sake of the lesser intelligent MasterBeakers out there, tis just a hypothetical example now!]
...Macros are in. It just went from

#defmacro My_Macro
Call_A_Fucntion( Arg1, Arg2 )
#enddefmacro

#defmacro Another_Macro
Call_Another_Function( Arg1 )
Call_Yet_Another_Function( Arg1, Arg2 )
#enddefmacro

#macro My_Macro, "yes", No
#macro Another_Macro, True, False


to

Call_A_Function( "yes", No )
Call_Another_Function( True )
Call_Yet_Another_Function( True, False )


Its quite exciting really! :D


Phil Newton(Posted 2003) [#18]
I've recently been playing around with writing a pre-processor thingy for an IDE I want to write, but it's not got to too many features at the moment. #include <> is in, but that's about the only one at the moment.

At the moment I'm working on transforming something like this into working Blitz code:

Type Persom
    Field name$

    Person()
    Person(pName$)
    Output()
End Type

Function Person::Person()
    this.name$ = ""
End Function

Function Person::Person(pName$)
    this.name$ = pName$
End Function

Function Person::Output()
    Print "Name = " + this.name$
End Function

Person Ty = new Person("Ty")
Ty.Output()


At the moment I've got the functions sorted nicely, and it's just a case of getting the last 2 lines working. I already know how to do it (I think), so that's not too bad. I'm not too keen on the syntax (would prefer the function code inside the type definition), but I'm keeping it simple for now.


Michael Reitzenstein(Posted 2003) [#19]
Cool, an OOP preprocessor. Cool and yuck :P


Michael Reitzenstein(Posted 2003) [#20]
New to macros:

#defmacro blah

#ifmacroarg 2

TwoArguments ()

#elseifmacroarg

OneArguemtn( )

#endifmacroarg

#enddefmacro

#macro blah, hah
#macro blah, hah, hah


will generate

OneArgument( )
TwoArguments( )


Also, the constants DEBUG, COMPILEONLY and CREATINGEXE are defined automatically depending on what the user is doing. So, you can do something really cool like:

#ifdef DEBUG
Text 1, 1, FPS( )
#endif

#ifdef CREATINGEXE
#ifdef DEBUG
RuntimeError "WHAT THE HELL ARE YOU DOING!?"
#endif
#endif



Michael Reitzenstein(Posted 2003) [#21]
Oooh, just ran my first completely preprocessed program without any redirection or anything. I just turned debug on, and hit the compile button on this:

#ifdef DEBUG
	
	RuntimeError "debug IS ON"
	
#Else

	RuntimeError "DEBUG IS OFF"
	
#EndIf


...And it came up with "debug IS ON".

The last hurdle to 'true' integration is environment variables but they shouldn't be *too* hard to fix.

One thing though - the compile process is very ugly at the moment. Oh well, I don't know how to fix this (for now!) but I will search diligently. Atleast I would, if I knew how to spell it properly.


Michael Reitzenstein(Posted 2003) [#22]


Full Integration is finished as far as I can tell...


Zenith(Posted 2003) [#23]
Haha, cool man!


Michael Reitzenstein(Posted 2003) [#24]
#PeekType, #PokeType, #ReadType, #WriteType, #SizeOf are in the newest build...

Now I 'just' have to do code profiling and option explicit and inline functions! :)