My "from PACKAGE import *" (Python) simulation project (reflection)

Anything QL Software or Programming Related.
User avatar
ql_freak
Gold Card
Posts: 498
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by ql_freak »

 
Watchers (not testers yet) needed.

EDIT (p.s.): WARNING: rn does NOT(!) renumber included line numbers in GO TO (GO SUB)!!! It's only for clean programs without GO TO and similar(!).

I finally have had found time, to improve my rn program (renumbering S[uper]BASIC-like programs). My test source "rnBefore_bas" (which will be renumbered) is:

Code: Select all

100 REMark Test for rn (renumbering C prog)
110 :
120 PRINT'hello world'
130 REMark Tests for rn: (Write in an Editor, not ED. Mix Lines with line numbers and without, with (forced) space after line number (not neessary, if you enter a line!).
140 :
AND HERE A LINE WITHOUT LINE NUMBER. WILL RN HANDLE THIS?
Now a line with a lower line number than the preceeding lines:
10 Oops, that's not possible in S(uper)BASIC (10 cannot follow after 140)
20    This line has spaces after the forced space. These MUST be preserved!
      Of course only the spaces after the forced space, while for an unnumbered line
  ALL spaces must be preserved.
999REMark (This was originally line 999): A line which cannot be saved but is correct SuperBASIC(!) In this case
REMark rn should (or should not, I'm not sure) add a forced space after the 999
5 REMark A linenumber with just one digit and forced space
8REMark and one 1 digit line number with missing forced space
1000:
1010 REMark: TODO: Add more tests above.
result file "rnAfter_bas" after command: ex'rn';'10000 5 <WIN1_DIRECTORY_rnBefore_bas >WIN1_DIRECTORY_rnAFTER_bas' is:

Code: Select all

10000 REMark Test for rn (renumbering C prog)
10005 :
10010 PRINT'hello world'
10015 REMark Tests for rn: (Write in an Editor, not ED. Mix Lines with line numbers and without, with (forced) space after line number (not neessary, if you enter a line!).
10020 :
10025 AND HERE A LINE WITHOUT LINE NUMBER. WILL RN HANDLE THIS?
10030 Now a line with a lower line number than the preceeding lines:
10035 Oops, that's not possible in S(uper)BASIC (10 cannot follow after 140)
10040    This line has spaces after the forced space. These MUST be preserved!
10045       Of course only the spaces after the forced space, while for an unnumbered line
10050   ALL spaces must be preserved.
10055 REMark (This was originally line 999): A line which cannot be saved but is correct SuperBASIC(!) In this case
10060 REMark rn should (or should not, I'm not sure) add a forced space after the 999
10065 REMark A linenumber with just one digit and forced space
10070 REMark and one 1 digit line number with missing forced space
10075 :
10080 REMark: TODO: Add more tests above.
Would this behaviour be okay?

Finally I realized, that I can use Visual Studio C (with its superb debugger :-) to develop rn further. The source now compiles with Visual Studio (free for private/small business usage) and EJC for the QL :-)))

Together with my reflection_cde it is now easily possible to merge any SuperBASIC-program. I hope I will find time, to publish an example here shortly (am currently extremly short of time).
Attachments
rn.zip
(6.65 KiB) Downloaded 3 times


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
Popopo
Gold Card
Posts: 447
Joined: Wed Apr 07, 2021 10:37 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by Popopo »

Amazing!
Lot of question I want to do :) but not till I get my brain fresh enough to understand a little more about your work.

In general, it is powering up the renumbering command. Isn't it?

Also... about to have a toolchain with Visual Studio or VSCode to program in C for QL is something very interesting for me.
I am thinking about to set & use Geany to allow to program in SuperBasic and compile it at once for QL.

I have really no idea (even when I use VSCode) how that works and doesn't inspiring me any trust along time (I see it like Eclipse growing up without control and sense making annoying to code for newbies or even average programmers). So about it, also I would ask, but not here (in order to do not bother with the main & important topic).

Nice to read your code and working method.
Thanks


User avatar
pjw
QL Wafer Drive
Posts: 1622
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by pjw »

Hi ql-freak. I sent you a PM letting you know about a problem with your reflection toolkit.


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
Derek_Stewart
Font of All Knowledge
Posts: 4711
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by Derek_Stewart »

Hi,

Totally off-topic, is Python going to be ported to the QL?


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2477
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by NormanDunbar »

I looked into that back at Python 2.7. basically, No!

Sorry.

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: 498
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by ql_freak »

Derek_Stewart wrote: Wed May 28, 2025 8:34 am Totally off-topic, is Python going to be ported to the QL?
The subject may a be misunderstanding, but it's absolutely not offtopic. It is my project to use the SuperBASIC MERGE command similar as the Python "import" (or more exactly, as the subject says) the "from Python import *" (import all global variables, functions and procedures) from a SuperBASIC program. With the new "rn" job the SuperBASIC program to merge may have line numbers or not, even mixed is possible. I think this is an improvement. Until now, if you want to merge a program, you must renumber your source or the program which should be merged. See my example here: viewtopic.php?p=64237#p64237

So now it's possible to create SuperBASIC-"libraries" which can be merged into a program, when this program is started, this will also save a lot of disk space, as the program itself must not contain all global variables, procedures and functions from the library. For a BBQL with just MicroDrives this IMHO may be a big advantage.


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 :-)
Derek_Stewart
Font of All Knowledge
Posts: 4711
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by Derek_Stewart »

...sorry for being a dummy, just did not the message correctly, brain is getti g mesxing, breathing solder flux...

I like the idea of libraries of Superbasic prcedures and functions, it does sound familiarm I thought there was something aready donem maybe locked in the Quanta Library.


Regards,

Derek
User avatar
BSJR
Trump Card
Posts: 222
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by BSJR »

Derek_Stewart wrote: Wed May 28, 2025 10:12 pm ...sorry for being a dummy, just did not the message correctly, brain is getti g mesxing, breathing solder flux...

I like the idea of libraries of Superbasic prcedures and functions, it does sound familiarm I thought there was something aready donem maybe locked in the Quanta Library.
There is also W.Lenerz's BasicLinker which allows you to write numberless Basic modules that can be linked through a _ctrl text file to make a numbered and combined _bas file, and can even call Qlib to compile the lot.
He also made a library of "standard" modules to use, probably on Dilwyn's site somewhere.

BSJR


User avatar
polka
Trump Card
Posts: 212
Joined: Mon Mar 07, 2011 11:43 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by polka »

Hi,
I did not find W.Lenerz's BasicLinker ? But

What I understood from this thread is that you want to be able to load a superbasic program by "importing like with Python" modules that compose it ? And do it without the hassle of line number managing ? Well, my advice is : do not bother to mimic other programming or preprocessing tools, do it using only the power of "vanilla" superbasic ( TK2 eventually added).
This plain superbasic function will read unnumbered superbasic from a file suffixed with "_TXT" and create (or overwrite) a file with line numbers and with the same name suffixed with "_BAS" :

1 DEFine FuNction add_line_numbers(f$,first,interval)
2 input_file$ = dev$ & f$ & "_txt"
3 output_file$ = dev$ & f$ & "_bas"
4 OPEN_IN#5,input_file$
5 OPEN_OVER#6,output_file$
6 l = first : i = interval
7 REPeat number
8 INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
9 IF CODE(l$(k))=13 THEN k = k-1
10 IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
11 ELSE i = 0 : END IF
12 IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
13 END REPeat number
14 CLOSE#6 : CLOSE#5 : RETurn l
15 END DEFine add_line_numbers


It needs a string parameter F$ and two numbers : the number of the first line and the interval between the line numbers. And because I coded it as a FuNction, it will return the number of the last line. To be noted that if the _TXT file has blank lines they are removed and if the lines finish with CRLF, the CR characters are dismissed in the resulting _BAS file.
The _BAS files are ready to be MERGE or MRUN using these two superbasic commands. Only, GOTOs or GOSUBs (that are actually bad and moreover not at all useful in superbasic programs) should be avoided.
Last edited by polka on Sun Jun 01, 2025 4:01 pm, edited 2 times in total.


May the FORTH be with you !
POLKa
User avatar
polka
Trump Card
Posts: 212
Joined: Mon Mar 07, 2011 11:43 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by polka »

As an example of how this could foster modular loading of superbasic programs, here is my way to BOOT : in this little BOOT file, I load only one PROCedure called BYE and the FuNction ALN (abbreviation of "add_line_numbers"). These are numbered from 32742 to 32767, and surrouned by some unnumbered superbasic commands (that will be executed immediately when BOOT is loaded).

DEV$="FLP1_" : MODE 4 : PROG_USE DEV$ : DATA_USE DEV$

32741 MRUN DEV$ & "TOOB"

32742 DEFine FuNction ALN(f$,f,d)
32743 input_file$ = DEV$ & f$ & "_txt"
32744 output_file$ = DEV$ & f$ & "_bas"
32745 OPEN_IN#5,input_file$:OPEN_OVER#6,output_file$
32746 l = f : i = d
32747 REPeat number
32748 INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
32749 IF CODE(l$(k)) = 13 THEN k = k - 1
32750 IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$(1 TO k)
32751 ELSE i = 0 : ENDIF
32752 IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = d
32753 END REPeat number
32754 CLOSE#6 : CLOSE#5 : RETurn l
32755 END DEFine ALN

32757 DEFine PROCedure BYE
32758 PAPER#3,0:INK#3,4:CSIZE#3,0,0:CLS#3:AT#3,0,7
32759 PRINT#3,' F1',,'F2',,'F3',,'F4',,'F5':RESTORE OK
32760 FOR i = 5 TO 69 STEP 16
32761 READ p,q,p$,Q$:PAPER#3,p:INK#3,q
32762 AT#3,1,i:PRINT#3,p$:AT#3,2,i:PRINT#3,Q$
32763 END FOR i
32764 p = CODE(INKEY$(-1))/4
32765 IF p<58 OR p>62 : GO TO 32764
32766 CLS#0:CLS:CLS#2:GO TO p+OK-53
32767 END DEFine BYE

PRINT aln("MANIFEST",1,1)
MRUN DEV$ & "MANIFEST_bas"


You see that in the two last lines of this BOOT, FuNtion ALN is first used to add line numbers to a MANIFEST_TXT file that is then MRUN as MANIFEST_BAS.
Last edited by polka on Sun Jun 01, 2025 12:49 pm, edited 1 time in total.


May the FORTH be with you !
POLKa
Post Reply