1
0
forked from alex-eg/sex

hold a function type's parameters by value on the interface

A record a pub function type took or returned by value was declared
only, so an importer could neither define a callback for it nor call
one.
This commit is contained in:
2026-10-15 14:44:34 +03:00
parent 44101c0c06
commit 2279c371f2
2 changed files with 14 additions and 2 deletions

View File

@@ -202,7 +202,10 @@
;;;
;;; (* const cell) -> ((const . #t) (cell . #t))
;;; [cell 4] -> ((cell . #f))
;;; (fn ((cell)) int) -> ((cell . #t) (int . #t)) ; declaring is enough
;;; (fn ((cell)) int) -> ((cell . #f) (int . #f))
;;;
;;; A function type takes and returns by value whatever it is held
;;; through: C wants the body to define or call one of its functions.
(define (type-uses type behind?)
(cond
((symbol? type) (list (cons type behind?)))
@@ -215,7 +218,7 @@
(if (array-bound? type) (bound-uses (last type)) (list)))))
((fn closure)
(if (and (pair? (cdr type)) (list? (second type)))
(append-map (lambda (t) (type-uses t #t))
(append-map (lambda (t) (type-uses t #f))
(signature-types (second type) (last type)))
(list)))
((struct union enum)

View File

@@ -534,6 +534,15 @@ ahead of its pub forms."
"held by value"))
(test-assert "returned"
(interface-reports? "(record cell ((v int))) (pub fn f () cell)" "held by value"))
(test-assert "or taken by a function a pub one takes"
(interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn ((c cell)) void))) void)"
"held by value"))
(test-assert "or returned by one"
(interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn () cell))) void)"
"held by value"))
(test "but a pointer there is still a pointer"
'((record cell))
(interface-of "(record cell ((v int))) (pub fn take ((cb (fn ((c (* cell))) void))) void)"))
(test-assert "or taken by a pub method"
(interface-reports? "(record cell ((v int))) (ops cell (pub fn get ((self cell)) int))"
"held by value"))