resolve the closure types in a closure's signature

The struct, call helper and conversion thunk of a closure type went out
with any closure type in its signature as written, which C has no name
for; so a closure could neither return nor take one, and no currying.
This commit is contained in:
2026-10-18 22:02:55 +03:00
parent 72adb5284b
commit 3e6e6c71e7
2 changed files with 31 additions and 2 deletions

View File

@@ -1630,7 +1630,17 @@
;;; The code pointer takes the environment first; everything else is
;;; the closure's own signature.
(define (closure-code-type type)
`(fn (((* void)) ,@(second type)) ,(third type)))
(let ((type (signature-resolved type)))
`(fn (((* void)) ,@(second type)) ,(third type))))
;;; TYPE with the closure types of its signature made their structs: the
;;; code generated for it goes out as it is, and C has no `closure'.
;;;
;;; (closure ((int)) (closure ((int)) int))
;;; -> (closure ((int)) (struct ƛint_int))
(define (signature-resolved type)
`(closure ,(map resolve-closure-types (second type))
,(resolve-closure-types (third type))))
;;; Emitted once per signature, before the toplevel form that first
;;; needed it.
@@ -1686,6 +1696,7 @@
;;; }
(define (register-fn-conversion! type src-form)
(let* ((closure (closure-struct-name type))
(type (signature-resolved type))
(convert (suffixed closure "_fromfn"))
(record (suffixed closure "_fnptr"))
(thunk (suffixed closure "_fnthunk"))
@@ -1745,6 +1756,7 @@
;;; `table[++i].code(&table[++i].env, 10)' and bump `i' twice.
(define (register-closure-call! type src-form)
(let* ((closure (closure-struct-name type))
(type (signature-resolved type))
(helper (suffixed closure "_call"))
(returns (third type))
(params (map (lambda (arg index)