lua: scoreboard iter — table.getn/foreach/foreachi + string.reverse (sort.lua unblocked past getn)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 20:04:45 +00:00
parent 5ea81fe4e0
commit 0b0d704f1e
4 changed files with 94 additions and 40 deletions

View File

@@ -918,6 +918,21 @@
(dict-set! string "gmatch" lua-string-gmatch)
(dict-set! string "gsub" lua-string-gsub)
(dict-set! string "format" lua-string-format)
(define
lua-string-reverse
(fn (s)
(let ((out ""))
(begin
(define
rloop
(fn (i)
(when (>= i 0)
(begin
(set! out (str out (char-at s i)))
(rloop (- i 1))))))
(rloop (- (len s) 1))
out))))
(dict-set! string "reverse" lua-string-reverse)
;; ── math library ──────────────────────────────────────────────
(define math {})
@@ -1167,6 +1182,44 @@
(dict-set! table "sort" lua-table-sort)
(dict-set! table "unpack" lua-unpack)
(dict-set! table "maxn" lua-table-maxn)
(dict-set! table "getn" lua-len)
(dict-set! table "setn" (fn (t n) nil))
(define
lua-table-foreach
(fn (t f)
(let ((ks (keys t)))
(begin
(define
tfl
(fn (i)
(when (< i (len ks))
(let ((k (nth ks i)))
(cond
((= k "__meta") (tfl (+ i 1)))
(else
(let ((r (lua-call f (lua-key-to-value k) (get t k))))
(cond
((lua-truthy? r) r)
(else (tfl (+ i 1)))))))))))
(tfl 0)
nil))))
(dict-set! table "foreach" lua-table-foreach)
(define
lua-table-foreachi
(fn (t f)
(let ((n (lua-len t)))
(begin
(define
tfi
(fn (i)
(when (<= i n)
(let ((r (lua-call f i (get t (str i)))))
(cond
((lua-truthy? r) r)
(else (tfi (+ i 1))))))))
(tfi 1)
nil))))
(dict-set! table "foreachi" lua-table-foreachi)
(define unpack lua-unpack)

View File

@@ -1,8 +1,8 @@
{
"totals": {
"pass": 0,
"fail": 14,
"timeout": 2,
"fail": 13,
"timeout": 3,
"skip": 8,
"total": 24,
"runnable": 16,
@@ -15,15 +15,15 @@
],
[
"timeout",
2
],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
2
3
],
[
"arith type error",
1
],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
1
]
],
"results": [
@@ -43,19 +43,19 @@
"name": "attrib.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5584
"ms": 5703
},
{
"name": "big.lua",
"status": "timeout",
"reason": "per-test timeout",
"ms": 8004
"ms": 8008
},
{
"name": "calls.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4599
"ms": 4488
},
{
"name": "checktable.lua",
@@ -79,7 +79,7 @@
"name": "constructs.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4056
"ms": 4285
},
{
"name": "db.lua",
@@ -97,7 +97,7 @@
"name": "events.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6705
"ms": 6639
},
{
"name": "files.lua",
@@ -115,13 +115,13 @@
"name": "literals.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 1734
"ms": 1774
},
{
"name": "locals.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 1510
"ms": 1552
},
{
"name": "main.lua",
@@ -133,43 +133,43 @@
"name": "math.lua",
"status": "fail",
"reason": "arith type error",
"ms": 3820
"ms": 3789
},
{
"name": "nextvar.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6758
"ms": 6939
},
{
"name": "pm.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5586
"ms": 5707
},
{
"name": "sort.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 1121
"status": "timeout",
"reason": "per-test timeout",
"ms": 8007
},
{
"name": "strings.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3652
"ms": 3846
},
{
"name": "vararg.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2009
"ms": 2116
},
{
"name": "verybig.lua",
"status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 527
"ms": 534
}
]
}

View File

@@ -1,14 +1,14 @@
# Lua-on-SX conformance scoreboard
**Pass rate:** 0/16 runnable (0.0%)
fail=14 timeout=2 skip=8 total=24
fail=13 timeout=3 skip=8 total=24
## Top failure modes
- **11x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **2x** timeout
- **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
- **3x** timeout
- **1x** arith type error
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
## Per-test results
@@ -16,25 +16,25 @@ fail=14 timeout=2 skip=8 total=24
|---|---|---|---:|
| all.lua | skip | driver uses dofile to chain other tests | 0 |
| api.lua | skip | requires testC (C debug library) | 0 |
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5584 |
| big.lua | timeout | per-test timeout | 8004 |
| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4599 |
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5703 |
| big.lua | timeout | per-test timeout | 8008 |
| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4488 |
| checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | timeout | per-test timeout | 8007 |
| code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4056 |
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4285 |
| db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3049 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6705 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6639 |
| files.lua | skip | io library | 0 |
| gc.lua | skip | collectgarbage / finalisers | 0 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1734 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1510 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1774 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1552 |
| main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | arith type error | 3820 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6758 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5586 |
| sort.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1121 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3652 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2009 |
| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 527 |
| math.lua | fail | arith type error | 3789 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6939 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5707 |
| sort.lua | timeout | per-test timeout | 8007 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3846 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2116 |
| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 534 |

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._
- 2026-04-24: lua: scoreboard iteration — `table.getn`/`setn`/`foreach`/`foreachi` (Lua 5.0-era), `string.reverse`. `sort.lua` unblocked past `getn`-undef; now times out on the 30k-element sort body (insertion sort too slow). 13 fail / 3 timeout / 0 pass.
- 2026-04-24: lua: scoreboard iteration — parser consumes trailing `;` after `return`; added `collectgarbage`/`setfenv`/`getfenv`/`T` stubs. All parse errors and undefined-symbol failures eliminated — every runnable test now executes deep into the script. Failure mix: **11× assertion failed**, 2× timeout, 2× call-non-fn, 1× arith. Still 0/16 pass but the remaining work is substantive (stdlib fidelity vs the exact PUC-Rio assertions).
- 2026-04-24: lua: scoreboard iteration — trailing-dot number literals (`5.`), preload stdlibs in `package.loaded` (`string`/`math`/`table`/`io`/`os`/`coroutine`/`package`/`_G`), `arg` stub, `debug` module stub. Assertion-failure count 4→**8**, parse errors 3→**1**, call-non-fn stable, module-not-found gone.
- 2026-04-24: lua: scoreboard iteration — **vararg `...` transpile**. Parser already emitted `(lua-vararg)`; transpile now: (a) binds `__varargs` in function body when `is-vararg`, (b) emits `__varargs` for `...` uses; `lua-varargs`/`lua-spread-last-multi` runtime helpers spread multi in last call-arg and last table-pos positions. Eliminated all 6× "transpile: unsupported" failures; top-5 now all real asserts. 353 unit tests.