richpl / PyBasic

Simple interactive BASIC interpreter written in Python
GNU General Public License v3.0
170 stars 46 forks source link

Two possible bugs #21

Closed RetiredWizard closed 3 years ago

RetiredWizard commented 3 years ago

Hello,

Great project, thank you so much! I've ported your interpreter to micropython and included it in my PyDOS release https://github.com/RetiredWizard/PyDOS.

During the port I ran across a couple issues that I believe would affect your cPython version as well.

The first one was that numbers at the end of variable names seemed to cause a problem.

The second one was that there seemed to be a problem with loop variables caused when a for loop was exited using a goto statement and then the loop was reinitiated.

I tweaked my ported version to resolve the first issue and deal with the second issue although I don't think my solution to loop problem is complete.

Thanks again!

RetiredWizard commented 3 years ago

Well make that one possible bug, the numbered variable issue was obviously something I introduced during the port, I just ran your code on my PC and numbered variables work just fine.

richpl commented 3 years ago

Thanks for the feedback! I was considering whether to port to MicroPython in order to develop my own retro style computer on a microcontroller platform. I could have run PyBasic as it is on, say a Raspberry Pi, but it seems overkill to have a whole Linux operating system underlying a retro, interpreter based OS. You've beaten me to it and so I've given PyDOS a star.

Hmmm. Regarding the loop bug, it isn't something I've thought about. I guess I felt jumping out of a loop was possibly a bad idea anyway, but then again BASIC doesn't generally have the same concept of a while loop and "break" statement, so you need to achieve the same effect somehow. I can imagine my implementation would behave unpredictably. I'll take a look at your solution and will have a think about it.

RetiredWizard commented 3 years ago

My micro python port was severely memory limited so I made another modification to run the Basic code in place from flash, rather than load it into memory. I'm really happy with how the modification has worked out and can now run much larger programs. I also added some logic which allows the same python code to run in cPython on a PC or in micro python on a microcontroller. I'm afraid the structure of my modification isn't great, I realized late in the process that my background in traditional programming led me to passing in and out file handles and flags when I probably should have been using class variables, perhaps if I decide on some more changes I'll try to straighten that out.

Thanks again for posting your interpreter, I've been having a blast with it :-)

richpl commented 3 years ago

Apologies for not accepting your PRs yet @RetiredWizard. Having multiple contributors to the code is not something I've dealt with simultaneously before. It's getting complicated and making commits a bit tricky! I'm hoping it won't be too annoying for you to refactor and resubmit but I'll understand if it's too much hassle