Advertisement
Guest User

BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 03 - Parsing DIM statements

a guest
Feb 28th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 03 - Parsing DIM statements
  2. https://www.youtube.com/watch?v=5u0BI_Biokg&ab_channel=PlayBasic
  3. https://www.underwaredesign.com/forums/index.php?topic=4625.msg30567#msg30567
  4. ---------------------------------------------------------------------------------------------
  5.  
  6. hello welcome back we're outside again
  7.  
  8. so it's a bit noisy um
  9.  
  10. it's a beautiful day so i'm outside
  11.  
  12. that's why i'm recording outside as well
  13.  
  14. just easier for me
  15.  
  16. where are we with blitz basic to play
  17.  
  18. basic well we've been working on the
  19.  
  20. dimensioning support here in magpie in
  21.  
  22. the background
  23.  
  24. so i'll give it a
  25.  
  26. run debug mode
  27.  
  28. so
  29.  
  30. information is a bit different than i
  31.  
  32. was before but not much all that
  33.  
  34. interesting
  35.  
  36. this is our resulting code
  37.  
  38. so i'll sort of pick through this
  39.  
  40. well actually i'll pick through the
  41.  
  42. original code and we'll go through what
  43.  
  44. the converter supports
  45.  
  46. but that actually does compile now in
  47.  
  48. play basic
  49.  
  50. here's the original blitz code
  51.  
  52. so in blitz
  53.  
  54. our main changes are going to be we
  55.  
  56. the field
  57.  
  58. keyword here is obsolete so we don't
  59.  
  60. need that
  61.  
  62. and we
  63.  
  64. we have an n-type keyword rather than
  65.  
  66. end-end type keywords so those changes
  67.  
  68. have been made for us
  69.  
  70. the dimension statements are basically
  71.  
  72. the same there's nothing different about
  73.  
  74. those
  75.  
  76. well there is but we'll get to that in a
  77.  
  78. second
  79.  
  80. in blitz we also have a thing
  81.  
  82. an integer
  83.  
  84. postfix
  85.  
  86. which is the percent symbol
  87.  
  88. so in pv we don't have that so we have
  89.  
  90. to remove those
  91.  
  92. which is what we do in our translation
  93.  
  94. floats the same strings the same now
  95.  
  96. blitz has a support for stacked arrays
  97.  
  98. and i thought i added this
  99.  
  100. well
  101.  
  102. this came up during the amos conversion
  103.  
  104. stuff because amos supports the same
  105.  
  106. thing
  107.  
  108. but haven't and you can also do it with
  109.  
  110. typed arrays notice the different syntax
  111.  
  112. here
  113.  
  114. this inverted syntax
  115.  
  116. and here i'm just testing whether you
  117.  
  118. can have complex expressions inside the
  119.  
  120. dimension statement
  121.  
  122. for the
  123.  
  124. field size
  125.  
  126. if i just grab these couple lines here
  127.  
  128. which the ones we want to look at really
  129.  
  130. the rest of it's all pretty much for
  131.  
  132. matches
  133.  
  134. we go to the translated
  135.  
  136. one which is
  137.  
  138. this is the one yeah
  139.  
  140. so you can see what the converter's done
  141.  
  142. is it's looked at this
  143.  
  144. first line i'll put the original lines
  145.  
  146. beside them
  147.  
  148. so this was the input line sorry
  149.  
  150. this was the original input line
  151.  
  152. this one was the
  153.  
  154. other original input line
  155.  
  156. the one at the bottom there was the
  157.  
  158. other one as well
  159.  
  160. let's comment them out
  161.  
  162. so
  163.  
  164. in the first case we've got a stack
  165.  
  166. dimension
  167.  
  168. a stacked array dimension we've got uh
  169.  
  170. array one integer type and then we've
  171.  
  172. got a second dimension on the same line
  173.  
  174. to do that in pb we've got to substitute
  175.  
  176. this comma with a dim colon
  177.  
  178. so we keep the things on the same line
  179.  
  180. but we're inserting the statement um
  181.  
  182. to allow us to phrase this and act the
  183.  
  184. same
  185.  
  186. when we have a type we've got a
  187.  
  188. rearranged expression
  189.  
  190. so
  191.  
  192. when we find this this declaration here
  193.  
  194. we're going okay array three all right
  195.  
  196. cool
  197.  
  198. as of of this type
  199.  
  200. and we've got these brackets here so we
  201.  
  202. need to rearrange these back into here
  203.  
  204. and replace our dot syntax with as
  205.  
  206. which is what pv accepts and because
  207.  
  208. they can be stacked we need to do the
  209.  
  210. same thing through here
  211.  
  212. and the last one has an expression
  213.  
  214. inside those things to show that we can
  215.  
  216. we can unlink these tokens
  217.  
  218. from in here
  219.  
  220. more sort of complicate sorry a more
  221.  
  222. complex expression
  223.  
  224. and move them back without damaging it
  225.  
  226. i hope not anyway um
  227.  
  228. let's try and run this one here and
  229.  
  230. debug
  231.  
  232. without getting output because there's
  233.  
  234. just nothing it's doing but we can see
  235.  
  236. what a race we have an array one which
  237.  
  238. is our integer array array two is fine
  239.  
  240. typed array
  241.  
  242. [Music]
  243.  
  244. yeah
  245.  
  246. we're getting now our arcade types
  247.  
  248. because the array has been declared but
  249.  
  250. the individual types within it are not
  251.  
  252. created until we actually
  253.  
  254. do a new of them
  255.  
  256. our flight array looks good and our
  257.  
  258. integer arrays look good as well so it's
  259.  
  260. all
  261.  
  262. working
  263.  
  264. so i've been doing this smaller subset
  265.  
  266. testing
  267.  
  268. to these larger ones i haven't tried the
  269.  
  270. bigger source code for for a few days
  271.  
  272. actually
  273.  
  274. this won't produce anything that's
  275.  
  276. useful like at the moment
  277.  
  278. our converter is catching these
  279.  
  280. dimension statements and phrasing out
  281.  
  282. what arrays we need
  283.  
  284. are within them but it's not storing
  285.  
  286. this in in a list
  287.  
  288. we need that because as we go through
  289.  
  290. the code
  291.  
  292. like these are the declarations but when
  293.  
  294. something's been used like we go print
  295.  
  296. was it a rate one or something uh l5
  297.  
  298. position five or something
  299.  
  300. plus uh i think it was
  301.  
  302. i used i in front of
  303.  
  304. 10 let's say let's say
  305.  
  306. um
  307.  
  308. at the moment when it's phrasing through
  309.  
  310. and it'll pick up these statements but
  311.  
  312. won't understand what these keywords are
  313.  
  314. so
  315.  
  316. if it's an integer array like that
  317.  
  318. no dramas it'll get spelled out the same
  319.  
  320. way it went in
  321.  
  322. because there's no translation required
  323.  
  324. but if that's obviously uh
  325.  
  326. one of these float arrays for example
  327.  
  328. or the inter ray up here that was
  329.  
  330. declared with the
  331.  
  332. oh it's been removed in this example
  333.  
  334. with a symbol added to it
  335.  
  336. and that keeps popping up later on in
  337.  
  338. the code we'd have to remove those
  339.  
  340. during our translation so we have to
  341.  
  342. skim through find this keyword and go
  343.  
  344. all right what's this word mean
  345.  
  346. look it up within our current scope
  347.  
  348. which is what we also need to do is keep
  349.  
  350. track of
  351.  
  352. are these arrays global are they local
  353.  
  354. so we sort of have to do that
  355.  
  356. and once we do that we should be able to
  357.  
  358. get a pretty good
  359.  
  360. you know not a great translation well
  361.  
  362. i think i think pretty good is about the
  363.  
  364. best we hope for
  365.  
  366. it'll be better than doing replacements
  367.  
  368. but it won't
  369.  
  370. give you
  371.  
  372. full out working code
  373.  
  374. out of the blocks
  375.  
  376. you'll find some expressions that white
  377.  
  378. that it won't understand or
  379.  
  380. or that i've not considered
  381.  
  382. it just has no clue about what to do
  383.  
  384. with them
  385.  
  386. you know to make this line here pb
  387.  
  388. compatible would have to remove these
  389.  
  390. percentage symbols
  391.  
  392. uh
  393.  
  394. or as we're saying before if if you go
  395.  
  396. dim you know
  397.  
  398. my strings
  399.  
  400. maybe a size 100 of them or whatever
  401.  
  402. in blitz you you don't have to use that
  403.  
  404. the perfect symbol so it's not baked
  405.  
  406. into the name
  407.  
  408. with pva it kind of is baked into the
  409.  
  410. name so we
  411.  
  412. it's okay to do stuff like this
  413.  
  414. in blitz
  415.  
  416. you know run through and grab
  417.  
  418. print out all the strings or whatever
  419.  
  420. you want to do
  421.  
  422. when we look through this to convert it
  423.  
  424. we'd have to
  425.  
  426. look for my string
  427.  
  428. check is my string declared within our
  429.  
  430. current scope if it is
  431.  
  432. then we look at the symbol
  433.  
  434. following that and we go okay
  435.  
  436. this was originally declared as a string
  437.  
  438. array and we're not using the string so
  439.  
  440. we better output this to make it
  441.  
  442. compatible with pba otherwise people
  443.  
  444. would just assume that that was
  445.  
  446. and we'll just assume this is an integer
  447.  
  448. version of that array
  449.  
  450. which is going to cause problems
  451.  
  452. but hopefully if we can catch
  453.  
  454. that kind of stuff
  455.  
  456. catch a lot a lot of the tight film
  457.  
  458. you know the um backslash stuff and
  459.  
  460. types won't work out of the box but
  461.  
  462. we'll get
  463.  
  464. a lot of the clunky syntax stuff work
  465.  
  466. and hopefully you get these variable and
  467.  
  468. array problems solved and that'll
  469.  
  470. actually go a long way
  471.  
  472. to you having a working program
  473.  
  474. when i started this the other day i
  475.  
  476. thought well if we get to a point where
  477.  
  478. it can solve you know
  479.  
  480. 50 of your problems
  481.  
  482. that's pretty good because on these
  483.  
  484. large co-bases that's hours and hours of
  485.  
  486. work
  487.  
  488. and for some programs if they don't use
  489.  
  490. things outside of what it what
  491.  
  492. understands how to solve that'll be fine
  493.  
  494. they'll you better pace them in convert
  495.  
  496. them and
  497.  
  498. get something that's probably 90
  499.  
  500. ready to run
  501.  
  502. um
  503.  
  504. that's what we are at the moment anyway
  505.  
  506. we'll just give it a go that uh the
  507.  
  508. longest source code
  509.  
  510. to see how long it takes should be a lot
  511.  
  512. slower now
  513.  
  514. should be um
  515.  
  516. this is the gy code
  517.  
  518. just wrote
  519.  
  520. not in debug but right straight out
  521.  
  522. well a fair bit slower so phrase times 3
  523.  
  524. 325 and the convert times about half a
  525.  
  526. second so we're almost at a second to do
  527.  
  528. a pretty full-on
  529.  
  530. uh
  531.  
  532. we're not fully compiling the code
  533.  
  534. obviously we're kind of picking through
  535.  
  536. and looking for things that we're
  537.  
  538. interested in and then when we find them
  539.  
  540. we're replacing those things
  541.  
  542. all right again to see if we're under
  543.  
  544. stress doing that
  545.  
  546. yeah i
  547.  
  548. thought as much
  549.  
  550. so about half a second to to load it and
  551.  
  552. tokenize it and output it
  553.  
  554. that's pretty acceptable for a 9000 line
  555.  
  556. 9000 lines of code
  557.  
  558. 87 000 tokens to run through
  559.  
  560. in just
  561.  
  562. pv
  563.  
  564. now that's not going to produce working
  565.  
  566. code
  567.  
  568. it will take ages we'll try and debug
  569.  
  570. mode but i've got a lot of debug dumps
  571.  
  572. at the moment so we might get stuck here
  573.  
  574. for a little while
  575.  
  576. um
  577.  
  578. so it took a lot longer because we've
  579.  
  580. got a lot more stuff being spat out to
  581.  
  582. the console
  583.  
  584. uh every time it finds a variable what
  585.  
  586. it thinks is a variable it's going to
  587.  
  588. speed up this little message
  589.  
  590. because also doing
  591.  
  592. it's a very preliminary version of
  593.  
  594. detecting variables but it's not
  595.  
  596. remembering them at the moment
  597.  
  598. so just look at the start of that
  599.  
  600. function we'll just see if we we've done
  601.  
  602. some
  603.  
  604. replacements of that
  605.  
  606. well there you go
  607.  
  608. so we've actually made a working
  609.  
  610. replacement this is the menus gy that
  611.  
  612. was
  613.  
  614. uh it was in
  615.  
  616. now we've converted something that's
  617.  
  618. compiles and will run straight out of
  619.  
  620. the box in play basic
  621.  
  622. those five lines there have been
  623.  
  624. converted perfectly
  625.  
  626. these lines here won't be that's our
  627.  
  628. next port of call with arrays is to
  629.  
  630. catch these
  631.  
  632. situations here and then
  633.  
  634. rearrange the expression suitably
  635.  
  636. [Music]
  637.  
  638. we might have to put warnings on some of
  639.  
  640. those there too
  641.  
  642. like if we know something's not gonna
  643.  
  644. not not being converted
  645.  
  646. uh correctly then we should warn you
  647.  
  648. know the end user that hey this line's
  649.  
  650. broken come and fix it
  651.  
  652. um
  653.  
  654. we've got some chicken before the egg
  655.  
  656. stuff here as well we've got
  657.  
  658. arrays with the typed been declared
  659.  
  660. before the types have been defined
  661.  
  662. you can do that in blitz you can't do
  663.  
  664. that in play basics that that code won't
  665.  
  666. build anyone
  667.  
  668. but syntactically we're closer
  669.  
  670. to something that's um
  671.  
  672. that will work
  673.  
  674. we haven't even started you know once we
  675.  
  676. get
  677.  
  678. and we get variables done means that
  679.  
  680. programs that just use arrays and
  681.  
  682. variables will will port
  683.  
  684. with a high degree of certainty
  685.  
  686. but we have to have you know emulations
  687.  
  688. of bullets functions so
  689.  
  690. this uh
  691.  
  692. well in our gy example
  693.  
  694. we've got this wrapping code where is
  695.  
  696. the code going there is
  697.  
  698. sorry
  699.  
  700. this thing called blitzwrapper which is
  701.  
  702. a list of just functions i'm emulating
  703.  
  704. uh in play basic code they do what blitz
  705.  
  706. does
  707.  
  708. sometimes they're just namesake wrappers
  709.  
  710. like that one there
  711.  
  712. we could substitute this for that and
  713.  
  714. life would go on straight away
  715.  
  716. these won't be so i know blitz has
  717.  
  718. different ideas about how images work
  719.  
  720. but for the most part we'll be able to
  721.  
  722. build a build a wrapper of these
  723.  
  724. commonplace functions and
  725.  
  726. commonplace
  727.  
  728. stuff will work straight out of the box
  729.  
  730. well
  731.  
  732. has a high degree of
  733.  
  734. possibility of working
  735.  
  736. it's the best we can hope for
  737.  
  738. all right thanks for listening to this
  739.  
  740. and thanks sorry for all the the car
  741.  
  742. noise in the background
  743.  
  744. uh i'll catch you next time bye
  745.  
  746.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement