added test suite and fixed REMs

This commit is contained in:
Luxferre
2026-06-15 12:56:41 +03:00
parent f7e8e72b81
commit e9c44d6e9a
4 changed files with 73 additions and 2 deletions
+4
View File
@@ -28,6 +28,10 @@ Here are all currently known implementations of LTTB:
* [Jim Tcl port](./lttb.tcl) (284 SLOC) * [Jim Tcl port](./lttb.tcl) (284 SLOC)
## Test suite
LTTB also ships a [test suite](test.bas) source code file to verify implementation correctness. Every non-empty line between the start and the end should end with `OK`.
## FAQ ## FAQ
Please read the [manual](lttb-manual.md) first, your question is most likely covered there. If not, here are some more questions and answers. Please read the [manual](lttb-manual.md) first, your question is most likely covered there. If not, here are some more questions and answers.
+3 -1
View File
@@ -218,7 +218,7 @@ Value and string printing routine. Accepts `STMT` string as a parameter.
Run the program currently loaded into the working memory. Run the program currently loaded into the working memory.
1. Set `IP = 1`. 1. Set `IP = 1`.
2. If `PROGMEM[IP]` exists and is not empty, execute `PROGEXEC(PROGMEM[IP])`. 2. If `PROGMEM[IP]` exists, is not empty and does not start with the string `REM`, execute `PROGEXEC(PROGMEM[IP])`.
3. Increment `IP` by 1. 3. Increment `IP` by 1.
4. If `IP > 0` and `IP < 32768`, go to step 2. 4. If `IP > 0` and `IP < 32768`, go to step 2.
@@ -279,3 +279,5 @@ Program saving routine into external storage media. The provided algorithm works
## Closing notes ## Closing notes
The set of algorithms in this document should be enough to create a complete and functional LTTB interpreter in any modern programming language. If you have any corrections or optimizations regarding the algorithms, feel free to create an issue in this repository. The set of algorithms in this document should be enough to create a complete and functional LTTB interpreter in any modern programming language. If you have any corrections or optimizations regarding the algorithms, feel free to create an issue in this repository.
In order to verify implementation correctness, you can use the code inside [test.bas](test.bas) shipped in this repository.
+1 -1
View File
@@ -256,7 +256,7 @@ proc int_RUN {} {
global progmem ip global progmem ip
set ip 1 set ip 1
while {$ip > 0 && $ip < 32768} { while {$ip > 0 && $ip < 32768} {
if {[dict exists $progmem $ip]} {lttb_exec $progmem($ip)} if {[dict exists $progmem $ip] && [string first REM $progmem($ip)] != 0} {lttb_exec $progmem($ip)}
incr ip incr ip
} }
} }
+65
View File
@@ -0,0 +1,65 @@
5 rem This is a comment and should never be executed
10 print "Luxferre's Truly Tiny BASIC test suite"
15 print ""
20 print "All lines should end with OK to pass"
30 print "Let's go..."
35 print ""
40 print "Nested IF and A-I zero init: ";
50 if a=0 if b=0 if c=0 if d=0 if e=0 if g=0 if h=0 if i=0 print "OK"
55 print ""
60 print "Nested IF and J-Q zero init: ";
70 if j=0 if k=0 if l=0 if m=0 if n=0 if o=0 if p=0 if q=0 print "OK"
75 print ""
80 print "Nested IF and R-Y zero init: ";
90 if r=0 if s=0 if t=0 if u=0 if v=0 if w=0 if x=0 if y=0 print "OK"
95 print ""
100 print "Z zero init: ";
110 if z=0 print "OK"
120 print ""
130 print "Precedence: ";
140 if 2 + 2 * 2 - 3 / 3 = 5 print "OK"
150 print ""
160 print "Left assoc and full THEN form: ";
170 if 63 / 8 * 8 = 56 then print "OK"
180 print ""
190 print "Parentheses: ";
200 if 5 * (2+3) * (4 + 1) = 125 print "OK"
210 print ""
220 print "Int pos wrap: ";
230 if 32767 + 1 = -32768 print "OK"
240 print ""
250 print "Int neg wrap: ";
260 if -32768 - 1 = 32767 print "OK"
270 print ""
280 print "int mod wrap: ";
290 if 32767 + 65535 = 32766 print "OK"
300 print ""
310 print "This should display 108 after a space: ";12*9;" -> OK"
315 print ""
320 print "This should display 56 after a tab: ", 63/8*8 ; " -> OK"
325 print ""
330 print "GOTO: ";
340 goto 3 * 300
350 print ""
360 print "GOSUB: ";
370 GOSUB 2 + 918
380 print "OK"
390 print ""
400 print "RND: ";
410 x = rnd(100) + rnd(100) + rnd(100) + rnd(100) + rnd(100) + rnd(100)
420 if x < 600 if rnd(100) <> x/6 print "OK"
430 print ""
440 print "Indirect line rewriting in if/then form: ";
450 if x > -1 then 950 print "OK"
460 gosub 950
470 print ""
480 print "Test end, thank you!"
490 end
890 print "This line should never be printed"
900 print "OK"
910 goto 350
920 print "OK"
930 print "RETURN: ";
940 return
950 print "NOT OK"
960 return