Author Topic: TI-OS BASIC For( Bug Fixed  (Read 25560 times)

0 Members and 1 Guest are viewing this topic.

Offline BrandonW

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 115
  • Rating: +38/-1
    • View Profile
TI-OS BASIC For( Bug Fixed
« on: May 26, 2010, 05:43:54 am »
I believe I've tracked down the bug with For( loops being very slow when the first line is a lone If block with a false condition and there's no ) or newline between the For( and the If.

It's complicated and hard to explain, but basically the code that handles the For( token assumes that you've put the ) on the end of the For( line, and so when it executes the For block, instead of jumping to the start of the line containing the If, it jumps to the If token itself.

Normally this isn't a problem, but it's important for the parser to handle the start of the line because it removes a byte from the operator stack that always gets pushed when beginning parsing of the line. Because an If block with a false condition will jump over the next line (including the newline), this never gets canceled out at the beginning of the loop, and so with every iteration you lose bytes of the operator stack. This in turn causes memory leaks and confuses the parser about what temporary variables should be cleaned up, and it's forced to near-constantly "garbage collect".

Or at least that's my theory.

In any case, the For( code shouldn't be making that stupid assumption, so I patched my OS to see if I could fix it, and it appears successful. I uploaded it to http://brandonw.net/crap/84P_OS2.41_BASICFixed.8xu if anyone wants to try it.

So we could be happy with this, or we could write an oncalc patch that does this in an OS version-independent way, or we could just live with the fact that you need a ).

Thoughts?

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: TI-OS BASIC For( Bug Fixed
« Reply #1 on: May 26, 2010, 07:59:03 am »
Definitely not a full, patched OS. An oncalc, version-independent patch would be best, IMO.
Of course, if you don't feel like patching it, I think it wouldn't be too hard to just use )s. When I do program in BASIC, I avoid that type of For( loop anyway, or just use a ) for that reason.
But I'm not the only person here, so I wonder what others think should be done.
(Also: finally, a reason to use the OS-revalidator!)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: TI-OS BASIC For( Bug Fixed
« Reply #2 on: May 26, 2010, 08:03:39 am »
That's cool!  Has TI been email and told they need to fix this glitch and how to fix it?  It's cool that it's fixed.  Great job! :D

Offline BrandonW

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 115
  • Rating: +38/-1
    • View Profile
Re: TI-OS BASIC For( Bug Fixed
« Reply #3 on: May 26, 2010, 09:55:17 am »
No, I'm still working on how to even explain this. I managed to fix it, but I'm not 100% sure it's the right way, and if you're e-mailing TI to tell them they have a bug deep in their parser code, you want to make sure you're correct and very explicit.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: TI-OS BASIC For( Bug Fixed
« Reply #4 on: May 26, 2010, 09:57:32 am »
Pretty cool that you were able to track down such an old know bug. :D Nice work! I wouldn't mind a patch, because I tend to forget these oddities sometimes.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-OS BASIC For( Bug Fixed
« Reply #5 on: May 26, 2010, 12:41:29 pm »
Wow nice, I wish I could try it but I do not have a 84+. I hope an on-calc patch that works on most recent TI-83 Plus and TI-84 Plus OSes can be done. Just make sure there won't be conflicts with any other patch you have, though (such as the xLIB fix for 2.53MP and 2.54MP)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: TI-OS BASIC For( Bug Fixed
« Reply #6 on: May 26, 2010, 02:43:24 pm »
What exactly is meant by an independent program to do it instead of a patch? Also, great work :) Glad to know this can be fixed now (especially for people who need to spare every byte possible when creating a program). Good luck with figuring out how to explain this to TI.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-OS BASIC For( Bug Fixed
« Reply #7 on: May 26, 2010, 02:54:53 pm »
On the TI-Nspire, to fix xLIB issues with OS 2.54MP, you need to run a small 8xp program using the Asm() command. The fix remains until the Nspire is rebooted (keypad/battery removed or keypad swapped)

Not sure about non-Nspire, though.

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: TI-OS BASIC For( Bug Fixed
« Reply #8 on: May 26, 2010, 03:23:52 pm »
Wow, I was curious to know why the heck that bug existed.
You are continuing the "fixing bugs for them". :P

Nowadays many experienced TI-BASIC programmers know that they should put the closing ) in loops that use If's. And it is well documented in TI|BD. So now many of us "live with it". If someone has interest to find a patch, he would almost certainly see first how to solve the bug.

I also prefer an oncalc patcher if possible. Sending a full patched OS for just one bug is a little exaggerated.
Hobbing in calculator projects.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-OS BASIC For( Bug Fixed
« Reply #9 on: May 26, 2010, 03:34:16 pm »
Yeah the issue is that a lot of BASIC coders will get told to not close parhentesises, but not about the For loop issue, meaning they'll forget that part. Such patch would help a lot

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: TI-OS BASIC For( Bug Fixed
« Reply #10 on: May 26, 2010, 03:38:25 pm »
Ah ok, I gotcha. Thanks. Ya, I think a program would be easier.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-OS BASIC For( Bug Fixed
« Reply #11 on: May 26, 2010, 04:09:35 pm »
That said, later, if BrandonW managed to find a way to make Mathprint as fast as on the 73, find a way to fix the inverted text issues some BASIC games has and the potential bugs 2.53 MP got, he could maybe provide an OS patch including every fixes he managed to apply to his OS copy.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: TI-OS BASIC For( Bug Fixed
« Reply #12 on: May 26, 2010, 04:20:13 pm »
Ya, a patch like that would be nice. What is the inverted text issue?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI-OS BASIC For( Bug Fixed
« Reply #13 on: May 26, 2010, 04:32:27 pm »
If you enable the inverted text flag with an ASM prog or APP like xLIB, which displays white text on black background, doing DispGraph:Disp inverted the entire homescreen content. However, in OS 2.53MP this fails in most cases.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: TI-OS BASIC For( Bug Fixed
« Reply #14 on: May 26, 2010, 04:39:24 pm »
Oh ok, I thought you meant like something without assembly help haha. I get what you mean though.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)