New version of PreProcessor coming soon

Community Forums/Showcase/New version of PreProcessor coming soon

Michael Reitzenstein(Posted 2003) [#1]
The eventual goal of my game source was to have the same source compiling in Blitz3D and BlitzPlus, using 3D acceleration in Blitz3D and the windowed commands in BlitzPlus. This wouldn't be possible without a preprocessor - and mine was missing two key features.

Firstly, there was no automatic way to determine the compiler type. The preprocessor will now define either BLITZ3D or BLITZPLUS depending on what Blitz version you are running.

Secondly, it was incredibly difficult having the preprocessor installed in both Blitz3D and BlitzPlus. I never bothered - up until today my BlitzPlus never had my own preprocessor installed on it. The preprocessor now automatically declares environment variables, which should fix quite a few problems.

Added to that is the version 6.0 fixes (6.0 wasn't officially released), which are:

/* Changes Since 5.0
* Completely redid profiling. It's now sooo cool!
* Fixed a #Macro bug [I now clear out the conditional stack, what a mistake!]
* Fixed a #Define bug
* Added Enum
* Fixed a bug where double spaces between Function and the Function Name will interfere with profiling
* #ProfileNoFunctions
* #ProfileSection [Section]
* #EndProfileSection
* #Clamp Variable, Low, High
* Profiling now includes a separate HTML page per function.
*
* ProfileSections don't do any funky stack based things and so they have to be placed without overlap in terms of source position
*/


I guess the release will be in a day or two, all things going well.


Boiled Sweets(Posted 2003) [#2]
Is it free?


Beaker(Posted 2003) [#3]
I think so. And it comes with a free Tanned Genital box set.


Rob(Posted 2003) [#4]
With rich tea biscuit stains.


Michael Reitzenstein(Posted 2003) [#5]
It is free.


Rob Pearmain(Posted 2003) [#6]
Please let me know when it is avaiable as I use it all the time (Mostly for #Option Explicit)


Michael Reitzenstein(Posted 2003) [#7]
Releasing it involves, well, uploading it... But since you asked, it's released now. Download it here.


Rob Pearmain(Posted 2003) [#8]
awesome, many thanks


Ross C(Posted 2003) [#9]
Hey Michael! What exactly is a preproceesor? I'm not familar with that term. :)


Michael Reitzenstein(Posted 2003) [#10]
Hey Michael! What exactly is a preproceesor? I'm not familar with that term. :)


If you don't know what one does, chances are you won't find it useful. But here is a quick lowdown:

A preprocessor is an extra step inbetween the IDE and the compiler. It scans the code, making changes to it according to the preprocessor directives placed in the original source file. This is how #IfDef, macros, code profiling etc can all be done automatically.


Paradox7(Posted 2003) [#11]
I to always wonder what exactly this would be use for? I've heard of others using it, to write for example a macro of say 200lines, which would then write out code of 1000+ lines for him. I mean what exactly can be done here with this? Any examples? Small programs written to show what this can do, no matter how pointless the resulting program is, just wondering how to utilize this as it seems to help others who know what it does :P


MSW(Posted 2003) [#12]
Paradox7 - this is just one little example...

Lets say you write a small little function to pull appart a 16-bit integer inorder to get the Red, Green, and Blue color componets...no big deal right?

Now lets say that your application is some sort of graphics editing software...maybe used to create tiles for a 3D game or textures, whatever...and you have included some other function that will blur the tile,graphic...basicly a routine that uses that "seperate color componets" a lot.

Well then the precompiler profiler will tell you that you are spending a lot of time in this "seperate color" function...so if you want to increase the speed of the blur routine it would be wise to try and optimize the "seperate color" function...however that will only go so far as the core process of calling a function takes time (PUSH stuff onto the stack, JUMP to the function, POP stuff back off the stack, do the function code, then JUMP back to where the function was called)...

So what you can do instead is define the "seperate colors" function as a Macro...then basicly the precompiler finds everyplace where you call the "seperate colors" function and places the code within the function inline with the rest of your program as it is compiled...this allows your program to operate those functions faster because the CPU doesn't need to do a function call at all...basicly you can go from this:

FOR i = 1 to 100

 Temp% = Dostuff(i)

NEXT

END


Function Dostuff (value%)
 Value = value + 1
Return Value
End Function



by useing the macro the Blitz compiler sees this:

For i=1 to 100

 Temp% = i + 1

Next


Pretty simple stuff (given a overly simple example)...but great for speeding up things and such...


Michael Reitzenstein(Posted 2003) [#13]
I've heard of others using it, to write for example a macro of say 200lines, which would then write out code of 1000+ lines for him.


That's me! :)

OK, here is a useful, real world example. This macro, when supplied with a type name and a field, will return the instance of that type with the smallest value in that field.

Type Test
	
	Field Yes
	Field No
	
End Type

t.Test = New Test
t\Yes = 5
t\No = 6

t.Test = New Test
t\Yes = 10
t\No = 2

t.Test = New Test
t\Yes = 50
t\No = 50

Type Test2
	
	Field Testing
	
End Type

t2.Test2 = New Test2
t2\Testing = 5

t2.Test2 = New Test2
t2\Testing = 6

t = SmallestFieldTestYes( )

Print "Smallest Field Test/Yes Values:"
Print "Yes - " + t\Yes
Print "No - " + t\No

t = SmallestFieldTestNo( )

Print "Smallest Field Test/No Values:"
Print "Yes - " + t\Yes
Print "No - " + t\No

t2 = SmallestFieldTest2Testing( )

Print "Smallest Field Test2/Testing Value:"
Print "Testing - " + t2\Testing

WaitKey( )

#DefMacro SmallestField
	
	#IfMacroArg 2	
	
		Function SmallestFieldArg1Arg2.Arg1( )
		
			Local SmallestInstance.Arg1
			Local InstanceLoop.Arg1
			
			For InstanceLoop = Each Arg1
			
				If SmallestInstance = Null
					
					SmallestInstance = InstanceLoop
									
				EndIf
				
				If InstanceLoop\Arg2 < SmallestInstance\Arg2
				
					SmallestInstance = InstanceLoop
					
				EndIf
				
			Next
			
			Return SmallestInstance
			
		End Function
		
	#EndIf
	
#EndDefMacro

#Macro SmallestField, Test, Yes ;Generates SmallestFieldTestYes( )
#Macro SmallestField, Test, No ; Generates SmallestFieldTestNo( )
#Macro SmallestField, Test2, Testing ; Generates SmallestFieldTest2Testing( )


And there we have it. Three functions that sort specific types generated from a single macro of equal length that sorts generic types. Without the preprocessor, this would require three separately coded functions. This is only scratching the surface!

And what MSW says is definitely true - Macros are inlined. The C# version of my preprocessor doesn't support inlined functions (the one written in BlitzBasic did), so if you really need some speed (without even doing a jump as with goto!) macros can be very useful.


LineOf7s(Posted 2003) [#14]
Am I right to think that based on the error I'm getting when trying to use it, "written in C#" means it needs the .NET framework to use?


Koriolis(Posted 2003) [#15]
Right.


LineOf7s(Posted 2003) [#16]
Bummer.


@rtur(Posted 2003) [#17]
I've got installed framework but preprocessor does not working. Why it can be?
PS:
Protean demo that uses framework works fine for me...


Michael Reitzenstein(Posted 2003) [#18]
Uh... I don't know!


Bot Builder(Posted 2003) [#19]
it says "The application failed to initialize properly (0xc0000135). Click ok to terminate the application" :( I've never tried runing you preprocessor before. I Believe I did it right and followed the manual instructions.


Michael Reitzenstein(Posted 2003) [#20]
Do you have the .Net framework?


Bot Builder(Posted 2003) [#21]
mmm. not that I know of. How do I check? and if I don't have it, where can I get it? Heard it's a pretty big dl... oh well. I would like to have a good blitz preprocessor.

(edit)
nevermind just did a google search and found the microsoft website.