Page 2 of 3
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Thu Apr 17, 2025 3:37 pm
by tofro
I actually found a way to get the current highest used line number from S*BASIC without messing with poorly documented internal S*BASIC data structures:
- Append a line 32767 to your program holding "32767 DATA 999" (the actual value in that DATA item is totally arbitrary, BTW)
- RENUM 1 TO;1,1
- RESTORE 1
- REPEAT lp: IF EOF : EXIT LP : READ a$ : END REPEAT lp
- lastLine = PEEK_W (\\$94)
- DLINE lastLine
Step 1 can be done using MERGE or MRUN
This uses the fact that S*BASIC actually keeps track of the current DATA line number in a basic system variable (\\$94). We make sure the last line of the program is a DATA line, read all DATA as far as possible, then PEEK the current DATA line number and delete the inserted line. After the routine has run, lastLine will hold the next usable line number.
The RENUM in step 2 is to "compress" used line numbers as much as possible, thus will leave your program with lines starting from 1 in 1-steps. If you don't like this, do another RENUM at the end of the routine that renumbers the program to your liking.
If you think someone was as bold as using line # 32767 already, add another RENUM before (1).
You need to read a string in the loop to avoid data type mismatches in possibly already existing DATA lines. Obviously, if your program already has some DATA lines, you'll also need to do a RESTORE 1 after the routine has run (because it has exhausted all the DATA already)
EDIT: Just found that anything but RENUM without arguments (so, 10, 10) will stop the program in SBASIC with no message whatsoever.... - So, it still works which RENUM only, but your range of line numbers is severely limited (I conceive that as a bug in SBASIC, BTW). Apparently, SBASIC doesn't "RENUM" the current line it is in. But you should be able to arrange your programs that they survive a RENUM.
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sat Apr 19, 2025 1:31 am
by ql_freak
Giorgio Garabello wrote: Thu Apr 17, 2025 8:47 am
I guess yours is a "challenge" to try to do this in basic, because the simplest thing would be with QD or MicroEmacs to remove the numbers and reintroduce them automatically with SSB.
I confess, I haven't looked at SSB yet :‑( But can it merge a S(uper)BASIC program without line numbers (I'm planning to extend it [the "rn" executable], so that also S(uper)BASIC programs with line number can be merged) to a loaded S(uper)BASIC program? Then I should stop development. AND: I don't want to use QD, MicroEMACS, ... as editor. I want to use ED, as only this has the advantage of syntax checking every line which is entered. (BTW: This will perhaps be my next project: Write EMACS-extension[s], which checks syntax of S(uper)BASIC as ED, when programming S(uper)BASIC).
The intention is to simulate the "import" (or to be exactly the from MODULE import *) statement from Python for S(uper)BASIC programs, which DO NOT(!) use GO TO (GO SUB, ...).
See my other post
here. As written here, as I have used EJC, the rn program is reentrant (most probably even ROMable).
But as my main PC is defect, I'm currently busy with setting up my GPD Pocket 3, which is a full (Intel Core 7, 1 GByte SSD) Notebook (albeit much smaller than a real Mini-Notebook – unfortunately larger than a GPD Pocket 2, which really fits in a Pocket).
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sat Apr 19, 2025 1:54 am
by ql_freak
tofro wrote: Thu Apr 17, 2025 2:47 pm
Well I'd guess that a
Code: Select all
RENUM 1 TO;1,1
MERGE <to highest possible line number for inserted code (i.e 32767-line count)>
RENUM 1 TO;10,10
Should do as well. Admitted here's no chance to catch errors, but that shouldn't fail more often than any more sophisticated method. This is the pragmatic approach: Just make as much room as possible for the inserted code and when that turns out not enough, any other hugely more complicated method wouldn't have worked as well.....
I'm afraid, I do not understand this code fully. AFAIK RENUM should (must?) not be used inside a program. AND: I don't want to renumber the currently loaded program. Please see my
example (which I will most probably extend, so that it can be used to merge SuperBASIC programs with line numbers). Of course it would be much better, to write a better MERGE S(uper)BASIC machine code extension than my rn executable, but this is much more difficult, than writing it in C (with the advantage of getc(), (s)scanf(), (s)printf(), ...).
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sat Apr 19, 2025 4:07 am
by swensont
Peter,
Structured SuperBasic (SSB) is an pre-processor for SuperBasic. It takes a text file, which is usually a SuperBasic program, and adds lines numbers. It also support "conditional compilation" meaning it supports #IFDEF type statements. It supports #INCLUDE to combine a number of SSB-type programs into the final result. I wrote SSB because I had just spent a couple of years doing Pascal in college and was learning C. Having line numbers made the code difficult to read. Adding in other pre-processor options was the influence of the C pre-processor. Also, by not using line numbers, other programming tools could be used like Make, Ctags, etc.
I wrote it to write SuperBasic in a style that I wanted and a few others have found it useful. Norman has extended it to add features that he wanted.
Tim
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sat Apr 19, 2025 9:48 am
by tofro
ql_freak wrote: Sat Apr 19, 2025 1:54 am
I'm afraid, I do not understand this code fully. AFAIK RENUM should (must?) not be used inside a program. AND: I don't want to renumber the currently loaded program. Please see my
example (which I will most probably extend, so that it can be used to merge SuperBASIC programs with line numbers). Of course it would be much better, to write a better MERGE S(uper)BASIC machine code extension than my rn executable, but this is much more difficult, than writing it in C (with the advantage of getc(), (s)scanf(), (s)printf(), ...).
RENUM can very well be used in a running program - as long as you make sure the line numbers that "currently run" (i.e. the ones that actually call RENUM) don't change. You can achieve this by putting the RENUM code at the beginning of the program with increments you intend to use later. Of course it's a dirty hack, but the only method I see that does what you want from S*BASIC. But if you refuse to have your program renumbered, well you need to do it the complicated way (or you introduce a convention that makes sure all your programs and snippets have a DATA line as the last line).
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sat Apr 19, 2025 10:23 am
by Martin_Head
I'm not sure exactly what you are trying to do. But could you pull the 'ED' code from the SMSQ/E sources, and modify it to take it's input from a file instead of the keyboard.
If you have a SuperBASIC program loaded and start ED with something like ED 32000. It will start editing on the last line. If your import file starts with a CHR$(10) (enter). Then you get a new line. Then anything read from the file will be the same as typing it in. Just end the file with an Escape to exit.
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sun Apr 20, 2025 7:00 pm
by Giorgio Garabello
ql_freak wrote: Sat Apr 19, 2025 1:31 am
Giorgio Garabello wrote: Thu Apr 17, 2025 8:47 am
I guess yours is a "challenge" to try to do this in basic, because the simplest thing would be with QD or MicroEmacs to remove the numbers and reintroduce them automatically with SSB.
I confess, I haven't looked at SSB yet :‑( But can it merge a S(uper)BASIC program without line numbers (I'm planning to extend it [the "rn" executable], so that also S(uper)BASIC programs with line number can be merged) to a loaded S(uper)BASIC program? Then I should stop development. AND: I don't want to use QD, MicroEMACS, ... as editor. I want to use ED, as only this has the advantage of syntax checking every line which is entered. (BTW: This will perhaps be my next project: Write EMACS-extension[s], which checks syntax of S(uper)BASIC as ED, when programming S(uper)BASIC).
The intention is to simulate the "import" (or to be exactly the from MODULE import *) statement from Python for S(uper)BASIC programs, which DO NOT(!) use GO TO (GO SUB, ...).
See my other post
here. As written here, as I have used EJC, the rn program is reentrant (most probably even ROMable).
But as my main PC is defect, I'm currently busy with setting up my GPD Pocket 3, which is a full (Intel Core 7, 1 GByte SSD) Notebook (albeit much smaller than a real Mini-Notebook – unfortunately larger than a GPD Pocket 2, which really fits in a Pocket).
Then SSB is not good for you.
You write the code without numbers with an editor (I use MicroEMACS that has the highlighting of the basic words) then from Emacs I transform the SSB code into basic, I compile it and then I run it (all from MicroEMACS).
I use SSB because it allows you to have "includes" like the C language (and some other special things that improve programming)
If you want to modify EMACS count on my help, I know that editor very well, I can help you
Giorgio
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Sun Apr 20, 2025 7:06 pm
by Giorgio Garabello
swensont wrote: Sat Apr 19, 2025 4:07 am
Peter,
Structured SuperBasic (SSB) is an pre-processor for SuperBasic. It takes a text file, which is usually a SuperBasic program, and adds lines numbers. It also support "conditional compilation" meaning it supports #IFDEF type statements. It supports #INCLUDE to combine a number of SSB-type programs into the final result. I wrote SSB because I had just spent a couple of years doing Pascal in college and was learning C. Having line numbers made the code difficult to read. Adding in other pre-processor options was the influence of the C pre-processor. Also, by not using line numbers, other programming tools could be used like Make, Ctags, etc.
I wrote it to write SuperBasic in a style that I wanted and a few others have found it useful. Norman has extended it to add features that he wanted.
Tim
Where can I find this extended version?
What release number is it?
Thank you Tim
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Mon Apr 21, 2025 7:06 am
by Derek_Stewart
Giorgio Garabello wrote: Sun Apr 20, 2025 7:00 pm
Then SSB is not good for you.
You write the code without numbers with an editor (I use MicroEMACS that has the highlighting of the basic words) then from Emacs I transform the SSB code into basic, I compile it and then I run it (all from MicroEMACS).
I use SSB because it allows you to have "includes" like the C language (and some other special things that improve programming)
If you want to modify EMACS count on my help, I know that editor very well, I can help you
Giorgio
Hi,
How do you run SSB from MicroEMACS?
Re: My "from PACKAGE import *" (Python) simulation project
Posted: Mon Apr 21, 2025 7:42 am
by NormanDunbar
Morning Derek.
https://github.com/SinclairQL/Structure ... tag/2.7.2g
2.7.2g is the latest. Details in the docs as to what changed. One thing I added that is incompatible with Tim's version,the line continuation character is "/" in Tim's but in mine it's "/+" as I often use PRINT statements with the trailing slash to get a linefeed. Those lines were combined with the next one and caused MISTakes.
Cheers,
Norm.