One of the most annoying thing while using BlitzMax NG is the NEED to convert everything in a SUPERSTRICT version (due to the way the compiler works!)
Of course, after so many years using BlitzMax, I’m already used to write in ‘superstrict’ mode.
But quite ALL the CODE EXAMPLE are written in plain mode, just few in Strict mode, and very very few in SuperStrict mode.
So another brilliant idea (maybe someone else found already a solution to this and I’m wasting my time… I don’t know :D!)
SSStrictor: the super-strict source code convertor (good as a name of a wrestler!)
Of course it is just a test, written in few minutes.
What it does exactly?
It reads a file (I’m using the AUDIO examples source code) and try to convert it in a superstrict version
This is the original AllocChannel.bmx source code
'AllocChannel.bmx timer=createtimer(20) sound=LoadSound ("shoot.wav") channel=AllocChannel() for i=1 to 20 waittimer timer playsound sound,channel next
This is the result
'AllocChannel.bmx Local timer:TTimer=createtimer(20) Local sound:TSound=LoadSound("shoot.wav") Local channel:TChannel=AllocChannel() For Local i:Int=1 to 20 waittimer timer playsound sound,channel next
Of course there are so many presumptions (like in the For.. definition, just Int at the moment) and no control in case of nested function, Local conflict etc
But, considering that code examples are ‘basic’ this should be quite enough to make an easy conversion, to test and correct then manually.
At the moment I need to create a dictionary of Commands and return type, adding manually any possible commands (like AllocChannel, CueSound, LoadSound etc)
A smart version should read from
C:\BlitzMax150\docs\html\Modules\commands.txt
all the definitions required… and automatically build the dictionary.
It doesn’t understand ‘user function’ (in this version) or type-parameter.
This is the source code (if you want to test it!)
Enjoy
Rem Stricter read a bmx source code and trasform it in a superstrict version v.1 05-oct-2017 Test file: AllocChannel.bmx End Rem SuperStrict Local file$="C:\BlitzMax150\mod\brl.mod\audio.mod\doc\AllocChannel.bmx" 'Local file$="C:\BlitzMax150\mod\brl.mod\audio.mod\doc\CueSound.bmx" Local source$ Local newfile$ source=LoadText(file) Print "------------------------------------" Print "Original" Print "------------------------------------" Print source Global map_var:Tmap=CreateMap() Global map_dictionary:Tmap=CreateMap() Dictionary() Type Tvar Field name$ Field rettype$ End Type Global NL$="~n" For Local line$=EachIn source.split("~n") If line.startswith("'") newfile=newfile+line+NL;line="" If line.toupper().startswith("LOCAL ") newfile=newfile+line+NL;line="" If line.toupper().startswith("GLOBAL ") newfile=newfile+line+NL;line="" If line.contains("=") newfile=Newfile+CheckLine(line);line="" If line<>"" newfile=newfile+line+NL Next Function CheckLine:String(linea$="") If linea="" Return -1 Local precode$="Local " Local p1:Int,p2:Int,com$,dict:Tdictionary Local resto$,forvar$,forpar$ Local c$[]=linea.split("=") c=c[..2] If c[0]="" Return -1 If c[1]="" Return -1 'check FOR.. If linea.toupper().startswith("FOR ") ' '(source) For X=1 to 10 '(dest ) For Local X:INT=1 to 10 'part 1: For X c=linea.split("=") c=c[..2] p1=c[0].find(" ") forvar=c[0][p1+1..] forpar=c[1] 'check Variabile type If forvar.contains(":")=False forvar=forvar+":Int" End If If c[0].toupper().contains(" LOCAL ")=False forvar="For Local "+forvar Return forvar+"="+forpar+NL Else Return linea+NL End If End If c[1]=c[1].Replace(" (","(") p1=c[1].find(":") p2=c[1].find("(") p1=Max(p1,p2) resto=c[1][p1..].Trim() If p1>-1 ' com=c[1][..p1] dict=Tdictionary.Exist(com) If dict ' Print " Esiste......" ' Print " Return Type: '"+dict.ReturnType+"'" Return precode+c[0]+dict.ReturnType+"="+com+resto+NL End If End If End Function Print "------------------------------------------" Print newfile Type Tdictionary Field functionName:String Field ReturnType:String Function Exist:Tdictionary(_cmd$) Return Tdictionary(MapValueForKey(map_dictionary,_cmd.toupper())) End Function Function Add:Tdictionary(_fn$,_rv$) If _fn="" Or _rv="" Return Null Local nn:Tdictionary=New Tdictionary nn.functionName=_fn nn.ReturnType=_rv MapInsert map_dictionary,_fn.toupper(),nn Return nn End Function End Type Rem sound=LoadSound ("shoot.wav") channel=AllocChannel() End Rem Function Dictionary:Int() Tdictionary.Add("CreateTimer",":TTimer") Tdictionary.Add("LoadSound",":TSound") Tdictionary.Add("AllocChannel",":TChannel") Tdictionary.Add("CueSound",":TChannel") Return 0 End Function