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)))
(cond
((= (first f) "pos")
(begin
(set! t (assoc t (str array-idx) (nth f 1)))
(set! array-idx (+ array-idx 1))))
(let ((v (nth f 1)))
(cond
((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")
(let
((k (nth f 1)) (v (nth f 2)))
@@ -384,23 +399,48 @@
(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
lua-apply
(fn
(f rargs)
(f rargs-in)
(let
((n (len rargs)))
(cond
((= n 0) (f))
((= n 1) (f (nth rargs 0)))
((= n 2) (f (nth rargs 0) (nth rargs 1)))
((= n 3) (f (nth rargs 0) (nth rargs 1) (nth rargs 2)))
((= n 4) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3)))
((= n 5) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4)))
((= n 6) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5)))
((= 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))))))
((rargs (lua-spread-last-multi rargs-in)))
(let
((n (len rargs)))
(cond
((= n 0) (f))
((= n 1) (f (nth rargs 0)))
((= n 2) (f (nth rargs 0) (nth rargs 1)))
((= n 3) (f (nth rargs 0) (nth rargs 1) (nth rargs 2)))
((= n 4) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3)))
((= n 5) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4)))
((= n 6) (f (nth rargs 0) (nth rargs 1) (nth rargs 2) (nth rargs 3) (nth rargs 4) (nth rargs 5)))
((= 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
lua-call
@@ -1441,3 +1481,15 @@
(define _G {})
(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))))))