Too many parameters/locals bug

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Too many parameters/locals bug

Post by NormanDunbar »

Does anyone remember the bug whereby if a SuperBASIC procedure or function had a total of 10 (I think) or more parameters and locals, it would corrupt SuperBASIC? I was reading an old DJToolkit manual this morning -- don't ask -- and came across a comment from myself about it. I was wondering what exactly caused this problem. Does anyone know? It's no doubt already fixed in SMSQ so looking in the sources probably won't help. It's not urgent, or causing any problems, I'm just curious.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: Too many parameters/locals bug

Post by dilwyn »

From one of Simon Goodwin's bugs articles:
“MG” SuperBasic has been thoroughly spring-cleaned. You can use any number of parameters and LOCALs in a procedure or function. Previous versions of the Basic allowed only enough space for nine such names. If you used more, the program could lock up or be corrupted by the appearance of spurious PRINT keywords in place of names towards the end of the program. That knowledge may help you to spot program listings which were improved by their authors, untested, before publication.


User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Too many parameters/locals bug

Post by NormanDunbar »

Thanks Dilwyn. I was wondering if the problem was caused by assuming "nobody will need more than 9 parameters or locals" and it seems that that was indeed the cause of the error.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
stevepoole
Super Gold Card
Posts: 716
Joined: Mon Nov 24, 2014 2:03 pm

Re: Too many parameters/locals bug

Post by stevepoole »

Hi Norm,

There was a fix for the LOCals bug :
erzero=one: if erzero<>0: print 'error': stop

DEF FUnction one
Local (nine elements).
erone=two: RETurn erone
end def

DEF FUNCtion two
Local (another nine elements)
ertwo=main: RETurn ertwo
end def

DEF FUNCtion main etc

You could nest as many dummy routines as you needed locals in your main program....
I used this technique many times without problems.
Note the error returns needed, to get back up through the calls !

Regards, Steve.
_________________


User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Too many parameters/locals bug

Post by NormanDunbar »

Interesting, very interesting! And quite strange too.

I'm not having problems with this, I was just wondering what had been the cause. But thanks for the workaround Steve.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: Too many parameters/locals bug

Post by ql_freak »

Hi Steve,
stevepoole wrote: Thu Jun 15, 2023 10:16 pm There was a fix for the LOCals bug :
erzero=one: if erzero<>0: print 'error': stop
...
Albeit I don't fully understand your (not complete?) example, I think it's because local variables in SuperBASIC are not really local variables as in other languages (e.g. C or Python). See the following example:

Code: Select all

100 REMark demo for visibility (c't 11/1984, Florian Sachse)
110 :
120 o%=4:LIST#o%
130 :
140 REMark main program
150 :
160 test_text$ = 'From main program'
170 test1
180 test2
190 :
200 DEFine PROCedure test1
210   PRINT#o%,'Which variable is visible(?): ';test_text$
220 END DEFine
230 :
240 DEFine PROCedure test2
250   LOCal test_text$
260   :
270   test_text$ = 'From Procedure "test2"'
280   test1
290 END DEFine
300 :
310 :
320 REMark Output:
330 :
Which variable is visible(?): From main program
Which variable is visible(?): From Procedure "test2"
Regards
Peter


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Too many parameters/locals bug

Post by NormanDunbar »

Hi Peter,

SuperBASIC is interesting in this respect. I have a stalled project at https://github.com/NormanDunbar/C68Port -- the SBLocals directory has a C68 source file which emulates thecway the SuperBASIC handles locals -- basically, locals are visible in the FN/PROC which declared them and in any called FN/PROCs called from there, no matter how deep the call tree is!

The tests directory has a number of test programs to be sure my codecworks.

(If anyone is even slightly interested!)

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
ql_freak
Gold Card
Posts: 354
Joined: Sun Jan 18, 2015 1:29 am

Re: Too many parameters/locals bug

Post by ql_freak »

NormanDunbar wrote: Fri Jun 16, 2023 10:05 pm ... the SBLocals directory has a C68 source file which emulates thecway the SuperBASIC handles locals ...
...
(If anyone is even slightly interested!)
Sounds interesting, especially C68Port (Digital Precision?). Does this finally work? I have had bought it, but It didn't work. At least not with my programs.

Regards

Peter


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
NormanDunbar
Forum Moderator
Posts: 2278
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Too many parameters/locals bug

Post by NormanDunbar »

Hi Peter,
ql_freak wrote: Sat Jun 17, 2023 1:34 am Sounds interesting, especially C68Port (Digital Precision?). Does this finally work? I have had bought it, but It didn't work. At least not with my programs.
Well, Digital Precision's program was Cport, mine -- the stalled project -- is C68Port. I'm attempting to write a version of SuperBASIC to C68 style C code, whether or not I get it finished remains to be seen. I'm afraid I have many started but not finished projects these days. Something to do with writing books! When I started writing it, I decided to work out a manner in which I could get a proper emulation of how SuperBASIC handles locals. I know I got it working for integers and floats, and arrays of the same as well as strings. I thing I stalled somewhere/somehow on arrays of strings. I'd have to check though.

As for the original CPort, it did work -- sort of -- but If I remember correctly, there were a couple of programs written to massage the generated C code to make it actually work a bit better.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
stevepoole
Super Gold Card
Posts: 716
Joined: Mon Nov 24, 2014 2:03 pm

Re: Too many parameters/locals bug

Post by stevepoole »

Hi QL_Freak,

Herewith, a complete 'demo' program allowing more than nine locals in a function, with the possibility to escape on an error.....

It will work with procedures too. Tested under QDOS on SGC, (but used to run ok on 128ko).

Define the main routine however you require !

Steve.
NinePlus_Locals.zip
(637 Bytes) Downloaded 31 times
_______________________________________________________


Post Reply