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

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