PlayBASIC V1.65C3 - Beta 38/39 - Testing replacement LinkDLL block parser

  My Goals to finalize PlayBASIC V1.65 edition is to round it out..  Smoothing whatever edges that were left behind during the Compiler->VM translation progress that was made now years ago.. Too many years ago ! 

  This adventure (some would call it a nightmare) has seen me work through the built in libraries from obvious changes / nice to have things... like resorting Sprites / Images back to it's original specification, fleshing out ink mode support even more for graphical commands..  Through to replacing the scene sorting / the world partitioning /  replacing the arena allocation libraries used mostly in the Maps libraries..  Stuff I could have left, but felt those components needed some attention.  In fact all the legacy stuff needs a good shake down.  But I only have so much time.. 

  The command sets help the runtime abilities of PlayBASIC, but the compiler is how uses communicate intend through the command sets.  So making the language syntax smoother / more consistent is something I'd always slated as a PlayBASIC 2 thing..  But really those ideas work in either version.   

  Now I'm sure we all have a list of annoying syntactical things in the legacy editions of PlayBASIC, but the ones that still bother me are the one I would run into while writing things.

  For example, while writing the PolyWOLF demo(s) I actually ran into some of the recent syntax changes..  What have loving to be able to read the Handle from an array into and integer directly,  still change use them within expressions, but just being able to read the handle saves having to write helper functions to gain access to it.  Then ran into the MakeArray syntax only supported the legacy short hand..  For counter variables had to be declared while in explicit modes.  Etc.. 

  None of those are earth shattering by themselves, but they do create little frictions when writing code..

  Another area that was missing some this syntactical consistency was the LinkDLL->EndLInkDLL blocks.  Luckily a lot of this compiler / parser segmentation occurred during the initial transition from PlayBASIC V1.64 ->V1.65.  Since the compiler and Vm had be made to work more inline with each other.  So this when the compiler encounter a keyword, it passes control to a parser function that decodes the block..

  So while looking over these blocks, I kept wondering if any of them could be replacement and and LinkDLL blocks jumped out at me initially.. Namely the parameter syntax for those blocks expects the same short hand as old statements would use.  So i wrote a external replacement for those linkdll parser just to see how ugly stepping through all the existing and new cases would be,  yeah... it's a little more code than the classic approach, but more of focused.

    The main benefits from replacing such blocks are two fold. 

    1) Syntax is more inline with other declaration statements

    2) Can supports Pointers (User Defined Types) directly


    Just allowing a pointer types through the declarations alone makes like easier for library authors. 


    This is just example block the parser can decode,

PlayBASIC Code:
LinkDll "Some.dll"

    This() alias "cool"
        
    zTest1() alias "cool" 
    zTest2() alias "cool" as integer

    zTest100(a=100) alias "cool" 

    zTest1() alias "cool" 
    zTest2() alias "cool" as integer
    zTest3() alias "cool" as float
    zTest4() alias "cool" as string
    zTest5(A remstart hello world remend ) alias "cool" as string

    zTest6(ptr as byte) alias "cool"
    zTest7(ptr as word) alias "cool"
    zTest8(ptr as integer) alias "cool"
    zTest9(ptr as float) alias "cool"
    zTest10(ptr as string) alias "cool"
    zTest11(ptr as pointer) alias "cool" as string
    zTest12(ptr as byte pointer) alias "cool"
    zTest13(ptr as word pointer) alias "cool"
    zTest14(ptr as integer pointer) alias "cool"
    zTest15(ptr as float pointer) alias "cool"

        zTest200(a=100, b#= 123.456, c$="Hello World") alias "cool" 
    ;    zTest300(myarray()) alias "cool" 

    rem yeah

    /*  this is a comment */

    zTest20(a,b#,    c$    ,D as byte,E as word,P as pointer,PB as byte pointer,PW as word pointer, PI as integer pointer, PF as float pointer ) alias "cool"

    zTest(MyInt,MyFloat#,MyString$, A as integer , B as float ,C as string) alias "cool"  rem yeah 

    xCreateLine3D(fromX#, fromY#, fromZ#, toX#, toY#, toZ#, red, green ) Alias "_xCreateLine3D@44" As Integer
    xLine3DOrigin(line3d, x#, y#, z#, isGlobal) Alias "_xLine3DOrigin@20"
    xLine3DAddNode(line3d, x#, y#, z#, isGlobal) Alias "_xLine3DAddNode@20"
    xLine3DUseZBuffer(line3d, state) Alias "_xLine3DUseZBuffer@8"
    xLine3DRed(line3d) Alias "_xLine3DRed@4" As Integer
EndLinkDLL
COMMANDS USED: LINKDLL | ALIAS | INTEGER | FLOAT | STRING | BYTE | WORD | POINTER | ENDLINKDLL |
   

   
  Output:

CODE:

LINKDLL:"Some.dll"
This() alias "cool"
zTest1() alias "cool"
zTest2() alias "cool" as Integer
zTest100(a as Integer = 100) alias "cool"
zTest1() alias "cool"
zTest2() alias "cool" as Integer
zTest3() alias "cool" as Float
zTest4() alias "cool" as string
zTest5(A as Integer) alias "cool" as string
zTest6(ptr as Byte) alias "cool"
zTest7(ptr as Word) alias "cool"
zTest8(ptr as Integer) alias "cool"
zTest9(ptr# as Float) alias "cool"
zTest10(ptr$ as string) alias "cool"
zTest11(ptr as Pointer) alias "cool" as string
zTest12(ptr as Byte Pointer) alias "cool"
zTest13(ptr as WORD Pointer) alias "cool"
zTest14(ptr as INTEGER Pointer) alias "cool"
zTest15(ptr as FLOAT Pointer) alias "cool"
zTest200(a as Integer = 100 , b# as Float = 123.456 , c$ as string = "Hello World" alias "cool"
zTest20(a as Integer , b# as Float , c$ as string , D as Byte , E as Word , P as Pointer , PB as Byte Pointer , PW as WORD Pointer , PI as INTEGER Pointer , PF as FLOAT Pointer) alias "cool"
zTest(MyInt as Integer , MyFloat# as Float , MyString$ as string , A as Integer , B# as Float , C$ as string) alias "cool"
xCreateLine3D(fromX# as Float , fromY# as Float , fromZ# as Float , toX# as Float , toY# as Float , toZ# as Float , red as Integer , green as Integer) alias "_xCreateLine3D@44" as Integer
xLine3DOrigin(line3d as Integer , x# as Float , y# as Float , z# as Float , isGlobal as Integer) alias "_xLine3DOrigin@20"
xLine3DAddNode(line3d as Integer , x# as Float , y# as Float , z# as Float , isGlobal as Integer) alias "_xLine3DAddNode@20"
xLine3DUseZBuffer(line3d as Integer , state as Integer) alias "_xLine3DUseZBuffer@8"
xLine3DRed(line3d as Integer) alias "_xLine3DRed@4" as Integer
ENDLINKDLL



    The nice thing about the replacement is not only can it parse the existing code we can extend it without breaking it too badly..  I'll have to insert some of the original errors mind you... but I should be able to compare the new and old versions side by side..  Which is pretty handy..   

    Something I didn't notice before was the original LinkDLL parser had a way to embed the DLL into the program as PlayBASIC resource.  This is done by adding the "*" character in front of the initial DLL name. 

    Eg.

    LinkDLL "ExternalLIbrary.DLL"

    This would load it from disc externally.


    LinkDLL "*ExternalLIbrary.DLL"

    This version would pre-load the DLL into a resource in memory during compile time and then load the DLL from memory at runtime.


    Which is fine, but given the descriptive native of PlayBASIC, it's probably best add a keyword to make such declarations that little more obvious to the reader. 

    Something like

    LinkDLL "ExternalLIbrary.DLL" as resource

    LinkDLL "ExternalLIbrary.DLL" attach resource


    That sort of thing. 


    Mind you can just use the  #AddResource directive which would load the file into the PlayBASIC resource buffer.

PlayBASIC Code:
    #AddResource "ExternalLIbrary.DLL"
    LinkDLL "ExternalLIbrary.DLL" as resource

      etc etc

    EndLInkDLL
COMMANDS USED: LINKDLL | ENDLINKDLL |


    None of this matters when compiling and running from the PlayBASIC IDE though, the resource bundle is only built when exporting program into the final EXE..  (Retail Editions of PlayBASIC)