diff --git a/lib/lua/runtime.sx b/lib/lua/runtime.sx index f0f99c67..14bf4aab 100644 --- a/lib/lua/runtime.sx +++ b/lib/lua/runtime.sx @@ -1500,9 +1500,12 @@ (define lua-loadstring (fn (src) - (let ((compiled (lua-transpile src))) - (fn (&rest args) - (eval-expr (list (make-symbol "let") (list) compiled)))))) + (guard + (e (true (list (quote lua-multi) nil (str e)))) + (let ((compiled (lua-transpile src))) + (let ((wrapped (list (make-symbol "fn") (list (make-symbol "&rest") (make-symbol "__args")) + (list (make-symbol "let") (list) compiled)))) + (eval-expr wrapped)))))) (define loadstring lua-loadstring) (define load lua-loadstring) diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index ea3370b7..9563b5d7 100644 --- a/lib/lua/scoreboard.json +++ b/lib/lua/scoreboard.json @@ -11,7 +11,7 @@ "top_failure_modes": [ [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - 11 + 10 ], [ "timeout", @@ -20,6 +20,10 @@ [ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", 2 + ], + [ + "other: Unhandled exception: \\\"Not callable: nil (kont=10 frames)\\", + 1 ] ], "results": [ @@ -39,19 +43,19 @@ "name": "attrib.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 5800 + "ms": 5841 }, { "name": "big.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8007 + "ms": 8008 }, { "name": "calls.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4877 + "ms": 4666 }, { "name": "checktable.lua", @@ -63,7 +67,7 @@ "name": "closure.lua", "status": "timeout", "reason": "per-test timeout", - "ms": 8007 + "ms": 8008 }, { "name": "code.lua", @@ -75,7 +79,7 @@ "name": "constructs.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4365 + "ms": 4155 }, { "name": "db.lua", @@ -86,14 +90,14 @@ { "name": "errors.lua", "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3188 + "reason": "other: Unhandled exception: \\\"Not callable: nil (kont=10 frames)\\", + "ms": 3155 }, { "name": "events.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 7039 + "ms": 6725 }, { "name": "files.lua", @@ -111,13 +115,13 @@ "name": "literals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 1873 + "ms": 1787 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 1713 + "ms": 1539 }, { "name": "main.lua", @@ -129,19 +133,19 @@ "name": "math.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4010 + "ms": 3892 }, { "name": "nextvar.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6632 + "ms": 6711 }, { "name": "pm.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 5609 + "ms": 5734 }, { "name": "sort.lua", @@ -153,19 +157,19 @@ "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3655 + "ms": 3937 }, { "name": "vararg.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 2039 + "ms": 2096 }, { "name": "verybig.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 537 + "ms": 533 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index 86457ac2..6823bc66 100644 --- a/lib/lua/scoreboard.md +++ b/lib/lua/scoreboard.md @@ -5,9 +5,10 @@ fail=13 timeout=3 skip=8 total=24 ## Top failure modes -- **11x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ +- **10x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ - **3x** timeout - **2x** other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio +- **1x** other: Unhandled exception: \"Not callable: nil (kont=10 frames)\ ## Per-test results @@ -15,25 +16,25 @@ fail=13 timeout=3 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!\\\"\ | 5800 | -| big.lua | timeout | per-test timeout | 8007 | -| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4877 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5841 | +| big.lua | timeout | per-test timeout | 8008 | +| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4666 | | checktable.lua | skip | internal debug helpers | 0 | -| closure.lua | timeout | per-test timeout | 8007 | +| closure.lua | timeout | per-test timeout | 8008 | | code.lua | skip | bytecode inspection via debug library | 0 | -| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4365 | +| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4155 | | db.lua | skip | debug library | 0 | -| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3188 | -| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7039 | +| errors.lua | fail | other: Unhandled exception: \"Not callable: nil (kont=10 frames)\ | 3155 | +| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6725 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1873 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1713 | +| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1787 | +| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1539 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4010 | -| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6632 | -| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5609 | +| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3892 | +| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6711 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5734 | | sort.lua | timeout | per-test timeout | 8007 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3655 | -| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2039 | -| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 537 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3937 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2096 | +| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 533 | diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index b23a92a6..343ac66c 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-24: lua: scoreboard iteration — **`loadstring` error propagation**. When `loadstring(s)()` was implemented as `eval-expr ( (let () compiled))`, SX's `eval-expr` wrapped any propagated `raise` as "Unhandled exception: X" — so `error('hi')` inside a loadstring'd chunk came out as that wrapped string instead of the clean `"hi"` Lua expects. Fix: transpile source once into a lambda AST, `eval-expr` it ONCE to get a callable fn value, return that — subsequent calls propagate raises cleanly. Guarded parse-failure path returns `(nil, err)` per Lua convention. vararg.lua now runs past assert #18; errors.lua past parse stage. - 2026-04-24: lua: scoreboard iteration — `table.sort` O(n²) insertion-sort → **quicksort** (Lomuto partition). 1000-element sorts finish in ms; but `sort.lua` uses 30k elements and still times out even at 90s (metamethod-heavy interpreter overhead). Correctness verified on 1000/5000 element random arrays. - 2026-04-24: lua: scoreboard iteration — `dostring(s)` alias for `loadstring(s)()` (Lua 5.0 compat used by literals.lua). Diagnosed `locals.lua` call-non-fn at call #18 → `getfenv/setfenv` stub-return pattern fails `assert(getfenv(foo("")) == a)` (need real env tracking, deferred). Tokenizer long-string-leading-NL rule verified correct. - 2026-04-24: lua: scoreboard iteration — Lua 5.0-style `arg` auto-binding inside vararg functions (some PUC-Rio tests still rely on it). `lua-varargs-arg-table` builds `{1=v1, 2=v2, …, n=count}`; transpile adds `arg` binding alongside `__varargs` when `is-vararg`. Diagnosis done with assert-counter instrumentation — literals.lua fails at #4 (long-string NL rule), vararg.lua was at #2 (arg table — FIXED), attrib.lua at #9, locals.lua now past asserts into call-non-fn. 360 tests.