lua: unpack treats explicit nil i/j as missing (defaults to 1 and #t)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 00:31:03 +00:00
parent fd32bcf547
commit 1b34d41b33
4 changed files with 62 additions and 54 deletions

View File

@@ -1552,23 +1552,25 @@
(define (define
lua-unpack lua-unpack
(fn (&rest args) (fn (&rest args)
(let ((t (first args)) (let ((t (first args)))
(i (if (> (len args) 1) (nth args 1) 1)) (let ((i-raw (if (> (len args) 1) (nth args 1) nil))
(j (if (> (len args) 2) (nth args 2) (lua-len (first args))))) (j-raw (if (> (len args) 2) (nth args 2) nil)))
(cond (let ((i (if (= i-raw nil) 1 i-raw))
((> i j) nil) (j (if (= j-raw nil) (lua-len t) j-raw)))
(else (cond
(let ((out (list (quote lua-multi)))) ((> i j) nil)
(begin (else
(define (let ((out (list (quote lua-multi))))
loop (begin
(fn (k) (define
(when (<= k j) loop
(begin (fn (k)
(set! out (append out (list (get t (str k))))) (when (<= k j)
(loop (+ k 1)))))) (begin
(loop i) (set! out (append out (list (get t (str k)))))
out))))))) (loop (+ k 1))))))
(loop i)
out)))))))))
(define (define
lua-table-maxn lua-table-maxn

View File

@@ -1,8 +1,8 @@
{ {
"totals": { "totals": {
"pass": 1, "pass": 1,
"fail": 7, "fail": 9,
"timeout": 8, "timeout": 6,
"skip": 8, "skip": 8,
"total": 24, "total": 24,
"runnable": 16, "runnable": 16,
@@ -11,16 +11,20 @@
"top_failure_modes": [ "top_failure_modes": [
[ [
"timeout", "timeout",
8 6
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
4 5
], ],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
2 2
], ],
[
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
1
],
[ [
"undefined symbol: fat\\", "undefined symbol: fat\\",
1 1
@@ -41,21 +45,21 @@
}, },
{ {
"name": "attrib.lua", "name": "attrib.lua",
"status": "timeout", "status": "fail",
"reason": "per-test timeout", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\",
"ms": 8000 "ms": 6985
}, },
{ {
"name": "big.lua", "name": "big.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8007 "ms": 8008
}, },
{ {
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "undefined symbol: fat\\", "reason": "undefined symbol: fat\\",
"ms": 6732 "ms": 5721
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -67,7 +71,7 @@
"name": "closure.lua", "name": "closure.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8005 "ms": 8008
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -91,7 +95,7 @@
"name": "errors.lua", "name": "errors.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4579 "ms": 4667
}, },
{ {
"name": "events.lua", "name": "events.lua",
@@ -115,13 +119,13 @@
"name": "literals.lua", "name": "literals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2829 "ms": 2950
}, },
{ {
"name": "locals.lua", "name": "locals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 2598 "ms": 2366
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -133,19 +137,19 @@
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 6606 "ms": 4991
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8008 "ms": 8007
}, },
{ {
"name": "pm.lua", "name": "pm.lua",
"status": "timeout", "status": "fail",
"reason": "per-test timeout", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 8009 "ms": 6697
}, },
{ {
"name": "sort.lua", "name": "sort.lua",
@@ -157,19 +161,19 @@
"name": "strings.lua", "name": "strings.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6228 "ms": 4493
}, },
{ {
"name": "vararg.lua", "name": "vararg.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3087 "ms": 2541
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "pass", "status": "pass",
"reason": "", "reason": "",
"ms": 1058 "ms": 1187
} }
] ]
} }

View File

@@ -1,13 +1,14 @@
# Lua-on-SX conformance scoreboard # Lua-on-SX conformance scoreboard
**Pass rate:** 1/16 runnable (6.2%) **Pass rate:** 1/16 runnable (6.2%)
fail=7 timeout=8 skip=8 total=24 fail=9 timeout=6 skip=8 total=24
## Top failure modes ## Top failure modes
- **8x** timeout - **6x** timeout
- **4x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio
- **1x** other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\
- **1x** undefined symbol: fat\ - **1x** undefined symbol: fat\
## Per-test results ## Per-test results
@@ -16,25 +17,25 @@ fail=7 timeout=8 skip=8 total=24
|---|---|---|---:| |---|---|---|---:|
| all.lua | skip | driver uses dofile to chain other tests | 0 | | all.lua | skip | driver uses dofile to chain other tests | 0 |
| api.lua | skip | requires testC (C debug library) | 0 | | api.lua | skip | requires testC (C debug library) | 0 |
| attrib.lua | timeout | per-test timeout | 8000 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6985 |
| big.lua | timeout | per-test timeout | 8007 | | big.lua | timeout | per-test timeout | 8008 |
| calls.lua | fail | undefined symbol: fat\ | 6732 | | calls.lua | fail | undefined symbol: fat\ | 5721 |
| checktable.lua | skip | internal debug helpers | 0 | | checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | timeout | per-test timeout | 8005 | | closure.lua | timeout | per-test timeout | 8008 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | timeout | per-test timeout | 8007 | | constructs.lua | timeout | per-test timeout | 8007 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4579 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4667 |
| events.lua | timeout | per-test timeout | 8007 | | events.lua | timeout | per-test timeout | 8007 |
| files.lua | skip | io library | 0 | | files.lua | skip | io library | 0 |
| gc.lua | skip | collectgarbage / finalisers | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2829 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2950 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 2598 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 2366 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 6606 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4991 |
| nextvar.lua | timeout | per-test timeout | 8008 | | nextvar.lua | timeout | per-test timeout | 8007 |
| pm.lua | timeout | per-test timeout | 8009 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6697 |
| sort.lua | timeout | per-test timeout | 8007 | | sort.lua | timeout | per-test timeout | 8007 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6228 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4493 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3087 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2541 |
| verybig.lua | pass | - | 1058 | | verybig.lua | pass | - | 1187 |

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._ _Newest first. Agent appends on every commit._
- 2026-04-25: lua: scoreboard iteration — `unpack(t, i, j)` now treats explicit nil for `i` or `j` as missing (defaults to 1 and `#t`). vararg.lua-style `unpack(args, 1, args.n)` works when `args.n` is nil. Asserts 4→5, timeouts 8→6 (more tests reach assertions instead of timing out). 393/393 green.
- 2026-04-25: lua: scoreboard iteration — extended `string.format`. New `%x`/`%X`/`%o` (hex/octal), `%c` (codepoint→char via `lua-char-one`), `%q` (basic quote), width N (`%5d`), zero-pad (`%05d`), left-align (`%-5d`), `%.Ns` precision. Helpers `lua-fmt-pad` and `lua-fmt-int-base`. 393/393 green (+6 format tests). - 2026-04-25: lua: scoreboard iteration — extended `string.format`. New `%x`/`%X`/`%o` (hex/octal), `%c` (codepoint→char via `lua-char-one`), `%q` (basic quote), width N (`%5d`), zero-pad (`%05d`), left-align (`%-5d`), `%.Ns` precision. Helpers `lua-fmt-pad` and `lua-fmt-int-base`. 393/393 green (+6 format tests).
- 2026-04-25: lua: scoreboard iteration — `lua-eval-ast` now SKIPS the top-level guard when the parsed chunk has no top-level `return` (recursive AST walk via `lua-has-top-return?` that descends through control-flow but stops at function-body boundaries). Without the guard, top-level user defines leak to the SX top env, and `loadstring`-captured closures can find them. Verified: `function fat(x)...loadstring("return fat(...)")...end; x=fat(5)` works (was undefined). Most PUC-Rio tests still have top-level returns elsewhere, so they still need the guard. Scoreboard unchanged at 1/16 but unblocks future work. - 2026-04-25: lua: scoreboard iteration — `lua-eval-ast` now SKIPS the top-level guard when the parsed chunk has no top-level `return` (recursive AST walk via `lua-has-top-return?` that descends through control-flow but stops at function-body boundaries). Without the guard, top-level user defines leak to the SX top env, and `loadstring`-captured closures can find them. Verified: `function fat(x)...loadstring("return fat(...)")...end; x=fat(5)` works (was undefined). Most PUC-Rio tests still have top-level returns elsewhere, so they still need the guard. Scoreboard unchanged at 1/16 but unblocks future work.
- 2026-04-25: lua: scoreboard iteration — math fns now error on bad/missing args (was silently returning 0). New `lua-math-num "name" x` validator wraps `abs`/`ceil`/`floor`/`sqrt`/`exp`/`sin`/`cos`/`tan`/`asin`/`acos`/`atan`/`atan2`/`pow`. errors.lua moves past assert #4 (`pcall(math.sin)` now returns false+err as expected). - 2026-04-25: lua: scoreboard iteration — math fns now error on bad/missing args (was silently returning 0). New `lua-math-num "name" x` validator wraps `abs`/`ceil`/`floor`/`sqrt`/`exp`/`sin`/`cos`/`tan`/`asin`/`acos`/`atan`/`atan2`/`pow`. errors.lua moves past assert #4 (`pcall(math.sin)` now returns false+err as expected).