Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:57 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite/MMBasic-core: bug with subroutine nesting level (LocalIndex)

     Page 2 of 2    
Author Message
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 12:21pm 13 Jan 2023
Copy link to clipboard 
Print this post

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 Zealand
Posts: 2442
Posted: 01:40pm 13 Jan 2023
Copy link to clipboard 
Print this post

  matherp said  Shows why I never use ON ERROR. I thought it was supposed to skip the next five commands after an error


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
  Print
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 Kingdom
Posts: 4311
Posted: 02:02pm 13 Jan 2023
Copy link to clipboard 
Print this post

Hi Rob,

  robert.rozee said  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?


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.

  robert.rozee said  How is one case (1) justified over the other (n)?


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.

  robert.rozee said  I'd add to that, what about multi-line IF/THEN/ELSE's?


Is that a hypothetical issue or do you have code for me to add to my unit-tests ?

  robert.rozee said  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.


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 Zealand
Posts: 2442
Posted: 02:39pm 13 Jan 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4044
Posted: 02:48pm 13 Jan 2023
Copy link to clipboard 
Print this post

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
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025