Merge branch 'main' into 10
Some checks failed
akbasic CI Build / mutation_test (push) Failing after 11m28s
akbasic CI Build / akgl_build (push) Failing after 11m46s
akbasic CI Build / coverage (push) Failing after 12m10s
akbasic CI Build / sanitizers (push) Failing after 12m21s
akbasic CI Build / cmake_build (push) Failing after 12m33s

This commit is contained in:
2026-08-06 12:50:30 -04:00
committed by Starfort Source Vault
75 changed files with 2335 additions and 328 deletions

View File

@@ -0,0 +1,6 @@
10 REM A GEN invoked like an ordinary function is refused, not silently run.
20 GEN ONE(N#)
30 EMIT N#
40 END GEN
50 X# = ONE(5)
60 PRINT "UNREACHABLE"

View File

@@ -0,0 +1,2 @@
? 50 : RUNTIME ERROR ONE is a GEN; call it with FOR EACH or DO EACH, not as a function

View File

@@ -0,0 +1,8 @@
10 REM A DO EACH takes its condition on the LOOP, not on the DO line.
20 GEN ONE(N#)
30 EMIT N#
40 END GEN
50 DO EACH V# IN ONE(1) WHILE V# < 9
60 PRINT V#
70 LOOP
80 PRINT "UNREACHABLE"

View File

@@ -0,0 +1,2 @@
? 50 : PARSE ERROR DO EACH takes its WHILE/UNTIL on the LOOP, and nothing else here

View File

@@ -0,0 +1,14 @@
10 REM Same generator as generators_foreach.bas, via DO EACH ... LOOP.
20 DIM OBJ#(3)
30 OBJ#(0) = 100
40 OBJ#(1) = 200
50 OBJ#(2) = 300
60 GEN ROOMOBJECTS(R#)
70 FOR I# = 0 TO 2
80 IF I# <> 1 THEN EMIT OBJ#(I#)
90 NEXT I#
100 END GEN
110 DO EACH O# IN ROOMOBJECTS(0)
120 PRINT O#
130 LOOP
140 PRINT "DONE"

View File

@@ -0,0 +1,3 @@
100
300
DONE

View File

@@ -0,0 +1,3 @@
10 REM EMIT outside any GEN invocation is refused cleanly.
20 EMIT 5
30 PRINT "UNREACHABLE"

View File

@@ -0,0 +1,2 @@
? 20 : RUNTIME ERROR EMIT outside the context of a GEN body

View File

@@ -0,0 +1,11 @@
10 REM A GEN with no EMIT at all runs its FOR EACH/DO EACH body zero times.
20 GEN NOTHING(N#)
30 END GEN
40 FOR EACH X# IN NOTHING(0)
50 PRINT "NEVER FOR"
60 NEXT X#
70 PRINT "AFTER FOR"
80 DO EACH Y# IN NOTHING(0)
90 PRINT "NEVER DO"
100 LOOP
110 PRINT "AFTER DO"

View File

@@ -0,0 +1,2 @@
AFTER FOR
AFTER DO

View File

@@ -0,0 +1,15 @@
10 REM The GEN/FOR EACH example from issue #57, with real arrays standing in
20 REM for OBJCOUNT%/VISIBLE/OBJ%.
30 DIM OBJ#(3)
40 OBJ#(0) = 100
50 OBJ#(1) = 200
60 OBJ#(2) = 300
70 GEN ROOMOBJECTS(R#)
80 FOR I# = 0 TO 2
90 IF I# <> 1 THEN EMIT OBJ#(I#)
100 NEXT I#
110 END GEN
120 FOR EACH O# IN ROOMOBJECTS(0)
130 PRINT O#
140 NEXT O#
150 PRINT "DONE"

View File

@@ -0,0 +1,3 @@
100
300
DONE

View File

@@ -0,0 +1,15 @@
10 REM A WHILE or UNTIL on the LOOP composes with DO EACH: it is checked
20 REM after each trip through the body, with the loop variable still
30 REM holding that trip's value. Stopping abandons the generator cleanly.
40 GEN COUNTUP(N#)
50 FOR I# = 1 TO N#
60 EMIT I#
70 NEXT I#
80 END GEN
90 DO EACH V# IN COUNTUP(10)
100 PRINT V#
110 LOOP UNTIL V# = 3
120 DO EACH W# IN COUNTUP(4)
130 PRINT W# * 10
140 LOOP WHILE W# < 3
150 PRINT "DONE"

View File

@@ -0,0 +1,7 @@
1
2
3
10
20
30
DONE

View File

@@ -0,0 +1,10 @@
10 REM A stray NEXT with nothing open behaves like the plain-FOR case: the
20 REM FOR EACH's own NEXT closes it cleanly, and a second one errors.
30 GEN ONE(N#)
40 EMIT N#
50 END GEN
60 FOR EACH O# IN ONE(1)
70 PRINT O#
80 NEXT O#
90 NEXT O#
100 PRINT "UNREACHABLE"

View File

@@ -0,0 +1,3 @@
1
? 90 : RUNTIME ERROR NEXT outside the context of FOR

View File

@@ -0,0 +1,22 @@
10 REM Nested FOR EACH/DO EACH over the same GEN with different arguments,
20 REM in every combination of the two loop shapes.
30 GEN COUNTUP(N#)
40 FOR I# = 1 TO N#
50 EMIT I#
60 NEXT I#
70 END GEN
80 FOR EACH A# IN COUNTUP(2)
90 FOR EACH B# IN COUNTUP(3)
100 PRINT A# * 10 + B#
110 NEXT B#
120 NEXT A#
130 DO EACH C# IN COUNTUP(2)
140 DO EACH D# IN COUNTUP(2)
150 PRINT C# * 100 + D#
160 LOOP
170 LOOP
180 FOR EACH E# IN COUNTUP(2)
190 DO EACH F# IN COUNTUP(2)
200 PRINT E# * 1000 + F#
210 LOOP
220 NEXT E#

View File

@@ -0,0 +1,14 @@
11
12
13
21
22
23
101
102
201
202
1001
1002
2001
2002

View File

@@ -0,0 +1,15 @@
10 REM RETURN ends a GEN early, exactly as END GEN would: a GEN is a
20 REM function at heart, and only EMIT is different about it. Like a
30 REM GOSUB's or DEF's RETURN, it must stand in the GEN's own scope,
40 REM not inside a FOR or DO the body opened.
50 GEN FIRSTFEW(N#)
60 EMIT 1
70 IF N# < 2 THEN RETURN
80 EMIT 2
90 IF N# < 3 THEN RETURN
100 EMIT 3
110 END GEN
120 FOR EACH V# IN FIRSTFEW(2)
130 PRINT V#
140 NEXT V#
150 PRINT "DONE"

View File

@@ -0,0 +1,3 @@
1
2
DONE

View File

@@ -0,0 +1,11 @@
10 REM FOR EACH/DO EACH accept any emitted type, not just numeric.
20 GEN WORDS(N#)
30 EMIT "HELLO"
40 EMIT "WORLD"
50 END GEN
60 FOR EACH W$ IN WORDS(0)
70 PRINT W$
80 NEXT W$
90 DO EACH V$ IN WORDS(0)
100 PRINT V$
110 LOOP

View File

@@ -0,0 +1,4 @@
HELLO
WORLD
HELLO
WORLD

View File

@@ -0,0 +1,3 @@
10 PRINT "97 : " + ASC("a")
20 PRINT "65 : " + ASC("A")
30 PRINT "64 : " + ASC("@")

View File

@@ -0,0 +1,3 @@
97 : 97
65 : 65
64 : 64