![]() |
Forum Index : Microcontroller and PC projects : PicoMite/MMBasic-core: bug with subroutine nesting level (LocalIndex)
![]() ![]() |
|||||
Author | Message | ||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
I was thinking Li Chen Wang's Palo Alto Tiny BASIC, which pre-dates the TRS-80 IIRC. :) I had a version in EPROM for the Nascom-1. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2442 |
hi peter, i think half the mmbasic users out there thought the same as you! i've tried tracking down the forum discussions, but not had much luck finding anything particularly useful or complete. there are just dribs and drabs, and a good deal of confusion. tom: i think peter is trying to ask the question: should the ON ERROR state follow down into a function? should the function count as ONE statement, or as a collection of n statements? how is one case (1) justified over the other (n)? i'd add to that, what about multi-line IF/THEN/ELSE's? btw, this is the ONE use i've ever made of ON ERROR: Dim ok(28) For I = 1 To 28 On error skip SetPin I, DOUT ok(I) = (MM.Errno=0) Next I Do For I = 1 To 28 If ok(I) Then Print I; Pin(I) = 1 Pause 500 Pin(I) = 0 End If Next I Loop this code was for checking the pins of an E-28 module were all functioning. it configures all pins that are capable of being used for DOUT, then proceeds to cycle through them continuously flashing a series of attached LEDs. my personal view is that ON ERROR should only really be used with the simplest of cases: On error skip [single inbuilt statement that may generate an error] ok = (MM.Errno=0) what if the rules for ON ERROR SKIP were simply changed to: 1. ON ERROR SKIP [n] will suppress errors for the next n inbuilt statements; 2. none of these statements may invoke a call to a user function or a user subroutine; 3. neither may there be any GOTO or conditional statements; 4. deviating from the above rules may produce unexpected results. while these requirements would be added to the user manual, no C source code changes should be needed to enforce them. with the exception that some of the complexity of handling ON ERROR may be removed from the interpreter at a future date if required. cheers, rob :-) Edited 2023-01-13 23:41 by robert.rozee |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi Rob, N commands. Incidentally it looks like the FUNCTION <name> line doesn't count towards N but END FUNCTION does, or vice-versa. Either way is fine. IMO the current (N commands) version is justified over the other because it is the currently implemented behaviour ![]() I haven't asked for a change in the designed/documented behaviour, just a fix for the bug in that behaviour - Thanks for adding it @matherp. Is that a hypothetical issue or do you have code for me to add to my unit-tests ? My opinion is that no changes (or additional documentation) regarding ON ERROR SKIP are required, it's not like anyone but me seems to use if for anything but the very simplest case. If you twisted my arm (and using the CMM2 manual as a reference) the sentence "ON ERROR SKIP will ignore an error in a number of commands ..." could be changed to "ON ERROR SKIP will ignore errors reported by a number of commands ..." but mostly the confusion reported by @matherp and @Mixtel90 seems to be a case of people not RTFM ![]() I suspect exception handling (of a kind) could be added to MMBasic, perhaps one day I will even find the time to look at it. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2442 |
this is a silly example, but demonstrates the point: Do Input A On error skip 4 If A Mod 2 =0 Then Print "your number is EVEN" Print ; Else Print "your number is ODD" EndIf Z=1/0 Loop ? 1 your number is ODD ? 2 your number is EVEN [13] Z=1/0 Error : Divide by zero > one could put an argument that n=7 should be the appropriate count, but then does ELSE and ENDIF count as statements, or is the whole IF/THEN/ELSE a single statement? i also see that the line count ignores blank lines, but does NOT ignore lines that are just a comment (ie, starting with '). the way delphi does it is: TRY SetPin I, DOUT Print "Good enough for Australia" EXCEPT Print "I'm sorry Dave, I'm afraid I can't do that" END cheers, rob :-) Edited 2023-01-14 00:42 by robert.rozee |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Making it less buggy has to be good and the suggested code looks to fix the situation where the jmp buf gets corrupted due to being left with stale data. Maybe add a note to the manual recommending rare usage / use with small N (like, 1)? Looks like the fix can use more stack space but with small N it'll be short-lived I think. John |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |