From 1b34d41b3376e2e4310dd8cf169a17cfb05533db Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 25 Apr 2026 00:31:03 +0000 Subject: [PATCH] lua: unpack treats explicit nil i/j as missing (defaults to 1 and #t) --- lib/lua/runtime.sx | 36 +++++++++++++++++--------------- lib/lua/scoreboard.json | 46 ++++++++++++++++++++++------------------- lib/lua/scoreboard.md | 33 +++++++++++++++-------------- plans/lua-on-sx.md | 1 + 4 files changed, 62 insertions(+), 54 deletions(-) diff --git a/lib/lua/runtime.sx b/lib/lua/runtime.sx index 3c148e08..cf711f0f 100644 --- a/lib/lua/runtime.sx +++ b/lib/lua/runtime.sx @@ -1552,23 +1552,25 @@ (define lua-unpack (fn (&rest args) - (let ((t (first args)) - (i (if (> (len args) 1) (nth args 1) 1)) - (j (if (> (len args) 2) (nth args 2) (lua-len (first args))))) - (cond - ((> i j) nil) - (else - (let ((out (list (quote lua-multi)))) - (begin - (define - loop - (fn (k) - (when (<= k j) - (begin - (set! out (append out (list (get t (str k))))) - (loop (+ k 1)))))) - (loop i) - out))))))) + (let ((t (first args))) + (let ((i-raw (if (> (len args) 1) (nth args 1) nil)) + (j-raw (if (> (len args) 2) (nth args 2) nil))) + (let ((i (if (= i-raw nil) 1 i-raw)) + (j (if (= j-raw nil) (lua-len t) j-raw))) + (cond + ((> i j) nil) + (else + (let ((out (list (quote lua-multi)))) + (begin + (define + loop + (fn (k) + (when (<= k j) + (begin + (set! out (append out (list (get t (str k))))) + (loop (+ k 1)))))) + (loop i) + out))))))))) (define lua-table-maxn diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index ef127e69..1a4fbd86 100644 --- a/lib/lua/scoreboard.json +++ b/lib/lua/scoreboard.json @@ -1,8 +1,8 @@ { "totals": { "pass": 1, - "fail": 7, - "timeout": 8, + "fail": 9, + "timeout": 6, "skip": 8, "total": 24, "runnable": 16, @@ -11,16 +11,20 @@ "top_failure_modes": [ [ "timeout", - 8 + 6 ], [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - 4 + 5 ], [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", 2 ], + [ + "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", + 1 + ], [ "undefined symbol: fat\\", 1 @@ -41,21 +45,21 @@ }, { "name": "attrib.lua", - "status": "timeout", - "reason": "per-test timeout", - "ms": 8000 + "status": "fail", + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'C' not found\\\\\\\"\\", + "ms": 6985 }, { "name": "big.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8007 + "ms": 8008 }, { "name": "calls.lua", "status": "fail", "reason": "undefined symbol: fat\\", - "ms": 6732 + "ms": 5721 }, { "name": "checktable.lua", @@ -67,7 +71,7 @@ "name": "closure.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8005 + "ms": 8008 }, { "name": "code.lua", @@ -91,7 +95,7 @@ "name": "errors.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4579 + "ms": 4667 }, { "name": "events.lua", @@ -115,13 +119,13 @@ "name": "literals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 2829 + "ms": 2950 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 2598 + "ms": 2366 }, { "name": "main.lua", @@ -133,19 +137,19 @@ "name": "math.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 6606 + "ms": 4991 }, { "name": "nextvar.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8008 + "ms": 8007 }, { "name": "pm.lua", - "status": "timeout", - "reason": "per-test timeout", - "ms": 8009 + "status": "fail", + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", + "ms": 6697 }, { "name": "sort.lua", @@ -157,19 +161,19 @@ "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6228 + "ms": 4493 }, { "name": "vararg.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3087 + "ms": 2541 }, { "name": "verybig.lua", "status": "pass", "reason": "", - "ms": 1058 + "ms": 1187 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index 50da0d66..a1db5ec8 100644 --- a/lib/lua/scoreboard.md +++ b/lib/lua/scoreboard.md @@ -1,13 +1,14 @@ # Lua-on-SX conformance scoreboard **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 -- **8x** timeout -- **4x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ +- **6x** timeout +- **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **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\ ## 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 | | api.lua | skip | requires testC (C debug library) | 0 | -| attrib.lua | timeout | per-test timeout | 8000 | -| big.lua | timeout | per-test timeout | 8007 | -| calls.lua | fail | undefined symbol: fat\ | 6732 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'C' not found\\\"\ | 6985 | +| big.lua | timeout | per-test timeout | 8008 | +| calls.lua | fail | undefined symbol: fat\ | 5721 | | 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 | | constructs.lua | timeout | per-test timeout | 8007 | | 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 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2829 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 2598 | +| 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 | 2366 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 6606 | -| nextvar.lua | timeout | per-test timeout | 8008 | -| pm.lua | timeout | per-test timeout | 8009 | +| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 4991 | +| nextvar.lua | timeout | per-test timeout | 8007 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6697 | | sort.lua | timeout | per-test timeout | 8007 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6228 | -| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3087 | -| verybig.lua | pass | - | 1058 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4493 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2541 | +| verybig.lua | pass | - | 1187 | diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index 719fa5c8..929b6a93 100644 --- a/plans/lua-on-sx.md +++ b/plans/lua-on-sx.md @@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log. _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 — `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).