lua: vararg ... transpile (spreads in call+table last pos); 6x transpile-unsup fixed +6 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 19:38:22 +00:00
parent cf4d19fb94
commit 743e0bae87
6 changed files with 177 additions and 69 deletions

View File

@@ -259,9 +259,24 @@
((f (first fs))) ((f (first fs)))
(cond (cond
((= (first f) "pos") ((= (first f) "pos")
(begin (let ((v (nth f 1)))
(set! t (assoc t (str array-idx) (nth f 1))) (cond
(set! array-idx (+ array-idx 1)))) ((and (lua-multi? v) (= (len fs) 1))
(begin
(define
spread-loop
(fn (i)
(when (< i (len v))
(begin
(set! t (assoc t (str array-idx) (nth v i)))
(set! array-idx (+ array-idx 1))
(spread-loop (+ i 1))))))
(spread-loop 1)))
(else
(let ((val (if (lua-multi? v) (lua-first v) v)))
(begin
(set! t (assoc t (str array-idx) val))
(set! array-idx (+ array-idx 1))))))))
((= (first f) "kv") ((= (first f) "kv")
(let (let
((k (nth f 1)) (v (nth f 2))) ((k (nth f 1)) (v (nth f 2)))
@@ -384,23 +399,48 @@
(define sx-apply-ref apply) (define sx-apply-ref apply)
(define
lua-spread-last-multi
(fn (rargs)
(cond
((= (len rargs) 0) rargs)
(else
(let ((last-idx (- (len rargs) 1)))
(let ((last (nth rargs last-idx)))
(cond
((lua-multi? last)
(let ((init (lua-pack-build rargs 0)))
(append
(if (> last-idx 0) (lua-init-before rargs 0 last-idx) (list))
(rest last))))
(else rargs))))))))
(define
lua-init-before
(fn (rargs i limit)
(if (>= i limit)
(list)
(cons (nth rargs i) (lua-init-before rargs (+ i 1) limit)))))
(define (define
lua-apply lua-apply
(fn (fn
(f rargs) (f rargs-in)
(let (let
((n (len rargs))) ((rargs (lua-spread-last-multi rargs-in)))
(cond (let
((= n 0) (f)) ((n (len rargs)))
((= n 1) (f (nth rargs 0))) (cond
((= n 2) (f (nth rargs 0) (nth rargs 1))) ((= n 0) (f))
((= n 3) (f (nth rargs 0) (nth rargs 1) (nth rargs 2))) ((= n 1) (f (nth rargs 0)))
((= n 4) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3))) ((= n 2) (f (nth rargs 0) (nth rargs 1)))
((= n 5) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4))) ((= n 3) (f (nth rargs 0) (nth rargs 1) (nth rargs 2)))
((= n 6) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5))) ((= n 4) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3)))
((= n 7) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5) (nth rargs 6))) ((= n 5) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4)))
((= n 8) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5) (nth rargs 6) (nth rargs 7))) ((= n 6) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5)))
(else (sx-apply-ref f rargs)))))) ((= n 7) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5) (nth rargs 6)))
((= n 8) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5) (nth rargs 6) (nth rargs 7)))
(else (sx-apply-ref f rargs)))))))
(define (define
lua-call lua-call
@@ -1441,3 +1481,15 @@
(define _G {}) (define _G {})
(define _VERSION "Lua 5.1") (define _VERSION "Lua 5.1")
(define
lua-varargs
(fn (args skip)
(cons (quote lua-multi) (lua-varargs-tail args skip))))
(define
lua-varargs-tail
(fn (args i)
(if (>= i (len args))
(list)
(cons (nth args i) (lua-varargs-tail args (+ i 1))))))

View File

@@ -9,13 +9,9 @@
"pass_rate": 0.0 "pass_rate": 0.0
}, },
"top_failure_modes": [ "top_failure_modes": [
[
"transpile: unsupported node",
6
],
[ [
"other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
4 5
], ],
[ [
"parse error", "parse error",
@@ -25,9 +21,29 @@
"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 'string' not found\\\\",
1
],
[ [
"timeout", "timeout",
1 1
],
[
"undefined symbol: collectgarbage\\",
1
],
[
"undefined symbol: setfenv\\",
1
],
[
"undefined symbol: T\\",
1
],
[
"undefined symbol: arg\\",
1
] ]
], ],
"results": [ "results": [
@@ -46,20 +62,20 @@
{ {
"name": "attrib.lua", "name": "attrib.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: module 'string' not found\\\\",
"ms": 5378 "ms": 5744
}, },
{ {
"name": "big.lua", "name": "big.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8007 "ms": 8004
}, },
{ {
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4393 "ms": 4612
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -70,8 +86,8 @@
{ {
"name": "closure.lua", "name": "closure.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "undefined symbol: collectgarbage\\",
"ms": 5425 "ms": 6160
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -83,7 +99,7 @@
"name": "constructs.lua", "name": "constructs.lua",
"status": "fail", "status": "fail",
"reason": "parse error", "reason": "parse error",
"ms": 2509 "ms": 2720
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -95,13 +111,13 @@
"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": 2934 "ms": 3172
}, },
{ {
"name": "events.lua", "name": "events.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "undefined symbol: setfenv\\",
"ms": 6455 "ms": 6976
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -125,7 +141,7 @@
"name": "locals.lua", "name": "locals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 1554 "ms": 1707
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -137,43 +153,43 @@
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "parse error", "reason": "parse error",
"ms": 2378 "ms": 2475
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "undefined symbol: T\\",
"ms": 5918 "ms": 6743
}, },
{ {
"name": "pm.lua", "name": "pm.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5658 "ms": 5928
}, },
{ {
"name": "sort.lua", "name": "sort.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": 1145 "ms": 1169
}, },
{ {
"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": 3696 "ms": 3872
}, },
{ {
"name": "vararg.lua", "name": "vararg.lua",
"status": "fail", "status": "fail",
"reason": "transpile: unsupported node", "reason": "undefined symbol: arg\\",
"ms": 1901 "ms": 2140
}, },
{ {
"name": "verybig.lua", "name": "verybig.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": 533 "ms": 553
} }
] ]
} }

View File

@@ -5,11 +5,15 @@ fail=15 timeout=1 skip=8 total=24
## Top failure modes ## Top failure modes
- **6x** transpile: unsupported node - **5x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **4x** other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\
- **3x** parse error - **3x** parse error
- **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 'string' not found\\
- **1x** timeout - **1x** timeout
- **1x** undefined symbol: collectgarbage\
- **1x** undefined symbol: setfenv\
- **1x** undefined symbol: T\
- **1x** undefined symbol: arg\
## Per-test results ## Per-test results
@@ -17,25 +21,25 @@ fail=15 timeout=1 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 | fail | transpile: unsupported node | 5378 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: module 'string' not found\\ | 5744 |
| big.lua | timeout | per-test timeout | 8007 | | big.lua | timeout | per-test timeout | 8004 |
| calls.lua | fail | transpile: unsupported node | 4393 | | calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4612 |
| checktable.lua | skip | internal debug helpers | 0 | | checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | fail | transpile: unsupported node | 5425 | | closure.lua | fail | undefined symbol: collectgarbage\ | 6160 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | fail | parse error | 2509 | | constructs.lua | fail | parse error | 2720 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2934 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3172 |
| events.lua | fail | transpile: unsupported node | 6455 | | events.lua | fail | undefined symbol: setfenv\ | 6976 |
| 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 | parse error | 1786 | | literals.lua | fail | parse error | 1786 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1554 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1707 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | parse error | 2378 | | math.lua | fail | parse error | 2475 |
| nextvar.lua | fail | transpile: unsupported node | 5918 | | nextvar.lua | fail | undefined symbol: T\ | 6743 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5658 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5928 |
| sort.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1145 | | sort.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1169 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3696 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3872 |
| vararg.lua | fail | transpile: unsupported node | 1901 | | vararg.lua | fail | undefined symbol: arg\ | 2140 |
| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 533 | | verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 553 |

View File

@@ -888,6 +888,20 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1604) (epoch 1604)
(eval "(lua-eval-ast \"package.preload.noret = function() end local r = require(\\\"noret\\\") return type(r)\")") (eval "(lua-eval-ast \"package.preload.noret = function() end local r = require(\\\"noret\\\") return type(r)\")")
;; ── Phase 7: vararg `...` (scoreboard iteration) ──────────────
(epoch 1700)
(eval "(lua-eval-ast \"local function f(...) return ... end local a, b, c = f(1, 2, 3) return a + b + c\")")
(epoch 1701)
(eval "(lua-eval-ast \"local function f(...) local t = {...} return t[2] end return f(10, 20, 30)\")")
(epoch 1702)
(eval "(lua-eval-ast \"local function f(a, ...) return a + select(\\\"#\\\", ...) end return f(10, 1, 2, 3)\")")
(epoch 1703)
(eval "(lua-eval-ast \"local function f(...) return select(2, ...) end local a, b = f(10, 20, 30) return a + b\")")
(epoch 1704)
(eval "(lua-eval-ast \"local function sum(...) local s = 0 for _, v in ipairs({...}) do s = s + v end return s end return sum(1, 2, 3, 4, 5)\")")
(epoch 1705)
(eval "(lua-eval-ast \"local function f(a, b, ...) return a * 100 + b * 10 + select(\\\"#\\\", ...) end return f(7, 8, 1, 2, 3)\")")
EPOCHS EPOCHS
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1336,6 +1350,14 @@ check 1602 "require unknown module errors" '1'
check 1603 "package.loaded populated" '42' check 1603 "package.loaded populated" '42'
check 1604 "nil return caches as true" '"boolean"' check 1604 "nil return caches as true" '"boolean"'
# ── Phase 7: vararg `...` (scoreboard iteration) ──────────────
check 1700 "f(...) return ... unpack" '6'
check 1701 "{...} table from vararg" '20'
check 1702 "f(a, ...) + select(#,...)" '13'
check 1703 "select(2, ...) unpack" '50'
check 1704 "sum via ipairs({...})" '15'
check 1705 "f(a, b, ...) mixed" '783'
TOTAL=$((PASS + FAIL)) TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL Lua-on-SX tests passed" echo "ok $PASS/$TOTAL Lua-on-SX tests passed"

View File

@@ -18,8 +18,7 @@
((= tag (quote lua-true)) true) ((= tag (quote lua-true)) true)
((= tag (quote lua-false)) false) ((= tag (quote lua-false)) false)
((= tag (quote lua-name)) (make-symbol (nth node 1))) ((= tag (quote lua-name)) (make-symbol (nth node 1)))
((= tag (quote lua-vararg)) ((= tag (quote lua-vararg)) (make-symbol "__varargs"))
(error "lua-transpile: ... not yet supported"))
((= tag (quote lua-binop)) (lua-tx-binop node)) ((= tag (quote lua-binop)) (lua-tx-binop node))
((= tag (quote lua-unop)) (lua-tx-unop node)) ((= tag (quote lua-unop)) (lua-tx-unop node))
((= tag (quote lua-call)) (lua-tx-call node)) ((= tag (quote lua-call)) (lua-tx-call node))
@@ -174,6 +173,13 @@
(list (make-symbol "lua-arg") (make-symbol "__args") i)) (list (make-symbol "lua-arg") (make-symbol "__args") i))
(lua-tx-function-bindings params (+ i 1)))))) (lua-tx-function-bindings params (+ i 1))))))
(define
lua-tx-function-varargs-binding
(fn (n)
(list
(make-symbol "__varargs")
(list (make-symbol "lua-varargs") (make-symbol "__args") n))))
(define (define
lua-tx-function lua-tx-function
(fn (fn
@@ -183,19 +189,26 @@
(is-vararg (nth node 2)) (is-vararg (nth node 2))
(body (nth node 3))) (body (nth node 3)))
(cond (cond
((= (len params) 0) ((and (= (len params) 0) (not is-vararg))
(list (list
(make-symbol "fn") (make-symbol "fn")
(list (make-symbol "&rest") (make-symbol "__args")) (list (make-symbol "&rest") (make-symbol "__args"))
(lua-tx body))) (lua-tx body)))
(else (else
(list (let
(make-symbol "fn") ((bindings (lua-tx-function-bindings params 0)))
(list (make-symbol "&rest") (make-symbol "__args")) (let
(list ((all-bindings
(make-symbol "let") (if is-vararg
(lua-tx-function-bindings params 0) (append bindings (list (lua-tx-function-varargs-binding (len params))))
(lua-tx body)))))))) bindings)))
(list
(make-symbol "fn")
(list (make-symbol "&rest") (make-symbol "__args"))
(list
(make-symbol "let")
all-bindings
(lua-tx body))))))))))
(define (define
lua-tx-block lua-tx-block

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-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.
- 2026-04-24: lua: scoreboard iteration — added `rawget`/`rawset`/`rawequal`/`rawlen`, `loadstring`/`load`, `select`, `assert`, `_G`, `_VERSION`. Failure mix now 6×vararg-transpile / 4×real-assertion / 3×parse / 2×call-non-fn / 1×timeout (was 14 parse + 1 print undef at baseline); tests now reach deep into real assertions. Still 0/16 runnable — next targets: vararg transpile, goto, loadstring-compile depth. 347 unit tests. - 2026-04-24: lua: scoreboard iteration — added `rawget`/`rawset`/`rawequal`/`rawlen`, `loadstring`/`load`, `select`, `assert`, `_G`, `_VERSION`. Failure mix now 6×vararg-transpile / 4×real-assertion / 3×parse / 2×call-non-fn / 1×timeout (was 14 parse + 1 print undef at baseline); tests now reach deep into real assertions. Still 0/16 runnable — next targets: vararg transpile, goto, loadstring-compile depth. 347 unit tests.
- 2026-04-24: lua: `require`/`package` via preload-only (no filesystem search). `package.loaded` caching, nil-returning modules cache as `true`, unknown modules error. 347 tests. - 2026-04-24: lua: `require`/`package` via preload-only (no filesystem search). `package.loaded` caching, nil-returning modules cache as `true`, unknown modules error. 347 tests.
- 2026-04-24: lua: `os` stub — time/clock monotonic counter, difftime, date (default string / `*t` dict), getenv/remove/rename/tmpname/execute/exit stubs. Phase 6 complete. 342 tests. - 2026-04-24: lua: `os` stub — time/clock monotonic counter, difftime, date (default string / `*t` dict), getenv/remove/rename/tmpname/execute/exit stubs. Phase 6 complete. 342 tests.