diff --git a/lib/lua/parser.sx b/lib/lua/parser.sx index 9611ea45..7195ee65 100644 --- a/lib/lua/parser.sx +++ b/lib/lua/parser.sx @@ -211,6 +211,8 @@ (lua-tok-type t) " " (lua-tok-value t)))))))) + (define parse-pow-chain + (fn () (let ((lhs (parse-primary))) (parse-binop-rhs 10 lhs)))) (set! parse-unary (fn @@ -228,7 +230,7 @@ (begin (advance-tok!) (list (quote lua-unop) "not" (parse-unary)))) - (else (parse-primary))))) + (else (parse-pow-chain))))) (define parse-binop-rhs (fn diff --git a/lib/lua/scoreboard.json b/lib/lua/scoreboard.json index 58f05353..a9d54092 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!\\\\\\\"\\", - 10 + 9 ], [ "timeout", @@ -21,6 +21,10 @@ "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", 2 ], + [ + "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", + 1 + ], [ "other: Unhandled exception: \\\"Not callable: nil (kont=10 frames)\\", 1 @@ -43,7 +47,7 @@ "name": "attrib.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 5719 + "ms": 6000 }, { "name": "big.lua", @@ -55,7 +59,7 @@ "name": "calls.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4548 + "ms": 4946 }, { "name": "checktable.lua", @@ -78,8 +82,8 @@ { "name": "constructs.lua", "status": "fail", - "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4153 + "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to compare incompat", + "ms": 4533 }, { "name": "db.lua", @@ -91,13 +95,13 @@ "name": "errors.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Not callable: nil (kont=10 frames)\\", - "ms": 2938 + "ms": 3217 }, { "name": "events.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6598 + "ms": 7215 }, { "name": "files.lua", @@ -115,13 +119,13 @@ "name": "literals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 1859 + "ms": 1901 }, { "name": "locals.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 1687 + "ms": 1693 }, { "name": "main.lua", @@ -133,19 +137,19 @@ "name": "math.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 3774 + "ms": 4095 }, { "name": "nextvar.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 6637 + "ms": 7177 }, { "name": "pm.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 5886 + "ms": 6048 }, { "name": "sort.lua", @@ -157,19 +161,19 @@ "name": "strings.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 4040 + "ms": 3990 }, { "name": "vararg.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", - "ms": 2064 + "ms": 2249 }, { "name": "verybig.lua", "status": "fail", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", - "ms": 545 + "ms": 572 } ] } \ No newline at end of file diff --git a/lib/lua/scoreboard.md b/lib/lua/scoreboard.md index 1c80f585..eb5d76a2 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 -- **10x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ +- **9x** 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: \"Unhandled exception: \\\"lua: attempt to compare incompat - **1x** other: Unhandled exception: \"Not callable: nil (kont=10 frames)\ ## Per-test results @@ -16,25 +17,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!\\\"\ | 5719 | +| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6000 | | big.lua | timeout | per-test timeout | 8006 | -| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4548 | +| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4946 | | checktable.lua | skip | internal debug helpers | 0 | | closure.lua | timeout | per-test timeout | 8003 | | code.lua | skip | bytecode inspection via debug library | 0 | -| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4153 | +| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to compare incompat | 4533 | | db.lua | skip | debug library | 0 | -| errors.lua | fail | other: Unhandled exception: \"Not callable: nil (kont=10 frames)\ | 2938 | -| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6598 | +| errors.lua | fail | other: Unhandled exception: \"Not callable: nil (kont=10 frames)\ | 3217 | +| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7215 | | files.lua | skip | io library | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 | -| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1859 | -| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1687 | +| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1901 | +| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1693 | | main.lua | skip | standalone interpreter driver | 0 | -| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3774 | -| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6637 | -| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5886 | +| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4095 | +| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7177 | +| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6048 | | sort.lua | timeout | per-test timeout | 8007 | -| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4040 | -| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2064 | -| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 545 | +| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3990 | +| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2249 | +| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 572 | diff --git a/lib/lua/test.sh b/lib/lua/test.sh index 09d87cae..c9f8908c 100755 --- a/lib/lua/test.sh +++ b/lib/lua/test.sh @@ -928,6 +928,14 @@ cat > "$TMPFILE" << 'EPOCHS' (epoch 1831) (eval "(lua-eval-ast \"if \\\"\\\\09912\\\" == \\\"c12\\\" then return 1 else return 0 end\")") +;; ── Unary-minus / ^ precedence (Lua spec: ^ tighter than -) ── +(epoch 1840) +(eval "(lua-eval-ast \"return -2^2\")") +(epoch 1841) +(eval "(lua-eval-ast \"return 2^3^2\")") +(epoch 1842) +(eval "(lua-eval-ast \"if -2^2 == -4 then return 1 else return 0 end\")") + EPOCHS OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) @@ -1401,6 +1409,11 @@ check 1821 "arg[i] access" '60' check 1830 "\\65 → A" '"A"' check 1831 "\\099 + 12 → c12" '1' +# ── Unary-minus / ^ precedence (Lua: ^ tighter than unary -) ── +check 1840 "-2^2 = -4" '-4' +check 1841 "2^3^2 = 512 (right-assoc)" '512' +check 1842 "-2^2 == -4 true" '1' + TOTAL=$((PASS + FAIL)) if [ $FAIL -eq 0 ]; then echo "ok $PASS/$TOTAL Lua-on-SX tests passed" diff --git a/plans/lua-on-sx.md b/plans/lua-on-sx.md index 082f9ab1..29a28e5d 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 — **unary-minus / `^` precedence fix**. Per Lua spec, `^` binds tighter than unary `-`, so `-2^2` should parse as `-(2^2) = -4`, not `(-2)^2 = 4`. My parser recursed into `parse-unary` and then let `^` bind to the already-negated operand. Added `parse-pow-chain` helper and changed the `else` branch of `parse-unary` to parse a primary + `^`-chain before returning; unary operators now wrap the full `^`-chain. Fixed `constructs.lua` past assert #3 (moved to compare-incompatible). 365/365 green (+3 precedence tests). - 2026-04-24: lua: scoreboard iteration — `lua-byte-to-char` regression fix. My previous change returned 2-char strings (`"\a"` etc.) for bytes that SX string literals can't express (0, 7, 8, 11, 12, 14–31, 127+), breaking `'a\0a'` length from 3 → 4. Now only 9/10/13 and printable 32-126 produce real bytes; others use a single `"?"` placeholder so `string.len` stays correct. literals.lua back to failing at assert #4 (was regressed to #2). - 2026-04-24: lua: scoreboard iteration — **decimal string escapes** `\ddd` (1-3 digits). Tokenizer `read-string` previously fell through to literal for digits, so `"\65"` came out as `"65"` not `"A"`. Added `read-decimal-escape!` consuming up to 3 digits while keeping value ≤255, plus `\a`/`\b`/`\f`/`\v` control escapes and `lua-byte-to-char` ASCII lookup. 362 tests (+2 escape tests). - 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.