Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 03 - Parsing DIM statements
- https://www.youtube.com/watch?v=5u0BI_Biokg&ab_channel=PlayBasic
- https://www.underwaredesign.com/forums/index.php?topic=4625.msg30567#msg30567
- ---------------------------------------------------------------------------------------------
- hello welcome back we're outside again
- so it's a bit noisy um
- it's a beautiful day so i'm outside
- that's why i'm recording outside as well
- just easier for me
- where are we with blitz basic to play
- basic well we've been working on the
- dimensioning support here in magpie in
- the background
- so i'll give it a
- run debug mode
- so
- information is a bit different than i
- was before but not much all that
- interesting
- this is our resulting code
- so i'll sort of pick through this
- well actually i'll pick through the
- original code and we'll go through what
- the converter supports
- but that actually does compile now in
- play basic
- here's the original blitz code
- so in blitz
- our main changes are going to be we
- the field
- keyword here is obsolete so we don't
- need that
- and we
- we have an n-type keyword rather than
- end-end type keywords so those changes
- have been made for us
- the dimension statements are basically
- the same there's nothing different about
- those
- well there is but we'll get to that in a
- second
- in blitz we also have a thing
- an integer
- postfix
- which is the percent symbol
- so in pv we don't have that so we have
- to remove those
- which is what we do in our translation
- floats the same strings the same now
- blitz has a support for stacked arrays
- and i thought i added this
- well
- this came up during the amos conversion
- stuff because amos supports the same
- thing
- but haven't and you can also do it with
- typed arrays notice the different syntax
- here
- this inverted syntax
- and here i'm just testing whether you
- can have complex expressions inside the
- dimension statement
- for the
- field size
- if i just grab these couple lines here
- which the ones we want to look at really
- the rest of it's all pretty much for
- matches
- we go to the translated
- one which is
- this is the one yeah
- so you can see what the converter's done
- is it's looked at this
- first line i'll put the original lines
- beside them
- so this was the input line sorry
- this was the original input line
- this one was the
- other original input line
- the one at the bottom there was the
- other one as well
- let's comment them out
- so
- in the first case we've got a stack
- dimension
- a stacked array dimension we've got uh
- array one integer type and then we've
- got a second dimension on the same line
- to do that in pb we've got to substitute
- this comma with a dim colon
- so we keep the things on the same line
- but we're inserting the statement um
- to allow us to phrase this and act the
- same
- when we have a type we've got a
- rearranged expression
- so
- when we find this this declaration here
- we're going okay array three all right
- cool
- as of of this type
- and we've got these brackets here so we
- need to rearrange these back into here
- and replace our dot syntax with as
- which is what pv accepts and because
- they can be stacked we need to do the
- same thing through here
- and the last one has an expression
- inside those things to show that we can
- we can unlink these tokens
- from in here
- more sort of complicate sorry a more
- complex expression
- and move them back without damaging it
- i hope not anyway um
- let's try and run this one here and
- debug
- without getting output because there's
- just nothing it's doing but we can see
- what a race we have an array one which
- is our integer array array two is fine
- typed array
- [Music]
- yeah
- we're getting now our arcade types
- because the array has been declared but
- the individual types within it are not
- created until we actually
- do a new of them
- our flight array looks good and our
- integer arrays look good as well so it's
- all
- working
- so i've been doing this smaller subset
- testing
- to these larger ones i haven't tried the
- bigger source code for for a few days
- actually
- this won't produce anything that's
- useful like at the moment
- our converter is catching these
- dimension statements and phrasing out
- what arrays we need
- are within them but it's not storing
- this in in a list
- we need that because as we go through
- the code
- like these are the declarations but when
- something's been used like we go print
- was it a rate one or something uh l5
- position five or something
- plus uh i think it was
- i used i in front of
- 10 let's say let's say
- um
- at the moment when it's phrasing through
- and it'll pick up these statements but
- won't understand what these keywords are
- so
- if it's an integer array like that
- no dramas it'll get spelled out the same
- way it went in
- because there's no translation required
- but if that's obviously uh
- one of these float arrays for example
- or the inter ray up here that was
- declared with the
- oh it's been removed in this example
- with a symbol added to it
- and that keeps popping up later on in
- the code we'd have to remove those
- during our translation so we have to
- skim through find this keyword and go
- all right what's this word mean
- look it up within our current scope
- which is what we also need to do is keep
- track of
- are these arrays global are they local
- so we sort of have to do that
- and once we do that we should be able to
- get a pretty good
- you know not a great translation well
- i think i think pretty good is about the
- best we hope for
- it'll be better than doing replacements
- but it won't
- give you
- full out working code
- out of the blocks
- you'll find some expressions that white
- that it won't understand or
- or that i've not considered
- it just has no clue about what to do
- with them
- you know to make this line here pb
- compatible would have to remove these
- percentage symbols
- uh
- or as we're saying before if if you go
- dim you know
- my strings
- maybe a size 100 of them or whatever
- in blitz you you don't have to use that
- the perfect symbol so it's not baked
- into the name
- with pva it kind of is baked into the
- name so we
- it's okay to do stuff like this
- in blitz
- you know run through and grab
- print out all the strings or whatever
- you want to do
- when we look through this to convert it
- we'd have to
- look for my string
- check is my string declared within our
- current scope if it is
- then we look at the symbol
- following that and we go okay
- this was originally declared as a string
- array and we're not using the string so
- we better output this to make it
- compatible with pba otherwise people
- would just assume that that was
- and we'll just assume this is an integer
- version of that array
- which is going to cause problems
- but hopefully if we can catch
- that kind of stuff
- catch a lot a lot of the tight film
- you know the um backslash stuff and
- types won't work out of the box but
- we'll get
- a lot of the clunky syntax stuff work
- and hopefully you get these variable and
- array problems solved and that'll
- actually go a long way
- to you having a working program
- when i started this the other day i
- thought well if we get to a point where
- it can solve you know
- 50 of your problems
- that's pretty good because on these
- large co-bases that's hours and hours of
- work
- and for some programs if they don't use
- things outside of what it what
- understands how to solve that'll be fine
- they'll you better pace them in convert
- them and
- get something that's probably 90
- ready to run
- um
- that's what we are at the moment anyway
- we'll just give it a go that uh the
- longest source code
- to see how long it takes should be a lot
- slower now
- should be um
- this is the gy code
- just wrote
- not in debug but right straight out
- well a fair bit slower so phrase times 3
- 325 and the convert times about half a
- second so we're almost at a second to do
- a pretty full-on
- uh
- we're not fully compiling the code
- obviously we're kind of picking through
- and looking for things that we're
- interested in and then when we find them
- we're replacing those things
- all right again to see if we're under
- stress doing that
- yeah i
- thought as much
- so about half a second to to load it and
- tokenize it and output it
- that's pretty acceptable for a 9000 line
- 9000 lines of code
- 87 000 tokens to run through
- in just
- pv
- now that's not going to produce working
- code
- it will take ages we'll try and debug
- mode but i've got a lot of debug dumps
- at the moment so we might get stuck here
- for a little while
- um
- so it took a lot longer because we've
- got a lot more stuff being spat out to
- the console
- uh every time it finds a variable what
- it thinks is a variable it's going to
- speed up this little message
- because also doing
- it's a very preliminary version of
- detecting variables but it's not
- remembering them at the moment
- so just look at the start of that
- function we'll just see if we we've done
- some
- replacements of that
- well there you go
- so we've actually made a working
- replacement this is the menus gy that
- was
- uh it was in
- now we've converted something that's
- compiles and will run straight out of
- the box in play basic
- those five lines there have been
- converted perfectly
- these lines here won't be that's our
- next port of call with arrays is to
- catch these
- situations here and then
- rearrange the expression suitably
- [Music]
- we might have to put warnings on some of
- those there too
- like if we know something's not gonna
- not not being converted
- uh correctly then we should warn you
- know the end user that hey this line's
- broken come and fix it
- um
- we've got some chicken before the egg
- stuff here as well we've got
- arrays with the typed been declared
- before the types have been defined
- you can do that in blitz you can't do
- that in play basics that that code won't
- build anyone
- but syntactically we're closer
- to something that's um
- that will work
- we haven't even started you know once we
- get
- and we get variables done means that
- programs that just use arrays and
- variables will will port
- with a high degree of certainty
- but we have to have you know emulations
- of bullets functions so
- this uh
- well in our gy example
- we've got this wrapping code where is
- the code going there is
- sorry
- this thing called blitzwrapper which is
- a list of just functions i'm emulating
- uh in play basic code they do what blitz
- does
- sometimes they're just namesake wrappers
- like that one there
- we could substitute this for that and
- life would go on straight away
- these won't be so i know blitz has
- different ideas about how images work
- but for the most part we'll be able to
- build a build a wrapper of these
- commonplace functions and
- commonplace
- stuff will work straight out of the box
- well
- has a high degree of
- possibility of working
- it's the best we can hope for
- all right thanks for listening to this
- and thanks sorry for all the the car
- noise in the background
- uh i'll catch you next time bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement